public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: David Hanney <dh@digitalbrain.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: optimization/6330: tiny C++ prog broken under -O1
Date: Mon, 22 Apr 2002 02:06:00 -0000	[thread overview]
Message-ID: <20020422090601.19457.qmail@sources.redhat.com> (raw)

The following reply was made to PR optimization/6330; it has been noted by GNATS.

From: David Hanney <dh@digitalbrain.com>
To: rth@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
	gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: optimization/6330: tiny C++ prog broken under -O1
Date: Mon, 22 Apr 2002 10:02:00 +0100

 Many thanks for your prompt response!
 
 I assumed (wrongly, I know) that because "the cast-output is the same four 
 bytes
 as the cast-input" that it would be at the same address (union-style). My bad.
 
 But, given this behavior-set ..
 
     gcc with plain     C++ works.            (no compiler warning)
     gcc with optimized C++ doesn't work.     (no compiler warning)
     gcc with           C   doesn't compile.
    (under gcc 2.95.4 and gcc 3)
 
 .. would a compiler warning be useful here?
 
 Especially as the pointer may be formed implicitly via a reference
 (as shown in the code quoted below)
 
 cheers,
 
 DH
 
 -------------------------------------------
 #!/bin/sh
 
 # what compiler/OS version is it?
 gcc-3.0 -v
 uname -a
 
 # create a program
 echo '#include <stdio.h>' > x.cpp
 echo '#include <stdlib.h>' >> x.cpp
 echo 'typedef unsigned char byte;' >> x.cpp;
 echo 'typedef byte *pbyte;' >> x.cpp;
 echo 'void change(pbyte &z) { z = (pbyte)"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-3.0 x.cpp
 ./a.out
 
 # compile and run The Same Program optimized
 gcc-3.0 -O1 x.cpp
 ./a.out
 -------------------------------------------
 
 
 
 
 
 At 00:41 18/04/02 +0000, rth@gcc.gnu.org wrote:
 >Synopsis: tiny C++ prog broken under -O1
 >
 >State-Changed-From-To: open->closed
 >State-Changed-By: rth
 >State-Changed-When: Wed Apr 17 17:41:35 2002
 >State-Changed-Why:
 >     Not a bug.  You have taken the address of a temporary.
 >     You wanted "change((byte**)&s)".
 >
 >http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6330 
 >
 


             reply	other threads:[~2002-04-22  9:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-22  2:06 David Hanney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-04-22  9:36 Richard Henderson
2002-04-17 17:41 rth
2002-04-17  2:16 dh

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=20020422090601.19457.qmail@sources.redhat.com \
    --to=dh@digitalbrain.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@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).