[Bug c/19056] New: 4.0 optimizes away a SEGV; 3.4.1 does not
bh at techhouse dot brown dot edu
gcc-bugzilla@gcc.gnu.org
Fri Dec 17 15:15:00 GMT 2004
A minimized test case:
int main() {
int y = 1;
int *x = &y;
volatile int sum = 0;
while(1) {
sum += *x;
x++;
}
return 0;
}
Clearly, this should crash; under 3.4.1 it does. Under my checkout of a few
hours ago, however, it does not: instead, it enters an infinite loop (everything
inside the while(1) gets optimized away and we're left with just a jmp).
Workaround: make either x or sum volatile. This forces it to actually do the
computations inside the loop.
I'm not sure whether to view this as a compiler bug: this code is, at heart,
morally unbalanced. But it is a change in behaviour so I figured I'd report it.
--
Summary: 4.0 optimizes away a SEGV; 3.4.1 does not
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bh at techhouse dot brown dot edu
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19056
More information about the Gcc-bugs
mailing list