This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/2372: const struct parameter causes incorrect code with -O2.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2372: const struct parameter causes incorrect code with -O2.
- From: suckfish at ihug dot co dot nz
- Date: 24 Mar 2001 04:22:47 -0000
- Reply-To: suckfish at ihug dot co dot nz
>Number: 2372
>Category: c++
>Synopsis: const struct parameter causes incorrect code with -O2.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Mar 23 20:26:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: suckfish@ihug.co.nz
>Release: 2001-03-20 snapshot.
>Organization:
>Environment:
Linux i686.
>Description:
The function "miscompiled" in the attached file is not
compiled correctly with -O2 -march=i686.
By inspecting the assembler output for the function "miscompiled", one can see that a temporary stack variable is loaded without being set.
I discovered this in code using std::make_pair. The current prototype (with __GLIBCPP_RESOLVE_LIB_DEFECTS) has extraneous "const" decorations. Removing those would stop the use std::make_pair from triggering this bug.
>How-To-Repeat:
Compile attached file on Linux with -O2 -march=i686.
Confirm bug by running program or visually inspecting assembler.
Running the program prints "***Buggy***". It should
print "OK".
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="temp.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="temp.cc"
Ly8gREVDTEFSQVRJT05TCgpzdHJ1Y3QgUmVjb3JkIHsKICAgUmVjb3JkIChpbnQgYmIpIDoKICAg
ICAgYiAoYmIpCiAgICAgIHsgfQogICBpbnQgZXh0cmE7ICAgLy8gSGF2aW5nIGFuIGV4dHJhIG1l
bWJlciBpbiByZWNvcmQgaXMgY3J1Y2lhbC4KICAgaW50IGI7Cn07CiAgICAgIApzdHJ1Y3QgQ29u
dGFpbmVyIHsKICAgUmVjb3JkIHJlY29yZDsKICAgLy8gVGhlIGNvbnN0IG9uIHRoZS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