public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: gcc@sammal.pp.fi To: gcc-gnats@gcc.gnu.org Subject: c++/6341: G++ 3.0.4: two instances are stored in the same memory address? Date: Wed, 17 Apr 2002 12:26:00 -0000 [thread overview] Message-ID: <20020417191804.18273.qmail@sources.redhat.com> (raw) >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:
next reply other threads:[~2002-04-17 19:26 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-04-17 12:26 gcc [this message] 2002-04-17 18:58 rodrigc
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=20020417191804.18273.qmail@sources.redhat.com \ --to=gcc@sammal.pp.fi \ --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: linkBe 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).