https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109449
Bug ID: 109449
Summary: false positive stringop-overflow
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pionere at freemail dot hu
Target Milestone: ---
Compiling the following code:
#include <stdint.h>
#define DMAXX 40
#define DMAXY 40
#define DSIZEX 80
#define DSIZEY 80
typedef struct DrlgMem {
union {
uint8_t transvalMap[DMAXX][DMAXY];
uint8_t transDirMap[DSIZEX][DSIZEY];
};
} DrlgMem;
DrlgMem drlg;
void func()
{
int i, j;
uint8_t *tdp = &drlg.transDirMap[0][0];
for (i = DMAXX - 1; i >= 0; i--) {
for (j = DMAXY - 1; j >= 0; j--) {
uint8_t tvm = drlg.transvalMap[i][j];
uint8_t tpm = 0;
// 1. subtile
if (tvm & 1) {
tpm = 14;
} else {
tpm = 0;
}
tdp[2 * i * DSIZEY + 2 * j] = tpm;
// 3. subtile
if (tvm & 4) {
tpm = 25;
if (tvm & (1 << 0)) // 1. subtile
tpm |= (1 << 1); // DIR_NW
if (tvm & (1 << 3)) // 4. subtile
tpm |= (1 << 6); // DIR_SW
} else {
tpm = 0;
}
tdp[2 * i * DSIZEY + 2 * j + 1] = tpm;
// 2. subtile
if (tvm & 2) {
tpm = 98;
} else {
tpm = 0;
}
tdp[(2 * i + 1) * DSIZEY + 2 * j] = tpm; // 1. warning here
// 4. subtile
if (tvm & 8) {
tpm = 193;
} else {
tpm = 0;
}
tdp[(2 * i + 1) * DSIZEY + 2 * j + 1] = tpm; // 2. warning here
}
}
}
The result is multiple invalid warnings. E.g: '<source>:50:47: error: writing 1
byte into a region of size 0 [-Werror=stringop-overflow=]...'
Tried to reduce the sample code, but the warnings disappear even in case of
unrelated changes.