This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/OMAP-L138: Virtual Inheritance with common ancestor issue. (Diamond problem)

Part Number: OMAP-L138
Other Parts Discussed in Thread: MSP-EXP432E401Y

Tool/software: TI C/C++ Compiler

I am having a problem with virtual inheritance of a common ancestor and was wondering if anyone had seen the same issue or know of a workaround.

I have four int attributes in the base class that get initialised to 0 in the base class but upon completion of instantiation the four variables contain random values.

[CCS8.0.0.00016 on Windows 7 64bit]

It looks like this:

class A

{
public:
    virtual ~A(){};


protected:
    A() :
    a(0),
    b(0),
    c(0),
    d(0)
    {};

private:
    int a;
    int b;
    int c;
    int d;
};

class B : public virtual A
{
public:
    virtual ~B(){};

protected:
    B(){};
};

class C : public virtual A
{
public:
    virtual ~C(){};

protected:
    C(){};
};

class D : public B, public C
{
public:
    D(){};
    virtual ~D(){};
};

Walking through each of the constructors with the debugger the values are clearly initialised in the base class attributes to 0 but as I move up to each of the inheriting constructors each of the inheriting classes has its own addresses for the attributes which have moved slightly. the last two attributes (c & d) are referencing the top two (a & b) while a & b appear to be referencing the vtable!

Any ideas?

Thanks in advance.

Andy.

  • Andrew Southby said:
    Walking through each of the constructors with the debugger

    Perhaps this is a debugger display problem.  When you run through the code normally, does it compute the expected result?  If not, then please submit a test case based on one source file with the problem, as described in the article How to Submit a Compiler Test Case.  Add some comments similar to ...

    // Expect to see result AAA in variable VVV, but see result BBB instead

    Thanks and regards,

    -George

  • Hi George,

    You are correct it is the debugger displaying incorrect values not the compiler. Is there a way of moving this to a debugger forum?

    Thanks,
    Andy.
  • Hi Andy,
    It has been moved to the debugger forum. Are you debugging the ARM or DSP of the OMAP L138? Actually, if you have a simple test case with a compiled executable, that would be most helpful (a zip of the executable + source).

    Thanks
    ki
  • Hello,
    I haven’t heard back from you, I’m assuming you were able to resolve your issue. If not, please post a reply with an update below (or create a new thread).

    thanks,
    ki
  • Ki-Soo Lee said:
    Actually, if you have a simple test case with a compiled executable, that would be most helpful (a zip of the executable + source).

    I took the example code fragment from Andy and created the attached example project for a MSP-EXP432E401Y. It has build configurations which use:

    a) TI ARM compiler v18.1.1.LTS

    b) GNU ARM compiler v7.2.1

    The example sets the field members a=1, b=2, c=3, d=4 and includes a get() method which demonstrates the code executes correctly, but that the CCS 8.0.0.00016 debugger can incorrectly show the values of the fields.

    1) With the TI compiler at the end of the constructor for A the fields are shown correctly:

    At the end of the constructor for D all fields are shown with incorrect values, and the Location reported for the fields differs from that shown above:

    At the end of the main function after the call to to d_test.get() the local variables a, b, c, d obtained from the get() call have the correct values, but the debugger is still displaying the incorrect field values for d_test:

    2) With the GNU compiler at the end of the constructor for A the fields are shown correctly:

    At the end of the constructor for D all fields are shown with incorrect values, and the Location reported for the fields differs from that shown above:

    At the end of the main function after the call to to d_test.get() the local variables a, b, c, d obtained from the get() call have the correct values, but the debugger is still displaying the incorrect field values for d_test:

    MSP432E401Y_virtual_inheritence.zip

  • Thank you Chester. Bug has been filed for this. Tracking ID: CCSIDE-3345