http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59590
Bug ID: 59590 Summary: gcc produces an infinite loop on O2 optimization Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: cottrell at wfu dot edu Created attachment 31508 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31508&action=edit minimal test case I'm getting an infinite loop with -O2, though the code is compiled correctly with just -O. I'm attaching a minimal test case -- but please see also the real function that exposes the problem: the following is the real counterpart to fake_gradient() in the minimal case: static int richardson_gradient (double *b, double *g, int n, BFGS_CRIT_FUNC func, void *data) { double df[RSTEPS]; double eps = 1.0e-4; double d = 0.0001; double v = 2.0; double h, p4m; double bi0, f1, f2; int r = RSTEPS; int i, k, m; int err = 0; for (i=0; i<n; i++) { bi0 = b[i]; h = d * b[i] + eps * (b[i] == 0.0); for (k=0; k<r; k++) { b[i] = bi0 - h; f1 = func(b, data); b[i] = bi0 + h; f2 = func(b, data); if (na(f1) || na(f2)) { b[i] = bi0; return 1; } df[k] = (f2 - f1) / (2.0 * h); h /= v; } b[i] = bi0; p4m = 4.0; for (m=0; m<r-1; m++) { for (k=0; k<r-m; k++) { df[k] = (df[k+1] * p4m - df[k]) / (p4m - 1.0); // if (k == r-m-1) break; } p4m *= 4.0; } g[i] = df[0]; } return err; }