fix PR5295 where the .ll parser didn't reject a function after a global
authorChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 23:22:50 +0000 (23:22 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 23:22:50 +0000 (23:22 +0000)
or global after a function with conflicting names.  Update some testcases
that were accidentally depending on this behavior.

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

lib/AsmParser/LLParser.cpp
test/CodeGen/CPP/llvm2cpp.ll
test/CodeGen/X86/x86-64-pic-10.ll

index 52fd2b21e1a06dad0a0fc3b95022182c6086a38c..fa803bb1e9fe29b846462f4a4d9492aa922a101c 100644 (file)
@@ -603,8 +603,7 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
 
   // See if this value already exists in the symbol table.  If so, it is either
   // a redefinition or a definition of a forward reference.
-  if (GlobalValue *Val =
-        cast_or_null<GlobalValue>(M->getValueSymbolTable().lookup(Name))) {
+  if (GlobalValue *Val = M->getNamedValue(Name)) {
     // See if this was a redefinition.  If so, there is no entry in
     // ForwardRefVals.
     std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
@@ -671,9 +670,11 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
 
   // See if the global was forward referenced, if so, use the global.
   if (!Name.empty()) {
-    if ((GV = M->getGlobalVariable(Name, true)) &&
-        !ForwardRefVals.erase(Name))
-      return Error(NameLoc, "redefinition of global '@" + Name + "'");
+    if (GlobalValue *GVal = M->getNamedValue(Name)) {
+      if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
+        return Error(NameLoc, "redefinition of global '@" + Name + "'");
+      GV = cast<GlobalVariable>(GVal);
+    }
   } else {
     std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
       I = ForwardRefValIDs.find(NumberedVals.size());
@@ -2563,6 +2564,8 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
              AI != AE; ++AI)
           AI->setName("");
       }
+    } else if (M->getNamedValue(FunctionName)) {
+      return Error(NameLoc, "redefinition of function '@" + FunctionName + "'");
     }
 
   } else {
index 447f332b269e0bec6011495e1b97bdf52158e5fd..d0ba0cfac3125bd1c8c17b086917314bd0393402 100644 (file)
@@ -273,7 +273,7 @@ define i32 @foozball(i32) {
 @A = global i32* @B            ; <i32**> [#uses=0]
 @B = global i32 7              ; <i32*> [#uses=1]
 
-define void @X() {
+define void @test12312() {
        ret void
 }
 ; ModuleID = 'global_section.ll'
index 0f65e57449596cca07e4e0dd3d597beaa635d00c..7baa7e59e1c3f7209657bf9fe8183f2811153500 100644 (file)
@@ -3,7 +3,7 @@
 
 @g = alias weak i32 ()* @f
 
-define void @g() {
+define void @h() {
 entry:
        %tmp31 = call i32 @g()
         ret void