Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBE miscompiles common C++ Code (bigfib, tramp3d, etc) #2030

Closed
lattner opened this issue Sep 14, 2007 · 9 comments
Closed

CBE miscompiles common C++ Code (bigfib, tramp3d, etc) #2030

lattner opened this issue Sep 14, 2007 · 9 comments
Labels
bugzilla Issues migrated from bugzilla miscompilation wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@lattner
Copy link
Collaborator

lattner commented Sep 14, 2007

Bugzilla Link 1658
Resolution WONTFIX
Resolved on Mar 26, 2012 05:57
Version 1.0
OS All
CC @asl,@d0k,@edwintorok,@sunfishcode,@nlewycky

Extended Description

Consider this code:

struct ctor {
void *foo;
ctor(const ctor &X);
ctor() {}
};

struct test {
unsigned char *field0;
};

test foo();
ctor bar();

void testfunc() {
test xx;
ctor yy;

xx = foo();
yy = bar();
}

In the GCC abi, single element structs are returned as registers, larger structs and any struct with a copy ctor are returned by passing a hidden "sret" pointer to the struct. llvm-gcc compiles this to:

    %tmp2 = call i8* @&#8203;_Z3foov( )            ; <i8*> [#uses=0]
    call void @&#8203;_Z3barv( %struct.ctor* %tmp1 sret  )

which is correct. The problem is that the CBE doesn't know about this. When run through the CBE, we get:

struct l_struct_2E_ctor {
unsigned char field0;
};
...
struct l_struct_2E_ctor llvm_cbe_tmp1; /
Address-exposed local */
*((&llvm_cbe_tmp1)) = _Z3barv();
...

Suddenly the the C compiler compiling the CBE output will return the struct in a register, instead of passing it by dummy argument. This causes miscompilation of Misc-C++/bigfib and probably a lot of other stuff because this affects std::string.

-Chris

@asl
Copy link
Collaborator

asl commented Sep 14, 2007

Hrm :)

@lattner
Copy link
Collaborator Author

lattner commented Sep 14, 2007

ugly huh?

@lattner
Copy link
Collaborator Author

lattner commented Mar 7, 2008

*** Bug llvm/llvm-bugzilla-archive#2125 has been marked as a duplicate of this bug. ***

@nlewycky
Copy link
Contributor

nlewycky commented Mar 7, 2008

Does sret fix this? Or multiple value ret?

@lattner
Copy link
Collaborator Author

lattner commented Mar 7, 2008

Nope.

@lattner
Copy link
Collaborator Author

lattner commented Feb 8, 2009

*** Bug llvm/llvm-bugzilla-archive#3504 has been marked as a duplicate of this bug. ***

@d0k
Copy link
Member

d0k commented Mar 26, 2012

The C backend was removed from svn trunk and is no longer maintained. Closing the bug.

@lattner
Copy link
Collaborator Author

lattner commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#2125

@lattner
Copy link
Collaborator Author

lattner commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#3504

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Quuxplusone Quuxplusone added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla miscompilation wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

5 participants