public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/2372: const struct parameter causes incorrect code with -O2.
@ 2001-03-23 20:26 suckfish
  0 siblings, 0 replies; only message in thread
From: suckfish @ 2001-03-23 20:26 UTC (permalink / raw)
  To: gcc-gnats

>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
dGFpbmVyIHsKICAgUmVjb3JkIHJlY29yZDsKICAgLy8gVGhlIGNvbnN0IG9uIHRoZSBuZXh0IGxp
bmUgaXMgY3J1Y2lhbC4KICAgQ29udGFpbmVyICggY29uc3QgUmVjb3JkICBiKSA6IHJlY29yZChi
KSB7fQp9OwoKCnZvaWQgdXNlX3BhaXIgKGNvbnN0IENvbnRhaW5lciAmKTsKCi8vIE1JU0NPTVBJ
TEVEIEZVTkNUSU9OCnZvaWQgbWlzY29tcGlsZWQgKGludCBuKQp7CiAgIHVzZV9wYWlyIChDb250
YWluZXIgKG4pKTsKfQoKCi8vIFRFU1QgRk9SIENPUlJFQ1QgQkVIQVZJT1VSCgppbnQgbXlBcnJh
eVszXTsKaW50ICogaW50cCA9IG15QXJyYXk7Cgp2b2lkIHVzZV9wYWlyIChjb25zdCBDb250YWlu
ZXIgJiBjKQp7CiAgICppbnRwKysgPSBjLnJlY29yZC5iOwp9CgpleHRlcm4gIkMiIGludCBwcmlu
dGYgKGNvbnN0IGNoYXIgKiwuLi4pOwoKaW50IG1haW4oKQp7CiAgIG1pc2NvbXBpbGVkICgxMjM0
KTsKICAgbWlzY29tcGlsZWQgKDU0MzIpOwogICBtaXNjb21waWxlZCAoMjQ2OCk7CgogICBpZiAo
bXlBcnJheVswXSA9PSAxMjM0ICYmCiAgICAgICBteUFycmF5WzFdID09IDU0MzIgJiYKICAgICAg
IG15QXJyYXlbMl0gPT0gMjQ2OCkgewogICAgICBwcmludGYgKCJPay5cbiIpOwogICB9CiAgIGVs
c2UgewogICAgICBwcmludGYgKCIqKipCVUdHWSoqKlxuIik7CiAgIH0KICAgcmV0dXJuIDA7Cn0K


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-03-23 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-23 20:26 c++/2372: const struct parameter causes incorrect code with -O2 suckfish

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).