Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR14354
Status NEW
Importance P enhancement
Reported by Mayur Pandey (mayur.p@samsung.com)
Reported on 2012-11-15 09:51:03 -0800
Last modified on 2014-04-11 21:21:30 -0700
Version unspecified
Hardware PC Linux
CC dblaikie@gmail.com, echristo@gmail.com, llvm-bugs@lists.llvm.org, mayurthebond@gmail.com, rafael@espindo.la
Fixed by commit(s)
Attachments manual_i386.s (32841 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 9547
assembly file for the code

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
Quuxplusone commented 11 years ago

Attached manual_i386.s (32841 bytes, text/plain): assembly file for the code

Quuxplusone 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

Quuxplusone commented 11 years ago

Was this compiled with -O0 or some optimization?

Quuxplusone commented 11 years ago

it was compiled using -O0.

Quuxplusone 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.
Quuxplusone commented 10 years ago

Still a problem for 32-bit.