https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91890
Bug ID: 91890
Summary: [10 Regression] -Warray-bounds warning testing glibc
not suppressed by pragma
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jsm28 at gcc dot gnu.org
CC: msebor at gcc dot gnu.org
Target Milestone: ---
r275981 ("PR middle-end/91631 - buffer overflow into an array member of a
declared object not detected") introduced an error when the following code is
built with -O2 -Wall -Werror (the problem isn't that there is a -Warray-bounds
diagnostic for the code, the problem is that the pragma is no longer
suppressing it for some reason). This is reduced from a glibc testcase (which
has had the pragma to suppress the warning for some time, but the pragma is no
longer working).
char one[50];
char two[50];
void
test_strncat (void)
{
(void) __builtin_strcpy (one, "gh");
(void) __builtin_strcpy (two, "ef");
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#pragma GCC diagnostic ignored "-Warray-bounds"
(void) __builtin_strncat (one, two, 99);
#pragma GCC diagnostic pop
}
aarch64-glibc-linux-gnu-gcc -S -O2 -Wall -Werror tester.c
tester.c: In function 'test_strncat':
tester.c:13:10: error: '__builtin_strncat' forming offset [50, 98] is out of
the bounds [0, 50] of object 'one' with type 'char[50]' [-Werror=array-bounds]
13 | (void) __builtin_strncat (one, two, 99);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tester.c:1:6: note: 'one' declared here
1 | char one[50];
| ^~~
cc1: all warnings being treated as errors