https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119104
--- Comment #7 from Alejandro Colomar <alx at kernel dot org> ---
alx@devuan:~/tmp$ cat nninz.c | grep -Tn ^
1: #include <stdlib.h>
2:
3: extern int any;
4:
5: [[gnu::nonnull]]
6: void f(void *);
7: [[gnu::nonnull_if_nonzero(1, 2)]]
8: void g(void *, int);
9:
10: int
11: main(void)
12: {
13: int one = 1;
14: int zero = 0;
15:
16: f(NULL); // -Wnonnull
17: g(NULL, 1); // -Wnonnull
18: g(NULL, 0);
19: g(NULL, one); // -Wnonnull -O1
20: g(NULL, zero);
21: g(NULL, any);
22: }
alx@devuan:~/tmp$ gcc-15 -Wall -Wextra -O3 -S nninz.c
nninz.c: In function ‘main’:
nninz.c:16:9: warning: argument 1 null where non-null expected [-Wnonnull]
16 | f(NULL); // -Wnonnull
| ^
nninz.c:6:6: note: in a call to function ‘f’ declared ‘nonnull’
6 | void f(void *);
| ^
nninz.c:17:9: warning: argument 1 null where non-null expected because argument
2 is nonzero [-Wnonnull]
17 | g(NULL, 1); // -Wnonnull
| ^
nninz.c:8:6: note: in a call to function ‘g’ declared ‘nonnull_if_nonzero’
8 | void g(void *, int);
| ^
nninz.c:19:9: warning: argument 1 null where non-null expected because argument
2 is nonzero [-Wnonnull]
19 | g(NULL, one); // -Wnonnull -O1
| ^~~~~~~~~~~~
nninz.c:8:6: note: in a call to function ‘g’ declared ‘nonnull_if_nonzero’
8 | void g(void *, int);
| ^
Assuming that there's no agreement on wanting to diagnose line 21 under
-Wnonnull, could we add -Wnonnull-maybe-nonzero-size for diagnosing it?