This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count
- From: "ppluzhnikov at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 29 Apr 2013 23:18:29 +0000
- Subject: [Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count
- Auto-submitted: auto-generated
- References: <bug-53265-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53265
--- Comment #27 from Paul Pluzhnikov <ppluzhnikov at google dot com> 2013-04-29 23:18:29 UTC ---
Here is a reduced test case in which g++ (GCC) 4.9.0 20130426 (experimental)
produces infinite loop with -O2 due to aggressive loop optimization, but
doesn't warn (making the bug in user code hard to find).
g++ -O2 test.cc -Wall && ./a.out
Segmentation fault
g++ -O2 test.cc -Wall -fno-aggressive-loop-optimizations && ./a.out && echo ok
ok
struct Puzzle
{
int r[9];
int ignored[18];
} p;
int a, b;
int main()
{
int c = 0;
for (b = 0; b < 27; b++)
{
if (p.r[b] == 0)
c |= p.r[a];
if (c != 0)
return c;
}
return c;
}