https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69619
Bug ID: 69619 Summary: [6 Regression] compilation doesn't terminate during CCMP expansion Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: compile-time-hog, memory-hog Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- Target: aarch64 Testcase: int a, b, c, d; int e[1]; void fn1 () { int *f = &d; c = 6; for (; c; c--) { b = 0; for (; b <= 5; b++) { short g = e[(b + 2) * 9 + c]; *f = *f == a && e[(b + 2) * 9 + c]; } } } Given -O3 for aarch64 GCC doesn't terminate compilation and seems to keep eating more and more memory. The testcase does contain undefined behaviour and GCC warns about it: mycrash.c: In function 'fn1': mycrash.c:13:22: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations] short g = e[(b + 2) * 9 + c]; ~^~~~~~~~~~~~~~~~~ mycrash.c:11:7: note: within this loop for (; b <= 5; b++) but GCC shouldn't go into an infinite loop. At -O2 the testcase compiles instantaneously. Interrupting compilation in gdb and dumping the callstack shows that it's recursing deeply into the ccmp expansion code. After a few seconds of compilation I see a stack frame more than 400 levels deep with expand_ccmp_expr appearing periodically in there, though I don't know if that's the ccmp expand code's fault or the tree optimisers' fault. I can provide the tree dumps if needed, though they should be easy to reproduce with a recent aarch64 compiler