public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95515] New: missing --Wnonnull on a straightforward call with a null pointer
@ 2020-06-03 20:11 msebor at gcc dot gnu.org
  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
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-03 20:11 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/95515] missing --Wnonnull on a straightforward call with a null pointer
  2020-06-03 20:11 [Bug middle-end/95515] New: missing --Wnonnull on a straightforward call with a null pointer msebor at gcc dot gnu.org
@ 2023-02-02 22:26 ` pinskia at gcc dot gnu.org
  2023-02-02 22:39 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-02 22:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jg at jguk dot org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108646 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/95515] missing --Wnonnull on a straightforward call with a null pointer
  2020-06-03 20:11 [Bug middle-end/95515] New: missing --Wnonnull on a straightforward call with a null pointer msebor at gcc dot gnu.org
  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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-02 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 17308.

*** This bug has been marked as a duplicate of bug 17308 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-02 22:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03 20:11 [Bug middle-end/95515] New: missing --Wnonnull on a straightforward call with a null pointer msebor at gcc dot gnu.org
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

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).