This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/81876] New: [7 Regression] bogus -Wstrict-overflow warning with -O3
- From: "bunk at stusta dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 17 Aug 2017 08:42:20 +0000
- Subject: [Bug c/81876] New: [7 Regression] bogus -Wstrict-overflow warning with -O3
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81876
Bug ID: 81876
Summary: [7 Regression] bogus -Wstrict-overflow warning with
-O3
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: bunk at stusta dot de
Target Milestone: ---
Testcase based on an xbubble build error on Debian:
$ cat test.c
struct _Bubble {
int color;
};
typedef struct _Bubble * Bubble;
typedef enum {
EAST=0,
NORTH_EAST,
NORTH_WEST,
WEST,
SOUTH_WEST,
SOUTH_EAST
} Quadrant;
struct _CellArray {
Bubble cell[(8 * 12)];
int first_row;
};
typedef struct _CellArray * CellArray;
void cell_array_lower( CellArray ca ) {
int i;
for ( i = ( ca->first_row*8 ); i < ( ca->first_row*8 ) + 8; i++ )
ca->cell[i] = ((void *)0);
}
$ gcc-6 -O2 -Wall -Werror -c test.c
$ gcc-6 -O3 -Wall -Werror -c test.c
$ gcc -O2 -Wall -Werror -c test.c
$ gcc -O3 -Wall -Werror -c test.c
test.c: In function ‘cell_array_lower’:
test.c:25:17: error: assuming signed overflow does not occur when assuming that
(X + c) >= X is always true [-Werror=strict-overflow]
ca->cell[i] = ((void *)0);
~~~~~~~~~~~~^~~~~~~~~~~~~
cc1: all warnings being treated as errors
$
It works when replacing the "+ 8" in the loop condition with a variable whose
value is not known at compile time.