LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1658 - CBE miscompiles common C++ Code (bigfib, tramp3d, etc)
Summary: CBE miscompiles common C++ Code (bigfib, tramp3d, etc)
Status: RESOLVED WONTFIX
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: C (show other bugs)
Version: 1.0
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
: 2125 3504 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-09-14 12:30 PDT by Chris Lattner
Modified: 2012-03-26 05:57 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-09-14 12:30:21 PDT
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* @_Z3foov( )            ; <i8*> [#uses=0]
        call void @_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
Comment 1 Anton Korobeynikov 2007-09-14 12:53:23 PDT
Hrm :) 
Comment 2 Chris Lattner 2007-09-14 12:57:27 PDT
ugly huh?
Comment 3 Chris Lattner 2008-03-07 00:14:54 PST
*** Bug 2125 has been marked as a duplicate of this bug. ***
Comment 4 Nick Lewycky 2008-03-07 00:19:12 PST
Does sret fix this? Or multiple value ret?
Comment 5 Chris Lattner 2008-03-07 00:22:05 PST
Nope.
Comment 6 Chris Lattner 2009-02-07 16:28:40 PST
*** Bug 3504 has been marked as a duplicate of this bug. ***
Comment 7 Benjamin Kramer 2012-03-26 05:57:32 PDT
The C backend was removed from svn trunk and is no longer maintained. Closing the bug.