[llvm-commits] [gcc-plugin] r81369 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Wed Sep 9 11:48:49 PDT 2009


Author: baldrick
Date: Wed Sep  9 13:48:48 2009
New Revision: 81369

URL: http://llvm.org/viewvc/llvm-project?rev=81369&view=rev
Log:
When using a DenseMap M, doing M[x]=function_that_changes_M
can result in badness like using freed memory.  So avoid this
construct.

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

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=81369&r1=81368&r2=81369&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Wed Sep  9 13:48:48 2009
@@ -2279,8 +2279,10 @@
   assert(SSA_VAR_P(var) && "Not an SSA variable!");
 
   // If the variable is itself an ssa name, use its LLVM value.
-  if (TREE_CODE (var) == SSA_NAME)
-    return SSANames[exp] = EmitSSA_NAME(var);
+  if (TREE_CODE (var) == SSA_NAME) {
+    Value *Val = EmitSSA_NAME(var);
+    return SSANames[exp] = Val;
+  }
 
   // Otherwise the symbol is a VAR_DECL, PARM_DECL or RESULT_DECL.  Since a
   // default definition is only created if the very first reference to the
@@ -2929,8 +2931,9 @@
   // If this is the definition of an ssa name, record it in the SSANames map.
   if (TREE_CODE(lhs) == SSA_NAME) {
     assert(SSANames.find(lhs) == SSANames.end() && "Multiply defined SSA name!");
-    return SSANames[lhs] = Builder.CreateBitCast(Emit(rhs, 0),
-                                                 ConvertType(TREE_TYPE(exp)));
+    Value *Val = Builder.CreateBitCast(Emit(rhs, 0),
+                                       ConvertType(TREE_TYPE(exp)));
+    return SSANames[lhs] = Val;
   } else if (canEmitRegisterVariable(lhs)) {
     // If this is a store to a register variable, EmitLV can't handle the dest
     // (there is no l-value of a register variable).  Emit an inline asm node





More information about the llvm-commits mailing list