Configured with: /home/ajd/gcc-3.4.2/configure --prefix=/opt/gcc-3.4.2 --
enable-languages=c,c++ --enable-threads=posix --with-gnu-as --without-gnu-ld --
with-as=/usr/local/bin/as
Thread model: posix
gcc version 3.4.2

Also reproduced on 3.4.0 and 3.3.2.

The following code segfaults at runtime.

Compiling without any options or optimization (ILP32 mode).

$ g++ test.cpp
$ ./a.out
Memory fault(coredump)

The fault is on the line 'start = src.m_s;', but I believe the problem is in 
the argument passing to change.

-----

class var
{
public:
 var();
 var(const var& copy);
 ~var();
 char *m_s;
public:
};

void change(var src, var from)
{
  char *start;
  start = src.m_s;
}


int main()
{
        var x;
        change(x, x);
        return 0;
}

var::~var()
{

}

var::var(const var& r)
{
        m_s = "UUU";
}

var::var()
{
        m_s = "UUU";
}

-----


The following assembly is produced for the call to change:

        adds r14 = -48, r35
        ;;
        mov r37 = r14
        adds r15 = -64, r35
        ;;
        mov r38 = r15
[.LEHB1:]
        br.call.sptk.many b0 = _ZN3varC1ERKS_#
[.LEHE1:]
        mov r1 = r36
        adds r15 = -48, r35
        adds r14 = -8, r35
        ;;
        st8 [r14] = r15
        adds r14 = -32, r35
        ;;
        mov r37 = r14
        adds r14 = -64, r35
        ;;
        mov r38 = r14
[.LEHB2:]
        br.call.sptk.many b0 = _ZN3varC1ERKS_#
        mov r1 = r36
        adds r14 = -32, r35
        adds r15 = -4, r35
        ;;
        ld4 r37 = [r15]
        mov r38 = r14
        br.call.sptk.many b0 = _Z6change3varS_#
        mov r1 = r36

The last 4 lines is where it appears to go wrong.
EG: it is loading from memory at [r15] which is uninitialized.

-- 
           Summary: Wrong code for function call involving copy constuctor
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ajd at gentrack dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: ia64-hp-hpux11.23
  GCC host triplet: ia64-hp-hpux11.23
GCC target triplet: ia64-hp-hpux11.23


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18214

Reply via email to