https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117144
Bug ID: 117144
Summary: More warnings if gcc -E xx.c -o xx.i and gcc -c xx.i
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: syq at gcc dot gnu.org
Target Milestone: ---
We may get some warning if
```
gcc -E -O2 xx.c -o xx.i
gcc -c -O2 xx.i -o xx.o
```
While not if `gcc -c` directly.
This is an example:
```
#define NULL (void *)0
#define hashmap_cast_ptr(p) ({
\
_Static_assert((__builtin_constant_p((p)) ? (p) == NULL : 0) ||
\
sizeof(*(p)) == sizeof(long),
\
#p " pointee should be a long-sized integer or a
pointer"); \
(long *)(p);
\
})
_Bool hashmap_find(long *map, long key, long *cands) {
if (*map > key) {
cands = map;
return 1==1;
}
cands = NULL;
return 1==0;
}
long *test (long *map, int key) {
long *value = NULL;
if (hashmap_find((map), (long)(key), hashmap_cast_ptr(&value)))
return value;
return NULL;
}
```
$ gcc -c -O2 xx.c
$ gcc -c -Wall -O2 xx.c
$ gcc -O2 -E xx.c -o xx.i
$ gcc -O2 -c -Wall xx.i -o xx.o
xx.c: In function ‘test’:
xx.c:21:107: warning: the comparison will always evaluate as ‘false’ for the
address of ‘value’ will never be NULL [-Waddress]
21 | if (hashmap_find((map), (long)(key), hashmap_cast_ptr(&value)))
|
^
xx.c:20:15: note: ‘value’ declared here
20 | long *value = NULL;
| ^~~~~
```
I find this problem when I try to use distcc to build libbpf/libbpf.c from
linux kernel.