https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88867
Bug ID: 88867 Summary: -Waggressive-loop-optimizations doesn't warn when -faggressive-loop-optimizations is in play Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: levon at movementarian dot org Target Milestone: --- Given how dangerous -faggressive-loop-optimizations has been proven to be, it's unfortunate that -Waggressive-loop-optimizations is non-functional in even simple cases. For example this test case: #define NULL ((void *)0) static char *arr[2] = { "nasal", "demons" }; long func() { int i; for (i = 0; i <= 2; i++) { if (arr[i] == NULL && i == 0) return (0xbad); } return (0xfad); } Is optimized to "return 0xbad" with -faggressive-loop-optimizations, but it is not possible to get GCC to warn about this. -Waggressive-loop-optimizations should warn every single time it relies on out-of-bounds behaviour like this. Otherwise, such code becomes impossible to find and fix. Same with trunk gcc on godbolt: https://godbolt.org/z/MN1beq