Bug 95515 - missing --Wnonnull on a straightforward call with a null pointer
Summary: missing --Wnonnull on a straightforward call with a null pointer
Status: RESOLVED DUPLICATE of bug 17308
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 108646 (view as bug list)
Depends on:
Blocks: Wnonnull
  Show dependency treegraph
 
Reported: 2020-06-03 20:11 UTC by Martin Sebor
Modified: 2024-01-01 02:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2020-06-03 20:11:28 UTC
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.
Comment 1 Andrew Pinski 2023-02-02 22:26:29 UTC
*** Bug 108646 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2023-02-02 22:39:39 UTC
Dup of bug 17308.

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