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

            Bug ID: 84315
           Summary: missing -Wnonnull for trivial null pointer dereference
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While testing my fix for pr84212 I noticed that even though GCC detects the
null pointer dereferences in the test cases below, the -Wnonnull warning fails
to point them out.

Test case 1:

$ cat b.c && gcc -O2 -S -Wall -Wnonnull -fdump-tree-optimized=/dev/stdout b.c
int main (void)
{
  int *p = 0;
  return p[123];   // missing -Wnonnull
}

;; Function main (main, funcdef_no=0, decl_uid=1950, cgraph_uid=0,
symbol_order=0) (executed once)

main ()
{
  int _2;

  <bb 2> [local count: 1073741825]:
  _2 ={v} MEM[(int *)0B + 492B];   // null dereference
  __builtin_trap ();               // detected here

}


Test case 2:

$ cat b.c && gcc -O2 -S -Wall -Wnonnull -fdump-tree-optimized=/dev/stdout b.c
int a[8];

int* f (unsigned i)
{
  return i < sizeof a ? a : 0;
}

int main (void)
{
  int *p = f (sizeof a);
  return *p;   // missing -Wnonnull
}

;; Function f (f, funcdef_no=0, decl_uid=1951, cgraph_uid=0, symbol_order=1)

f (unsigned int i)
{
  int * iftmp.0_1;

  <bb 2> [local count: 1073741825]:
  if (i_2(D) <= 31)
    goto <bb 4>; [71.00%]
  else
    goto <bb 3>; [29.00%]

  <bb 3> [local count: 311385128]:

  <bb 4> [local count: 1073741825]:
  # iftmp.0_1 = PHI <&a(2), 0B(3)>
  return iftmp.0_1;

}



;; Function main (main, funcdef_no=1, decl_uid=1954, cgraph_uid=1,
symbol_order=2) (executed once)

main ()
{
  int _2;

  <bb 2> [local count: 1073741825]:
  _2 ={v} MEM[(int *)0B];   // null dereference
  __builtin_trap ();        // detected here

}

Reply via email to