https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110458
Bug ID: 110458
Summary: -Warray-bounds=2 new false positive
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sirl at gcc dot gnu.org
Target Milestone: ---
Created attachment 55412
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55412&action=edit
testcase
Since somewhere between r14-1870 and r14-2097 a new -Warray-bounds=2 false
positive is shown for this little testcase:
typedef struct {
unsigned arr1[4];
unsigned arr2[4];
} data;
void f_notok(void *arrayOut) {
int i;
unsigned *arr2;
unsigned *arr1;
data *dataOut;
dataOut = (data *)arrayOut;
arr1 = dataOut[0].arr1;
arr2 = dataOut[0].arr2;
i = 0;
for (; i < 4; i++) {
arr1[i] = 0;
arr2[i] = 0;
}
}
When compiled with trunk@r2097 "gcc -O2 -W -Wall -Warray-bounds=2 -c
bug-Warray-bounds-eq-2.c" the warning is:
bug-Warray-bounds-eq-2.c: In function 'f_notok':
bug-Warray-bounds-eq-2.c:16:13: warning: '__builtin_memset' offset [16, 31]
from the object at 'arrayOut' is out of the bounds of referenced subobject
'arr1' with type 'unsigned int[4]' at offset 0 [-Warray-bounds=]
16 | arr1[i] = 0;
| ~~~~~~~~^~~
bug-Warray-bounds-eq-2.c:2:12: note: subobject 'arr1' declared here
2 | unsigned arr1[4];
| ^~~~
gcc-13.1.1 and earlier didn't warn here. The attached full testcase also shows
that slight variations in the code silence the warning.