https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90376
Bug ID: 90376
Summary: spurious -Warray-bounds on memset() of several
struct's subobjects
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ryabinin.a.a at gmail dot com
Target Milestone: ---
This is new on gcc 9.
# cat array_bounds.c
struct trace_iterator {
char a;
int seq;
long b;
};
void f(void)
{
static struct trace_iterator iter;
__builtin_memset(&iter.seq, 0,
sizeof(struct trace_iterator) -
__builtin_offsetof(struct trace_iterator, seq));
}
# gcc -O2 -c -Warray-bounds array_test.c
array_test.c: In function ‘f’:
array_test.c:12:2: warning: ‘__builtin_memset’ offset [9, 16] from the object
at ‘iter’ is out of the bounds of referenced subobject ‘seq’ with type ‘int’ at
offset 4 [-Warray-bounds]
12 | __builtin_memset(&iter.seq, 0,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 | sizeof(struct trace_iterator) -
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 | __builtin_offsetof(struct trace_iterator, seq));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~