https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91490
Bug ID: 91490
Summary: [9/10 Regression] bogus argument missing terminating
nul warning on strlen of a flexible array member
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The strlen call in f() below compiles with no warning and is successfully
folded to a constant, but the equivalent call in g() triggers two spurious
instances of the same warning and is not folded.
The warning is new in GCC 9 so GCC 8 compiles both functions without one, and
folds neither call,
$ cat a.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout a.c
struct A { char n, s[]; };
const struct A a1 = { 3, "321" };
int f (void)
{
return __builtin_strlen (a1.s); // no warning, folded to 3
}
const struct A a2 = { 3, { 3, 2, 1, 0 } };
int g (void)
{
return __builtin_strlen (a2.s); // bogus warning, not folded
}
a.c: In function ‘g’:
a.c:14:30: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
14 | return __builtin_strlen (a2.s); // bogus warning, not folded
| ~~^~
a.c:10:16: note: referenced argument declared here
10 | const struct A a2 = { 3, { 3, 2, 1, 0 } };
| ^~
a.c:14:30: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
14 | return __builtin_strlen (a2.s); // bogus warning, not folded
| ~~^~
a.c:10:16: note: referenced argument declared here
10 | const struct A a2 = { 3, { 3, 2, 1, 0 } };
| ^~
;; Function f (f, funcdef_no=0, decl_uid=1910, cgraph_uid=1, symbol_order=1)
f ()
{
<bb 2> [local count: 1073741824]:
return 3;
}
;; Function g (g, funcdef_no=1, decl_uid=1914, cgraph_uid=2, symbol_order=3)
g ()
{
long unsigned int _1;
int _3;
<bb 2> [local count: 1073741824]:
_1 = __builtin_strlen (&a2.s);
_3 = (int) _1;
return _3;
}