Don't crash on redefinitions.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 9 May 2014 21:49:17 +0000 (21:49 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 9 May 2014 21:49:17 +0000 (21:49 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208447 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/LLParser.cpp
test/Assembler/alias-redefinition.ll [new file with mode: 0644]

index 32037df958bd1769e4a9208396178a59e8251f34..892cff6f8fdb0eb7104f7c2b31a3e6fdeb1df434 100644 (file)
@@ -673,9 +673,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
     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::string &Name, LocTy NameLoc,
 
     // 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;
 }
 
diff --git a/test/Assembler/alias-redefinition.ll b/test/Assembler/alias-redefinition.ll
new file mode 100644 (file)
index 0000000..19ad85b
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: not llvm-as %s 2>&1 | FileCheck %s
+
+; CHECK: error: redefinition of global named '@bar'
+
+@foo = global i32 0
+@bar = alias i32* @foo
+@bar = alias i32* @foo