Fix PR1645 by resolving forward alias references.
authorChris Lattner <sabre@nondot.org>
Mon, 10 Sep 2007 23:23:53 +0000 (23:23 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 10 Sep 2007 23:23:53 +0000 (23:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41815 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/llvmAsmParser.y
test/Assembler/2007-09-10-AliasFwdRef.ll [new file with mode: 0644]

index cf9e5a7a538afc27b21450c8c8d0266a447b7100..6364b29bcd77d53f850fd7361ed77945c0ae99b4 100644 (file)
@@ -2129,6 +2129,27 @@ Definition
                                       CurModule.CurrentModule);
     GA->setVisibility($2);
     InsertValue(GA, CurModule.Values);
+    
+    
+    // If there was a forward reference of this alias, resolve it now.
+    
+    ValID ID;
+    if (!Name.empty())
+      ID = ValID::createGlobalName(Name);
+    else
+      ID = ValID::createGlobalID(CurModule.Values.size()-1);
+    
+    if (GlobalValue *FWGV =
+          CurModule.GetForwardRefForGlobal(GA->getType(), ID)) {
+      // Replace uses of the fwdref with the actual alias.
+      FWGV->replaceAllUsesWith(GA);
+      if (GlobalVariable *GV = dyn_cast<GlobalVariable>(FWGV))
+        GV->eraseFromParent();
+      else
+        cast<Function>(FWGV)->eraseFromParent();
+    }
+    ID.destroy();
+    
     CHECK_FOR_ERROR
   }
   | TARGET TargetDefinition { 
diff --git a/test/Assembler/2007-09-10-AliasFwdRef.ll b/test/Assembler/2007-09-10-AliasFwdRef.ll
new file mode 100644 (file)
index 0000000..b21491b
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llvm-dis
+; PR1645
+
+@__gthread_active_ptr.5335 = internal constant i8* bitcast (i32 (i32)* @__gthrw_pthread_cancel to i8*)    
+@__gthrw_pthread_cancel = alias weak i32 (i32)* @pthread_cancel   
+
+
+
+declare extern_weak i32 @pthread_cancel(i32)