c++/4643: multiple inheritance problem on arm using gcc 3.0.1

andy.parker@oxsemi.com andy.parker@oxsemi.com
Mon Oct 22 04:46:00 GMT 2001


>Number:         4643
>Category:       c++
>Synopsis:       multiple inheritance problem on arm using gcc 3.0.1
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 22 04:46:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     andy.parker@oxsemi.com
>Release:        gcc 3.0.1
>Organization:
>Environment:
Host: Linux mars 2.2.19-7.0.8 #1 Thu Jun 21 06:28:56 EDT 2001 i686 unknown 
Target: arm-elf
Configured with: /files/parker/src/gcc/gcc-3.0.1/configure --target=arm-elf --prefix=/files2/apps/gcc-3.0.1 --exec-prefix=/files2/apps/gcc-3.0.1/i686-pc-linux --with-gnu-as --with-newlib --with-gnu-ld --enable-sjlj-exceptions --disable-shared -v
Thread model: single
gcc version 3.0.1
>Description:
I have a struct and a pair of base classes A & B each containing a virtual method F() which returns an instance of the struct. I have a derived class C which overloads F().
The this pointer corrupts during execution of the code as described below. 

In the class definitions, I simply write the this pointer to an output port ( cdbg() ) and return a copy of the struct instance. The entry function on my embedded system is C_Entry

In C_Entry I have two base class pointers (a,b) and one derived class pointer (c), all pointing to a derived class instance (c_obj). I output the pointers to the debug port from C_Entry and also within the class methods.  I am unsurprised to see some maniplulation of the this pointer of the base class pointers but I believe that c's pointer should be inconsistent, which it clearly is not.


>How-To-Repeat:
Code:
struct Wibble {  int blah[1]; };

class A
{
public:
    virtual Wibble F();
};
class B
{
public:
    virtual Wibble F();
};


class C : public A, public B
{
public:
    Wibble F();
};
Wibble wibble;
Wibble A::F()
{
    cdbg() << "A:" << (int) this << "\n";
    return (wibble);
}
Wibble B::F()
{
    cdbg() << "B:" << (int) this << "\n";
    return (wibble);
}
Wibble C::F()
{
    cdbg() << "C:" << (int) this << "\n";
    return (wibble);
}

int C_Entry(void)
{
    C c_obj;
    C* c = &c_obj;
    cdbg() << SerPortStream::hex;
    A * a = c;
    B * b = c;
    cdbg() << "A:" << (int) a << "\n";
    cdbg() << "B:" << (int) b << "\n";
    cdbg() << "C:" << (int) c << "\n";
    a->F();
    b->F();
    c->F();
    cdbg() << "Complete\n";
    return (0);
}

Compilation settings:
arm-elf-g++ -pipe -Wall  -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -mlittle-endian -mno-sched-prolog -fno-omit-frame-pointer -fno-rtti -fno-exceptions -mcpu=arm9 -O2 -I./src -c src/a.cxx -o a.o

Run-time output:
A:3fddc
B:3fde0
C:3fddc
C:3fddc
C:3fde0
C:3fde0
Complete
>Fix:
If I change my struct definition to remove the array:
 
struct Wibble {  int blah; };

then I get output as expected:

A:3fddc
B:3fde0
C:3fddc
C:3fddc
C:3fddc
C:3fddc
Complete

Alternatively and in this case, I can return wibble by reference rather than value and get identical output.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list