Mayur Pandey
2012-Nov-29 07:10 UTC
[LLVMdev] operator overloading fails while debugging with gdb for i386
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 -- Thanx & Regards *Mayur Pandey * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121129/75068cf8/attachment.html>
Mayur Pandey
2012-Dec-01 11:13 UTC
[LLVMdev] operator overloading fails while debugging with gdb for i386
Problem seems not only with operator overloading, It occurs with struct value returning also. gdb while debugging expects the return value in eax, gcc does returns in eax, But Clang returns in edx(it can be checked in gdb by printing the contents of edx). Code(sample code) struct A1 { int x; int y; }; A1 sum(const A1 one, const A1 two) { A1 plus = {0,0}; plus.x = one.x + two.x; plus.y = one.y + two.y; return (plus); } int main (void) { A1 one= {2,3}; A1 two= {4,5}; A1 three = sum(one,two); return 0; } gcc assembley (snippet of sum function) _Z3sum2A1S_: .loc 1 8 0 pushl %ebp movl %esp, %ebp .loc 1 9 0 movl 8(%ebp), %eax movl $0, (%eax) movl 8(%ebp), %eax movl $0, 4(%eax) .loc 1 10 0 movl 12(%ebp), %edx movl 20(%ebp), %eax addl %eax, %edx movl 8(%ebp), %eax movl %edx, (%eax) .loc 1 11 0 movl 16(%ebp), %edx movl 24(%ebp), %eax addl %eax, %edx movl 8(%ebp), %eax movl %edx, 4(%eax) .LBE2: .loc 1 14 0 *movl 8(%ebp), %eax* popl %ebp ret $4 clang assembly (snippet of sum function) _Z3sum2A1S_: .loc 1 8 0 pushl %edi pushl %esi leal 24(%esp), %eax leal 16(%esp), %ecx movl 12(%esp), %edx .loc 1 9 17 prologue_end movl $0, 4(%edx) movl $0, (%edx) .loc 1 10 2 movl (%ecx), %esi movl (%eax), %edi addl %edi, %esi movl %esi, (%edx) .loc 1 11 2 movl 4(%ecx), %ecx movl 4(%eax), %eax addl %eax, %ecx *movl %ecx, 4(%edx)* .loc 1 13 2 popl %esi popl %edi ret $4 But while returning int value clang returns with eax... as expect. Problem comes with when used struct/class Is the behaviour of llvm as per the standards or is this a bug?? On Thu, Nov 29, 2012 at 12:40 PM, Mayur Pandey <mayurthebond at gmail.com>wrote:> 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 > > > > -- > Thanx & Regards > *Mayur Pandey * > > > > > >-- Thanx & Regards *Mayur Pandey * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121201/7ca25356/attachment.html>
James Molloy
2012-Dec-01 16:12 UTC
[LLVMdev] operator overloading fails while debugging with gdb for i386
Hi, Structures are passed by pointer, so the return value is not actually in eax. That code gets transformed into something like: void sum(A1 *out, const A1 one, const A1 two) { out->x = one.x + two.x out->y = one.y + two.y } So actually the function ends up returning void and operating on a hidden parameter, so %eax is dead at the end of the function and should not be being relied upon by the calling code. I believe this is a red-herring to whatever your actual bug is. Cheers, James ________________________________________ From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] On Behalf Of Mayur Pandey [mayurthebond at gmail.com] Sent: 01 December 2012 11:13 To: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] operator overloading fails while debugging with gdb for i386 Problem seems not only with operator overloading, It occurs with struct value returning also. gdb while debugging expects the return value in eax, gcc does returns in eax, But Clang returns in edx(it can be checked in gdb by printing the contents of edx). Code(sample code) struct A1 { int x; int y; }; A1 sum(const A1 one, const A1 two) { A1 plus = {0,0}; plus.x = one.x + two.x; plus.y = one.y + two.y; return (plus); } int main (void) { A1 one= {2,3}; A1 two= {4,5}; A1 three = sum(one,two); return 0; } gcc assembley (snippet of sum function) _Z3sum2A1S_: .loc 1 8 0 pushl %ebp movl %esp, %ebp .loc 1 9 0 movl 8(%ebp), %eax movl $0, (%eax) movl 8(%ebp), %eax movl $0, 4(%eax) .loc 1 10 0 movl 12(%ebp), %edx movl 20(%ebp), %eax addl %eax, %edx movl 8(%ebp), %eax movl %edx, (%eax) .loc 1 11 0 movl 16(%ebp), %edx movl 24(%ebp), %eax addl %eax, %edx movl 8(%ebp), %eax movl %edx, 4(%eax) .LBE2: .loc 1 14 0 movl 8(%ebp), %eax popl %ebp ret $4 clang assembly (snippet of sum function) _Z3sum2A1S_: .loc 1 8 0 pushl %edi pushl %esi leal 24(%esp), %eax leal 16(%esp), %ecx movl 12(%esp), %edx .loc 1 9 17 prologue_end movl $0, 4(%edx) movl $0, (%edx) .loc 1 10 2 movl (%ecx), %esi movl (%eax), %edi addl %edi, %esi movl %esi, (%edx) .loc 1 11 2 movl 4(%ecx), %ecx movl 4(%eax), %eax addl %eax, %ecx movl %ecx, 4(%edx) .loc 1 13 2 popl %esi popl %edi ret $4 But while returning int value clang returns with eax... as expect. Problem comes with when used struct/class Is the behaviour of llvm as per the standards or is this a bug?? On Thu, Nov 29, 2012 at 12:40 PM, Mayur Pandey <mayurthebond at gmail.com<mailto:mayurthebond at gmail.com>> wrote: 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 -- Thanx & Regards Mayur Pandey -- Thanx & Regards Mayur Pandey
Maybe Matching Threads
- [LLVMdev] operator overloading fails while debugging with gdb for i386
- [LLVMdev] operator overloading fails while debugging with gdb for i386
- [LLVMdev] operator overloading fails while debugging with gdb for i386
- [LLVMdev] operator overloading fails while debugging with gdb for i386
- [LLVMdev] initialization list with conversion operator dont work properly and report error