From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22953 invoked by alias); 17 Apr 2002 19:26:03 -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 22925 invoked by uid 71); 17 Apr 2002 19:26:01 -0000 Resent-Date: 17 Apr 2002 19:26:01 -0000 Resent-Message-ID: <20020417192601.22924.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, gcc@sammal.pp.fi Received:(qmail 18276 invoked by uid 61); 17 Apr 2002 19:18:05 -0000 Message-Id:<20020417191804.18273.qmail@sources.redhat.com> Date: Wed, 17 Apr 2002 12:26:00 -0000 From: gcc@sammal.pp.fi Reply-To: gcc@sammal.pp.fi To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/6341: G++ 3.0.4: two instances are stored in the same memory address? X-SW-Source: 2002-04/txt/msg00897.txt.bz2 List-Id: >Number: 6341 >Category: c++ >Synopsis: G++ 3.0.4: two instances are stored in the same memory address? >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Wed Apr 17 12:26:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Jukka Suomela >Release: gcc version 3.0.4 >Organization: >Environment: Tried two platforms with the same results: 1) Debian Linux (kernel 2.4.18) on i386, gcc-3.0.4 from Debian package. 2) SunOS 5.5.1 on Sparc, gcc-3.0.4 hand-compiled with "../gcc-3.0.4/configure --prefix=/usr/local/gcc-3.0.4". Output generated by "g++ -v -save-temps -O test.cc" on platform 1: Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.4/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux Thread model: posix gcc version 3.0.4 /usr/lib/gcc-lib/i386-linux/3.0.4/cpp0 -lang-c++ -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ test.cc test.ii GNU CPP version 3.0.4 (cpplib) (i386 Linux/ELF) ignoring nonexistent directory "/usr/i386-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/include/g++-v3 /usr/include/g++-v3/i386-linux /usr/include/g++-v3/backward /usr/local/include /usr/lib/gcc-lib/i386-linux/3.0.4/include /usr/include End of search list. /usr/lib/gcc-lib/i386-linux/3.0.4/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cc -O -version -o test.s GNU CPP version 3.0.4 (cpplib) (i386 Linux/ELF) GNU C++ version 3.0.4 (i386-linux) compiled by GNU C version 3.0.4. as -V -Qy -o test.o test.s GNU assembler version 2.12.90.0.1 (i386-linux) using BFD version 2.12.90.0.1 20020307 Debian/GNU Linux /usr/lib/gcc-lib/i386-linux/3.0.4/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc-lib/i386-linux/3.0.4/../../../crt1.o /usr/lib/gcc-lib/i386-linux/3.0.4/../../../crti.o /usr/lib/gcc-lib/i386-linux/3.0.4/crtbegin.o -L/usr/lib/gcc-lib/i386-linux/3.0.4 -L/usr/lib/gcc-lib/i386-linux/3.0.4/../../.. test.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i386-linux/3.0.4/crtend.o /usr/lib/gcc-lib/i386-linux/3.0.4/../../../crtn.o >Description: See the preprocessed (test.ii) code in "How-To-Repeat" section. When compiled without -O or with g++ 2.95.2, the output looks like this: X2: 1 0xbffffbf4 X2: 2 0xbffffbf8 ~X: 1 0xbffffbf4 X1: 3 0xbffffbf0 ~X: 3 0xbffffbf0 ~X: 2 0xbffffbf8 Looks fine. But, when compiled with g++ 3.0.4 and -O (or -O2 or -O3), the output looks like this: X2: 1 0xbffffbd4 X2: 2 0xbffffbe4 X1: 3 0xbffffbd4 ~X: 3 0xbffffbd4 ~X: 2 0xbffffbe4 ~X: 3 0xbffffbd4 It seems that the 1st and the 3rd instance of X use the same memory area at the same time. And the value of x in the first instance gets overwritten by the value of x in the 3rd instance. The command line used was: g++ -O test.cc There was no compiler output (warnings or errors). (PS. The help page of gnatsweb said about the Submitter-Id field that "If this is unknown, leave the default setting.". However, the default setting "unknown" didn't work. That's why I selected "net", without knowing what it means...) >How-To-Repeat: # 1 "test.cc" extern "C" int printf(const char *format, ...); static int y = 0; class X { public: X(const X& o) { x = ++y; printf("X1: %d %p\n", x, this); } X() { x = ++y; printf("X2: %d %p\n", x, this); } ~X() { printf("~X: %d %p\n", x, this); } private: int x; }; inline X a(X r) { return X(); } inline void b(X r) {} inline void c(X r) { b(r); } int main(void) { c(a(X())); } >Fix: No fix known. >Release-Note: >Audit-Trail: >Unformatted: