public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "geoffreydgr at icloud dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/107526] New: - -Wanayzer-null-dereference false positive with different behaviors when delete unrelated statement “int *e = 0;” Date: Fri, 04 Nov 2022 15:11:08 +0000 [thread overview] Message-ID: <bug-107526-4@http.gcc.gnu.org/bugzilla/> (raw) 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?
next reply other threads:[~2022-11-04 15:11 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-04 15:11 geoffreydgr at icloud dot com [this message] 2022-11-04 15:18 ` [Bug analyzer/107526] " geoffreydgr at icloud dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107526-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).