public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59590] New: gcc produces an infinite loop on O2 optimization
@ 2013-12-24 2:15 cottrell at wfu dot edu
2013-12-24 2:33 ` [Bug c/59590] " pinskia at gcc dot gnu.org
2013-12-24 3:52 ` cottrell at wfu dot edu
0 siblings, 2 replies; 3+ messages in thread
From: cottrell at wfu dot edu @ 2013-12-24 2:15 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/59590] gcc produces an infinite loop on O2 optimization
2013-12-24 2:15 [Bug c/59590] New: gcc produces an infinite loop on O2 optimization cottrell at wfu dot edu
@ 2013-12-24 2:33 ` pinskia at gcc dot gnu.org
2013-12-24 3:52 ` cottrell at wfu dot edu
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-12-24 2:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59590
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
df[k+1] reads past the bounds of df as k is 0...RSTEPS-1 so k+1 is 1...RSTEPS
and the bounds of df is 0...RSTEPS-1.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/59590] gcc produces an infinite loop on O2 optimization
2013-12-24 2:15 [Bug c/59590] New: gcc produces an infinite loop on O2 optimization cottrell at wfu dot edu
2013-12-24 2:33 ` [Bug c/59590] " pinskia at gcc dot gnu.org
@ 2013-12-24 3:52 ` cottrell at wfu dot edu
1 sibling, 0 replies; 3+ messages in thread
From: cottrell at wfu dot edu @ 2013-12-24 3:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59590
--- Comment #2 from Allin Cottrell <cottrell at wfu dot edu> ---
OK, you're right, there's an off-by-one bug in the second
k-loop.
But it's not very nice that gcc takes that as a license to
produce an infinite loop. However, I guess that makes this
report a duplicate of some others that have made the same
observation.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-24 3:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-24 2:15 [Bug c/59590] New: gcc produces an infinite loop on O2 optimization cottrell at wfu dot edu
2013-12-24 2:33 ` [Bug c/59590] " pinskia at gcc dot gnu.org
2013-12-24 3:52 ` cottrell at wfu dot edu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).