https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85788
Bug ID: 85788
Summary: False positive of -Wstringop-overflow= warning
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: msebor at gcc dot gnu.org
Target Milestone: ---
Probably a know scenario, but I'll report that anyway. It's reduced from
cuneiform package:
$ cat tc2.i
int b;
int *d = 0, *e;
void a(void *k, long l) {
long f = __builtin_object_size(k, 0);
__builtin___memset_chk(k, b, l, f);
}
typedef struct {
int g;
int h;
char i[8000 * 8];
} j;
static int make_str_raster(j *k) {
int *c = d;
for (; c; c = e)
k->g = k->h = 32767;
a(k->i, k->g / 8 * k->h);
for (; d;)
;
}
j m;
void n() { make_str_raster(&m); }
$ gcc tc2.i -O2
In function ‘a’,
inlined from ‘make_str_raster.constprop’ at tc2.i:17:3,
inlined from ‘n’ at tc2.i:22:12:
tc2.i:5:3: warning: ‘__builtin___memset_chk’ writing 134180865 bytes into a
region of size 64000 overflows the destination [-Wstringop-overflow=]
__builtin___memset_chk(k, b, l, f);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As seen, d == 0, thus 'for (; c; c = e)' never executes. It's combination of
jump-threading and VRP that triggers the warning.