public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/95515] New: missing --Wnonnull on a straightforward call with a null pointer
Date: Wed, 03 Jun 2020 20:11:28 +0000	[thread overview]
Message-ID: <bug-95515-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95515

            Bug ID: 95515
           Summary: missing --Wnonnull on a straightforward call with a
                    null pointer
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In the following test case only the first two instances of passing a null
argument to a nonnull function are diagnosed.  The third one isn't.

$ cat z.c && gcc -O2 -S -Wall -Wpedantic -fdump-tree-optimized=/dev/stdout z.c
__attribute__ ((nonnull)) void f (void*);

void f1 (void)
{
  f (0);           // Wnonnull (good)
}

void f2 (void)
{
  void *const p = 0;
  f (p);           // -Wnonnull (good)
}


void f3 (void)
{
  void *p = 0;
  f (p);           // missing -Wnonnull
}

z.c: In function ‘f1’:
z.c:5:3: warning: null argument where non-null required (argument 1)
[-Wnonnull]
    5 |   f (0);           // Wnonnull (good)
      |   ^
z.c: In function ‘f2’:
z.c:11:3: warning: null argument where non-null required (argument 1)
[-Wnonnull]
   11 |   f (p);           // -Wnonnull (good)
      |   ^

;; Function f1 (f1, funcdef_no=0, decl_uid=1932, cgraph_uid=1, symbol_order=0)

f1 ()
{
  <bb 2> [local count: 1073741824]:
  f (0B); [tail call]
  return;

}



;; Function f2 (f2, funcdef_no=4, decl_uid=1935, cgraph_uid=2, symbol_order=1)

f2 ()
{
  <bb 2> [local count: 1073741824]:
  f (0B); [tail call]
  return;

}



;; Function f3 (f3, funcdef_no=6, decl_uid=1939, cgraph_uid=3, symbol_order=2)

f3 ()
{
  <bb 2> [local count: 1073741824]:
  f (0B); [tail call]
  return;

}


Clang is similarly ineffective on its own, but its analyzer detects all three:

$ clang -O2 -S -Wall --analyze z.c
z.c:5:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  f (0);           // Wnonnull (good)
  ^~~~~
z.c:11:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  f (p);           // -Wnonnull (good)
  ^~~~~
z.c:18:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  f (p);           // missing -Wnonnull
  ^~~~~
3 warnings generated.

             reply	other threads:[~2020-06-03 20:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 20:11 msebor at gcc dot gnu.org [this message]
2023-02-02 22:26 ` [Bug middle-end/95515] " pinskia at gcc dot gnu.org
2023-02-02 22:39 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-95515-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).