public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/107526] New: - -Wanayzer-null-dereference false positive with different behaviors when delete unrelated statement “int *e = 0;”
@ 2022-11-04 15:11 geoffreydgr at icloud dot com
2022-11-04 15:18 ` [Bug analyzer/107526] " geoffreydgr at icloud dot com
0 siblings, 1 reply; 2+ messages in thread
From: geoffreydgr at icloud dot com @ 2022-11-04 15:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107526
Bug ID: 107526
Summary: - -Wanayzer-null-dereference false positive with
different behaviors when delete unrelated statement
“int *e = 0;”
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: geoffreydgr at icloud dot com
Target Milestone: ---
I encountered a false positive when compiling the following MCVE program with
gcc (trunk) with -fanalyzer -O0 in https://godbolt.org/z/ojqa7PjPf
```
#include <stdio.h>
void f(short *g) {
int a =0;
int b = (0 != g);
am:
if (b) {
int *c = &b;
*c = printf("NPD_FLAG\n");
}
int *e = 0; // (3) 'g' is NULL
(*g)++;
if (a)
goto am;
}
int main() {
short d=0;
f(&d);
return 0;
}
```
Gcc static analyzer reports dereference of NULL 'g' at line 4, which is a
false positive. while it gives wrong path note (3) 'g' is NULL at line 12.
If I delete line 12 as the following code, gcc analyzer does not report NPD
warning anymore.The statement `int *e = 0; ` is unrelated to `g` , but gcc
analyzer has different behaviors before and after deleting the statement.
```
#include <stdio.h>
void f(short *g) {
int a =0;
int b = (0 != g);
am:
if (b) {
int *c = &b;
*c = printf("NPD_FLAG\n");
}
int *e = 0; // (3) 'g' is NULL
(*g)++;
if (a)
goto am;
}
int main() {
short d=0;
f(&d);
return 0;
}
```
Do you have any thoughts about this false positive?
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug analyzer/107526] - -Wanayzer-null-dereference false positive with different behaviors when delete unrelated statement “int *e = 0;”
2022-11-04 15:11 [Bug analyzer/107526] New: - -Wanayzer-null-dereference false positive with different behaviors when delete unrelated statement “int *e = 0;” geoffreydgr at icloud dot com
@ 2022-11-04 15:18 ` geoffreydgr at icloud dot com
0 siblings, 0 replies; 2+ messages in thread
From: geoffreydgr at icloud dot com @ 2022-11-04 15:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107526
--- Comment #1 from Geoffrey <geoffreydgr at icloud dot com> ---
And if i compile this case with gcc 11.3, it does not report NPD warning.
https://godbolt.org/z/v88PWvs3s
seems like a regression problem.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-04 15:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 15:11 [Bug analyzer/107526] New: - -Wanayzer-null-dereference false positive with different behaviors when delete unrelated statement “int *e = 0;” geoffreydgr at icloud dot com
2022-11-04 15:18 ` [Bug analyzer/107526] " geoffreydgr at icloud dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).