https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84316
Bug ID: 84316 Summary: -Wnull-dereference doesn't work with LTO Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- As I mentioned in pr84315, while testing my fix for pr84212 I noticed that the -Wnull-dereference warning has no effect in LTO. Unlike some other middle-end warning options that are specified in c-family/c.opt and that explicitly enable LTO, -Wnull-dereference is only mentioned in common.opt with no mention of what languages it applies to (presumably because it's meant to apply to all languages). That makes me wonder if any other options in common.opt suffer from this problem. $ (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