llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.83k stars 11.91k forks source link

operator overloading fails while debugging with gdb for i386. #14726

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 14354
Version unspecified
OS Linux
Attachments assembly file for the code
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@echristo

Extended Description

For the given test:

class A1 { int x; int y;

public:

A1(int a, int b) { x=a; y=b; }

A1 operator+(const A1&); };

A1 A1::operator+(const A1& second) { A1 sum(0,0); sum.x = x + second.x; sum.y = y + second.y;

return (sum); }

int main (void) { A1 one(2,3); A1 two(4,5);

return 0; }

when the exectable of this code is debugged in gdb for i386, we dont get the expected results.

when we break at return 0; and give the command: print one + two, the result should be $1 = {x = 6, y = 8}, but the result obtained is $1 = {x = 2, y = 3}.

This is related to debug information generated, as normally the overloading is occuring. eg: A1 three = one + two results {x = 6, y = 8}.

On checking the assembly, a suspicious entry is found which may be related for the failure:

#DEBUG_VALUE: operator+:this <- undef
#DEBUG_VALUE: operator+:second <- undef
echristo commented 10 years ago

Still a problem for 32-bit.

llvmbot commented 11 years ago

In the above case, we see that the operator+ function's return value is returned in register edx. But gdb expects the return value in eax.

http://stackoverflow.com/questions/267674/inspect-the-return-value-of-a-function-in-gdb

so if we add the assembly instruction: movl %edx, %eax just before .loc 1 22 2 instruction in the assembly file and then compile with clang++ and run the executable, we get the desired results in gdb.

So probably this could be the reason. If this is it we might need to add another machine instruction. Just needs to be verified properly.

llvmbot commented 11 years ago

it was compiled using -O0.

echristo commented 11 years ago

Was this compiled with -O0 or some optimization?

dwblaikie commented 11 years ago

Eric - this was the bug I was mentioning a few days ago.

I haven't looked into/tried to reproduce it yet, but figured one of us will get to it sooner or later