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

Martin Sebor <msebor at gcc dot gnu.org> changed:

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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Aww rats, I forgot about -Wnull-dereference.

It's really unfortunate that -Wnull-dereference is disabled by default.  Worse,
enabling -Wnull-dereference has no effect in LTO (see below).  Let me resolve
this as invalid and open a new bug for the LTO limitation.

$ (set -x; cat a.c; cc='gcc -O3 -Wall -Wextra -Wnull-dereference -flto'; $cc -c
a.c && $cc -DMAIN -c -o main.o a.c && $cc a.o main.o)
+ cat a.c
#if MAIN

extern int f (int[], int, int);

int main (void)
{
  int *p = 0;
  int i = f (p, 123, 5);   // missing -Wnull-dereference

  int *q;
  int j = f (q, 123, 5);   // -Wuninitialized (good)

  return i + j;
}

#else

int f (int a[], int i, int x)
{
  int tmp = a[i];
  a[i] = x;
  return tmp;
}

#endif
+ cc='gcc -O3 -Wall -Wextra -Wnull-dereference -flto'
+ gcc -O3 -Wall -Wextra -Wnull-dereference -flto -c a.c
+ gcc -O3 -Wall -Wextra -Wnull-dereference -flto -DMAIN -c -o main.o a.c
a.c: In function ‘main’:
a.c:11:11: warning: ‘q’ is used uninitialized in this function
[-Wuninitialized]
   int j = f (q, 123, 5);   // -Wuninitialized (good)
           ^~~~~~~~~~~~~
+ gcc -O3 -Wall -Wextra -Wnull-dereference -flto a.o main.o

Reply via email to