[llvm] r208447 - Don't crash on redefinitions.

Rafael Espindola rafael.espindola at gmail.com
Fri May 9 14:49:17 PDT 2014


Author: rafael
Date: Fri May  9 16:49:17 2014
New Revision: 208447

URL: http://llvm.org/viewvc/llvm-project?rev=208447&view=rev
Log:
Don't crash on redefinitions.

One error we were not deleting the alias or putting it in the Module. The
end result is that there was an use left of the aliasee when the module was
deleted.

Added:
    llvm/trunk/test/Assembler/alias-redefinition.ll
Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=208447&r1=208446&r2=208447&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Fri May  9 16:49:17 2014
@@ -673,9 +673,8 @@ bool LLParser::ParseAlias(const std::str
     return Error(AliaseeLoc, "alias must have pointer type");
 
   // Okay, create the alias but do not insert it into the module yet.
-  GlobalAlias* GA = new GlobalAlias(Aliasee->getType(),
-                                    (GlobalValue::LinkageTypes)Linkage, Name,
-                                    Aliasee);
+  std::unique_ptr<GlobalAlias> GA(new GlobalAlias(
+      Aliasee->getType(), (GlobalValue::LinkageTypes)Linkage, Name, Aliasee));
   GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
   GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
 
@@ -697,15 +696,18 @@ bool LLParser::ParseAlias(const std::str
 
     // If they agree, just RAUW the old value with the alias and remove the
     // forward ref info.
-    Val->replaceAllUsesWith(GA);
+    Val->replaceAllUsesWith(GA.get());
     Val->eraseFromParent();
     ForwardRefVals.erase(I);
   }
 
   // Insert into the module, we know its name won't collide now.
-  M->getAliasList().push_back(GA);
+  M->getAliasList().push_back(GA.get());
   assert(GA->getName() == Name && "Should not be a name conflict!");
 
+  // The module owns this now
+  GA.release();
+
   return false;
 }
 

Added: llvm/trunk/test/Assembler/alias-redefinition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/alias-redefinition.ll?rev=208447&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/alias-redefinition.ll (added)
+++ llvm/trunk/test/Assembler/alias-redefinition.ll Fri May  9 16:49:17 2014
@@ -0,0 +1,7 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: error: redefinition of global named '@bar'
+
+ at foo = global i32 0
+ at bar = alias i32* @foo
+ at bar = alias i32* @foo





More information about the llvm-commits mailing list