public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: dh@digitalbrain.com
To: gcc-gnats@gcc.gnu.org
Subject: optimization/6330: tiny C++ prog broken under -O1
Date: Wed, 17 Apr 2002 02:16:00 -0000 [thread overview]
Message-ID: <20020417091109.537.qmail@sources.redhat.com> (raw)
>Number: 6330
>Category: optimization
>Synopsis: tiny C++ prog broken under -O1
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 17 02:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: dh@digitalbrain.com
>Release: 2.95.4 20011002 (Debian prerelease)
>Organization:
>Environment:
gcc version 2.95.4 20011002 (Debian prerelease)
Linux fee 2.4.18-p7-rmap12c-r #267 SMP Mon Feb 4 12:05:56 GMT 2002 i686 unknown
>Description:
Taking the address of an automatic variable says to the compiler "don't use a register for this!".
But I suspect that casting an automatic variable into another type and then taking the address of That
doesn't say anything of the kind
(even though it should)
>How-To-Repeat:
this linux console output shows a tiny shell script
being run that duplicates the problem ..
5750:fee:~: cat ./show_gcc_bug.sh
#!/bin/sh
# what compiler/OS version is it?
gcc -v
uname -a
# create a program
echo '#include <stdio.h>' > x.cpp
echo 'typedef unsigned char byte;' >> x.cpp;
echo 'void change(byte **z) { *z = (byte*)"correct"; }' >> x.cpp
echo 'int main() {' >> x.cpp
echo ' char *s = "incorrect";' >> x.cpp
echo ' change(&(byte*)s);' >> x.cpp
echo ' printf("%s\n", s);' >> x.cpp
echo ' exit(0);' >> x.cpp
echo '}' >> x.cpp
# compile and run it
gcc x.cpp
./a.out
# compile and run The Same Program optimized
gcc -O1 x.cpp
./a.out
5751:fee:~: ./show_gcc_bug.sh
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
Linux fee 2.4.18-p7-rmap12c-r #267 SMP Mon Feb 4 12:05:56 GMT 2002 i686 unknown
correct
incorrect
5752:fee:~:
>Fix:
no fix known ..
work arounds:
1)
change the x.cpp from &(byte*)s
to (byte**)&s
2)
rename x.cpp to x.c
because the C front end will give the error
"x.c:6: invalid lvalue in unary `&'"
rather than make incorrect code
>Release-Note:
>Audit-Trail:
>Unformatted:
next reply other threads:[~2002-04-17 9:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-17 2:16 dh [this message]
2002-04-17 17:41 rth
2002-04-22 2:06 David Hanney
2002-04-22 9:36 Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020417091109.537.qmail@sources.redhat.com \
--to=dh@digitalbrain.com \
--cc=gcc-gnats@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).