From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3057 invoked by alias); 17 Apr 2002 09:16:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3006 invoked by uid 71); 17 Apr 2002 09:16:02 -0000 Resent-Date: 17 Apr 2002 09:16:01 -0000 Resent-Message-ID: <20020417091601.3004.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, dh@digitalbrain.com Received:(qmail 539 invoked by uid 61); 17 Apr 2002 09:11:09 -0000 Message-Id:<20020417091109.537.qmail@sources.redhat.com> Date: Wed, 17 Apr 2002 02:16:00 -0000 From: dh@digitalbrain.com Reply-To: dh@digitalbrain.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/6330: tiny C++ prog broken under -O1 X-SW-Source: 2002-04/txt/msg00878.txt.bz2 List-Id: >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 ' > 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: