[LLVMbugs] [Bug 1658] New: CBE miscompiles common C++ Code

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Fri Sep 14 10:30:22 PDT 2007


           Summary: CBE miscompiles common C++ Code
           Product: libraries
           Version: 1.0
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Backend: C
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sabre at nondot.org
                CC: llvmbugs at cs.uiuc.edu

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.


Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list