Fix bug: FunctionResolve/2003-05-31-AllInternalDecls.ll
authorChris Lattner <sabre@nondot.org>
Sat, 31 May 2003 21:57:06 +0000 (21:57 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 31 May 2003 21:57:06 +0000 (21:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6486 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionResolution.cpp

index 18a28895fdcf3c9dcf8b8ef6261b0e8596e7e735..7ec1745ffdd4e33ef10c9b64a21a60b163f1ea38 100644 (file)
@@ -309,6 +309,23 @@ static bool ProcessGlobalsWithSameName(Module &M,
   }
 
   if (Globals.size() > 1) {         // Found a multiply defined global...
+    // If there are no external declarations, and there is at most one
+    // externally visible instance of the global, then there is nothing to do.
+    //
+    bool HasExternal = false;
+    unsigned NumInstancesWithExternalLinkage = 0;
+
+    for (unsigned i = 0, e = Globals.size(); i != e; ++i) {
+      if (Globals[i]->isExternal())
+        HasExternal = true;
+      else if (!Globals[i]->hasInternalLinkage())
+        NumInstancesWithExternalLinkage++;
+    }
+    
+    if (!HasExternal && NumInstancesWithExternalLinkage <= 1)
+      return false;  // Nothing to do?  Must have multiple internal definitions.
+
+
     // We should find exactly one concrete function definition, which is
     // probably the implementation.  Change all of the function definitions and
     // uses to use it instead.