[LLVMbugs] [Bug 1942] problem with assigning returned object to *this

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Jan 27 20:34:47 PST 2008


http://llvm.org/bugs/show_bug.cgi?id=1942


Chris Lattner <sabre at nondot.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




--- Comment #4 from Chris Lattner <sabre at nondot.org>  2008-01-27 22:34:44 ---
This fix is not correct.  Consider this testcase:

class foo {
public:
  int a[1000];
  foo(void) {}
  const foo operator+(const foo& in) const;
};

const foo foo::operator+(const foo& in) const {
  foo Out;
  Out.a[0] = 1;
  Out.a[1] = in.a[0];
  return Out;
}

GCC compiles this code to:

__ZNK3fooplERKS_:
        movl    4(%esp), %eax     <- out pointer
        movl    12(%esp), %edx   <- in pointer
        movl    $1, (%eax)             <- store to out[0]
        movl    (%edx), %edx         <- read in[0]
        movl    %edx, 4(%eax)       <- store to out[1]
        ret     $4

This means that GCC is implicitly assuming that the return slot and the output
cannot alias.  I think this needs to be fixed on the caller side, not the
callee side.  If llvm-gcc is producing code where the caller assumes that it
can alias the return slot with an argument, then the call produced will not
match the ABI and would produce an incorrect result when GCC compiled the
callee.

What do you think Duncan?

-Chris


-- 
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