This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84315] missing -Wnonnull for trivial null pointer dereference
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 09 Feb 2018 17:55:02 +0000
- Subject: [Bug tree-optimization/84315] missing -Wnonnull for trivial null pointer dereference
- Auto-submitted: auto-generated
- References: <bug-84315-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84315
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
-Wnull-dereference gets test case 1:
$ /usr/local/bin/gcc -c -O2 -S -Wall -Wnonnull
-fdump-tree-optimized=/dev/stdout -Wextra -pedantic -Wnull-dereference
-Warray-bounds=2 84315_1.c
84315_1.c: In function 'main':
84315_1.c:4:11: warning: null pointer dereference [-Wnull-dereference]
return p[123]; // missing -Wnonnull
~^~~~~
;; Function main (main, funcdef_no=0, decl_uid=1904, cgraph_uid=0,
symbol_order=0) (executed once)
main ()
{
int _2;
<bb 2> [local count: 1073741825]:
_2 ={v} MEM[(int *)0B + 492B];
__builtin_trap ();
}
$
It also gets test case 2:
$ /usr/local/bin/gcc -c -O2 -S -Wall -Wnonnull
-fdump-tree-optimized=/dev/stdout -Wextra -pedantic -Wnull-dereference
-Warray-bounds=2 84315_2.c
;; Function f (f, funcdef_no=0, decl_uid=1905, cgraph_uid=0, symbol_order=1)
f (unsigned int i)
{
int * iftmp.0_1;
<bb 2> [local count: 1073741825]:
if (i_2(D) <= 31)
goto <bb 4>; [71.00%]
else
goto <bb 3>; [29.00%]
<bb 3> [local count: 311385128]:
<bb 4> [local count: 1073741825]:
# iftmp.0_1 = PHI <&a(2), 0B(3)>
return iftmp.0_1;
}
84315_2.c: In function 'main':
84315_2.c:11:10: warning: null pointer dereference [-Wnull-dereference]
return *p; // missing -Wnonnull
^~
;; Function main (main, funcdef_no=1, decl_uid=1908, cgraph_uid=1,
symbol_order=2) (executed once)
main ()
{
int _2;
<bb 2> [local count: 1073741825]:
_2 ={v} MEM[(int *)0B];
__builtin_trap ();
}
$
I think just the -Wnull-dereference warning is fine; no need for -Wnonnull to
warn about it, too.