https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79594
Bug ID: 79594 Summary: -Waggressive-loop-optimizations incomplete and/or inconsistentt Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vincenzo.innocente at cern dot ch Target Milestone: --- given cat aggressiveLoop.cc #include <cmath> #include<limits> float x[1024]; float y[1024]; float w[512]; float z[128]; float c,q; void foo() { for (int i=0; i<1024; ++i) { auto zz=z[i]; auto yy = y[i]; if(x[i] > q) yy = zz; y[i]=yy; } } void foo2() { for (int i=0; i<1024; ++i) { auto zz=z[i]; auto yy = w[i]; if(x[i] > q) yy = zz; x[i]=yy; } } void foo3() { for (int i=0; i<1024; ++i) { auto zz=z[i]; auto yy = w[i]; if(x[i] > q) yy = zz; w[i]=yy; } } gcc version 7.0.1 20170205 (experimental) [trunk revision 245191] (GCC) reports c++ -Wall -O2 aggressiveLoop.cc -S aggressiveLoop.cc: In function 'void foo()': aggressiveLoop.cc:13:9: warning: iteration 128 invokes undefined behavior [-Waggressive-loop-optimizations] auto zz=z[i]; ^~ aggressiveLoop.cc:12:18: note: within this loop for (int i=0; i<1024; ++i) { ~^~~~~ aggressiveLoop.cc: In function 'void foo2()': aggressiveLoop.cc:22:9: warning: iteration 128 invokes undefined behavior [-Waggressive-loop-optimizations] auto zz=z[i]; ^~ aggressiveLoop.cc:21:18: note: within this loop for (int i=0; i<1024; ++i) { ~^~~~~ aggressiveLoop.cc: In function 'void foo3()': aggressiveLoop.cc:34:8: warning: iteration 512 invokes undefined behavior [-Waggressive-loop-optimizations] w[i]=yy; ~~~~^~~ aggressiveLoop.cc:30:18: note: within this loop for (int i=0; i<1024; ++i) { ~^~~~~ while in foo2 there is also "auto yy = w[i];" and in foo3 both assignments auto zz=z[i]; auto yy = w[i]; will "invokes undefined behavior" at iterations 128 and 512...