extern "C" void abort ();
struct A
{
int f;
A (int x) : f (x) {}
};
A
foo (const A &x, const A &y)
{
A r (0);
r = x.f == -111 ? y : (y.f == -111 || x.f > y.f) ? x : y;
A s (0);
r = r.f == -111 ? s : (r.f > s.f) ? r : s;
return r;
}
int
main ()
{
A a (A(0));
int b[] = { 1, 2, 9 };
for (int i = 0; i < 3; i++)
{
A c (b[i]);
if (foo (a, c).f != b[i])
abort ();
a = c;
}
}
is miscompiled on i?86-linux with -O2 -m32. From quick glance at the dumps,
dce3 removes a needed statement:
<retval>.fD.2005 = SR.23D.2103_26;
but already *.alias1 seems to be wrong:
# BLOCK 11
# PRED: 10 (true)
<L8>:;
iftmp.3D.2049_27 = &<retval>;
goto <bb 13> (<L10>);
# SUCC: 13 (fallthru)
# BLOCK 12
# PRED: 10 (false)
<L9>:;
iftmp.3D.2049_28 = &sD.2036;
# SUCC: 13 (fallthru)
# BLOCK 13
# PRED: 11 (fallthru) 12 (fallthru)
# iftmp.3D.2049_2 = PHI <iftmp.3D.2049_27(11), iftmp.3D.2049_28(12)>;
<L10>:;
iftmp.2D.2047_29 = iftmp.3D.2049_2;
goto <bb 15> (<L12>);
# SUCC: 15 (fallthru)
# BLOCK 14
# PRED: 9 (false)
<L11>:;
iftmp.2D.2047_30 = &sD.2036;
# SUCC: 15 (fallthru)
# BLOCK 15
# PRED: 13 (fallthru) 14 (fallthru)
# iftmp.2D.2047_1 = PHI <iftmp.2D.2047_29(13), iftmp.2D.2047_30(14)>;
<L12>:;
# D.2051_32 = V_MUST_DEF <D.2051_31>;
# VUSE <SFT.6D.2086_23>;
D.2051 = *iftmp.2D.2047_1;
Note that iftmp.2D.2047_1 can be either &sD.2036 (in that case it really VUSEs
SFT.6D.2086_23), but it can also be &<retval> and that's not stored anywhere.
--
Summary: [4.1/4.2 Regression] Miscompilation with RESULT_DECL
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jakub at gcc dot gnu dot org
GCC target triplet: i386-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32353