https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123981
Bug ID: 123981
Summary: -Wanalyzer-null-dereference does not consider __seg_gs
Product: gcc
Version: 14.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: auto at fedang dot net
Target Milestone: ---
The analyzer does not take into account custom address spaces when checking
pointer accesses. I tested for __seg_gs, but the same can be said for __seg_fs.
In this case we would not expect a NULL dereference warning as we are accessing
at offset 0 of the segment.
Maybe an option to skip -Wanalyzer-null-dereference for pointers with the
address space attribute is possible?
Test program:
```
#include <stdio.h>
#include <immintrin.h>
#define getgs() ((int * __seg_gs)0)
int main()
{
static int gsval = 42;
_writegsbase_u64((unsigned long long)&gsval);
printf("%d\n", *getgs());
return 0;
}
```
Warning:
```
gcc test.c -mfsgsbase -fanalyzer
test.c: In function ‘main’:
test.c:10:5: warning: dereference of NULL ‘0’ [CWE-476]
[-Wanalyzer-null-dereference]
10 | printf("%d\n", *getgs());
| ^~~~~~~~~~~~~~~~~~~~~~~~
‘main’: events 1-2
|
| 10 | printf("%d\n", *getgs());
| | ^~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (1) ‘0’ is NULL
| | (2) dereference of NULL ‘0’
|
```