This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/79310] -Wnonnull false positive on strlen after strstr
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 31 Jan 2017 21:43:14 +0000
- Subject: [Bug middle-end/79310] -Wnonnull false positive on strlen after strstr
- Auto-submitted: auto-generated
- References: <bug-79310-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79310
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
A similar case and optimization opportunity (and also a possible source of
false positives) exists with strchr.
$ cat t.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.c
void foo (const char *s, int x)
{
if (!__builtin_strchr (s, '\0'))
__builtin_abort ();
}
;; Function foo (foo, funcdef_no=0, decl_uid=1796, cgraph_uid=0,
symbol_order=0)
foo (const char * s, int x)
{
char * _1;
long unsigned int _4;
<bb 2> [100.00%]:
_4 = __builtin_strlen (s_3(D));
_1 = s_3(D) + _4;
if (_1 == 0B)
goto <bb 3>; [0.04%]
else
goto <bb 4>; [99.96%]
<bb 3> [0.04%]:
__builtin_abort ();
<bb 4> [99.96%]:
return;
}