public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/6341: G++ 3.0.4: two instances are stored in the same memory address?
@ 2002-04-17 12:26 gcc
  0 siblings, 0 replies; 2+ messages in thread
From: gcc @ 2002-04-17 12:26 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c++/6341: G++ 3.0.4: two instances are stored in the same memory address?
@ 2002-04-17 18:58 rodrigc
  0 siblings, 0 replies; 2+ messages in thread
From: rodrigc @ 2002-04-17 18:58 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gcc, nobody

Synopsis: G++ 3.0.4: two instances are stored in the same memory address?

State-Changed-From-To: open->closed
State-Changed-By: rodrigc
State-Changed-When: Wed Apr 17 18:58:54 2002
State-Changed-Why:
    Compiling with gcc 3.0.4, I get:
    
    X2: 1 0xbffff670
    X2: 2 0xbffff680
    X1: 3 0xbffff670
    ~X: 3 0xbffff670
    ~X: 2 0xbffff680
    ~X: 3 0xbffff670
    
    Compiling with gcc 3.1 (prerelease) I get:
    X2: 1 0xbffff660
    X2: 2 0xbffff670
    X1: 3 0xbffff650
    ~X: 3 0xbffff650
    ~X: 2 0xbffff670
    ~X: 1 0xbffff660

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6341


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-18  1:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-17 12:26 c++/6341: G++ 3.0.4: two instances are stored in the same memory address? gcc
2002-04-17 18:58 rodrigc

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).