This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/34768] New: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Jan 2008 13:22:41 -0000
- Subject: [Bug middle-end/34768] New: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
int x;
void __attribute__((noinline)) foo (void)
{
x = -x;
}
void __attribute__((const,noinline)) bar (void)
{
}
int __attribute__((noinline))
test (int c)
{
int tmp = x;
(c ? foo : bar) ();
return tmp + x;
}
extern void abort (void);
int main()
{
x = 1;
if (test (1) != 0)
abort ();
return 0;
}
creates wrong code because the side-effect of the call to foo() is not
accounted for.
Since the merge of tree-ssa already gimplification removes the function call.
Thus, the above fails with -O0.
If you modify the testcase to use the return-value, you see that wrong
alias information is created because we appearantly use the const attribute
for the indirect call.
int x;
int __attribute__((noinline)) foo (void)
{
x = -x;
return 0;
}
int __attribute__((const,noinline)) bar (void)
{
return 0;
}
int __attribute__((noinline))
test (int c)
{
int tmp = x;
int res = (c ? foo : bar) ();
return tmp + x + res;
}
extern void abort (void);
int main()
{
x = 1;
if (test (1) != 0)
abort ();
return 0;
}
alias produced is:
test (c)
{
int res;
int tmp;
int D.1207;
int x.3;
int D.1205;
int (*<T240>) (void) iftmp.2;
<bb 2>:
# VUSE <x_11(D)>
tmp_2 = x;
if (c_3(D) != 0)
goto <bb 4>;
else
goto <bb 3>;
<bb 3>:
<bb 4>:
# iftmp.2_1 = PHI <foo(2), bar(3)>
res_6 = iftmp.2_1 ();
# VUSE <x_11(D)>
x.3_7 = x;
D.1207_8 = tmp_2 + x.3_7;
D.1205_9 = D.1207_8 + res_6;
return D.1205_9;
}
and we happily CSE the load from x. This testcase requires -O to fail.
--
Summary: [4.1/4.2/4.3 Regression] Wrong code with conditional
function invocation
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34768