https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104367
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Declaring bar()n with attribute nonnull triggers -Wnonnull but only at -O1: In function ‘foo’, inlined from ‘main’ at pr104367.c:15:5: pr104367.c:11:5: warning: argument 1 null where non-null expected [-Wnonnull] 11 | bar(x); | ^~~~~~ pr104367.c: In function ‘main’: pr104367.c:3:32: note: in a call to function ‘bar’ declared ‘nonnull’ 3 | __attribute__ ((nonnull)) void bar(int *x) { | ^~~ At -O2 GCC notices the invalid access and emits a trap but doesn't warn: void foo (int * x) { int _3; <bb 2> [local count: 1073741824]: if (x_1(D) == 0B) goto <bb 3>; [9.81%] else goto <bb 4>; [90.19%] <bb 3> [local count: 105334072]: _3 ={v} MEM[(int *)0B]; __builtin_trap (); <bb 4> [local count: 1073741824]: return; }