Bug 40623 - variable seems to be optimised out incorrectly
Summary: variable seems to be optimised out incorrectly
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-02 17:53 UTC by Rafał Mużyło
Modified: 2009-07-02 20:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.3.4 4.4.1 4.5.0
Known to fail: 4.3.2 4.3.3 4.4.0
Last reconfirmed:


Attachments
a testcase for the bug (432 bytes, text/plain)
2009-07-02 18:02 UTC, Rafał Mużyło
Details
data for the test (48 bytes, text/plain)
2009-07-02 18:08 UTC, Rafał Mużyło
Details
this is correct assembly (835 bytes, text/plain)
2009-07-02 20:35 UTC, Rafał Mużyło
Details
this is the incorrect one (654 bytes, text/plain)
2009-07-02 20:37 UTC, Rafał Mużyło
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rafał Mużyło 2009-07-02 17:53:22 UTC
I'm in doubt about exact compiler info,
cause I want to report a bug from Gentoo bugzilla,
where reporter was using 4.3.2, but I could reproduce it
with 4.4.0.
We're both on x86.
It's http://bugs.gentoo.org/show_bug.cgi?id=276146.

A rather simple code fragment gets miscompiled,
but after making a few changes, that arithmetically are no-ops,
it can be compiled correctly.
Comment 1 Rafał Mużyło 2009-07-02 18:02:16 UTC
Created attachment 18124 [details]
a testcase for the bug

As I said in the Gentoo bug,
one version of the 'area' line produces correct result,
other does not and while that 'printf' should arithmetically
be a no-op, it's required for correct compilation.
I forgot to add that at least -O is required to trigger the bug,
with -O0, both versions work fine, even without 'printf'.
Comment 2 Rafał Mużyło 2009-07-02 18:05:24 UTC
Due to that 'printf' thing, it seems vaguely similar
to bug 39333, however here neither of the switches mentioned there
has an effect.
Comment 3 Rafał Mużyło 2009-07-02 18:08:02 UTC
Created attachment 18125 [details]
data for the test
Comment 4 Paolo Carlini 2009-07-02 18:26:07 UTC
Can't reproduce in any active branch, thus already fixed for 4.5.0, 4.4.1, 4.3.4 (maybe 4.3.3 too).
Comment 5 Rafał Mużyło 2009-07-02 20:33:13 UTC
It definitely doesn't work in 4.3.3.
I'll attach generated assembly.
Comment 6 Rafał Mużyło 2009-07-02 20:35:47 UTC
Created attachment 18127 [details]
this is correct assembly

...when 'printf' and '(x0*(y0+dy) - (x0+dx)*y0)'
Comment 7 Rafał Mużyło 2009-07-02 20:37:36 UTC
Created attachment 18128 [details]
this is the incorrect one

...with 'printf' and 'x0*y1-x1*y0'
Both with '-O2' (though -0 is enough).
Comment 8 Rafał Mużyło 2009-07-02 20:42:46 UTC
Though perhaps I didn't need to reopen.
Just making sure: could you reproduce it with one of
the mentioned versions ?
Comment 9 Paolo Carlini 2009-07-02 20:47:17 UTC
Yes, is not fixed in 4.3.3. Is already fixed for 4.3.4, etc.