[llvm-commits] [llvm-gcc-4.2] r50819 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Wed May 7 11:05:25 PDT 2008


Author: baldrick
Date: Wed May  7 13:05:25 2008
New Revision: 50819

URL: http://llvm.org/viewvc/llvm-project?rev=50819&view=rev
Log:
The temporary was only being created when the
thing being emitted was the RESULT_DECL, i.e.
a pointless copy.  Get rid of the temporary
by doing nothing in this case.  I particularly
want to get rid of this one because the type
can have variable size, so the temporary can
in fact be too small causing smashing of other
stack variables (and firing an assertion I
have here to catch this).

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=50819&r1=50818&r2=50819&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed May  7 13:05:25 2008
@@ -1763,16 +1763,16 @@
 
 Value *TreeToLLVM::EmitRETURN_EXPR(tree exp, const MemRef *DestLoc) {
   assert(DestLoc == 0 && "Does not return a value!");
-  if (TREE_OPERAND(exp, 0)) {
-    // Emit the expression, including the assignment to RESULT_DECL.  If the
-    // operand is an aggregate value, create a temporary to evaluate it into.
-    MemRef DestLoc;
-    const Type *DestTy = ConvertType(TREE_TYPE(TREE_OPERAND(exp, 0)));
-    if (!DestTy->isFirstClassType() && 
-        TREE_CODE(TREE_OPERAND(exp, 0)) != MODIFY_EXPR)
-      DestLoc = CreateTempLoc(DestTy);
-    Emit(TREE_OPERAND(exp, 0), DestLoc.Ptr ? &DestLoc : NULL);
-  }
+  tree retval = TREE_OPERAND(exp, 0);
+
+  assert((!retval || TREE_CODE(retval) == RESULT_DECL ||
+          (TREE_CODE(retval) == MODIFY_EXPR &&
+           TREE_CODE(TREE_OPERAND(retval, 0)) == RESULT_DECL)) &&
+         "RETURN_EXPR not gimple!");
+
+  if (retval && TREE_CODE(retval) != RESULT_DECL)
+    // Emit the assignment to RESULT_DECL.
+    Emit(retval, 0);
 
   // Emit a branch to the exit label.
   Builder.CreateBr(ReturnBB);





More information about the llvm-commits mailing list