Fix llvm-extract so that it changes the linkage of all GlobalValues to
authorBob Wilson <bob.wilson@apple.com>
Thu, 23 Sep 2010 17:25:06 +0000 (17:25 +0000)
committerBob Wilson <bob.wilson@apple.com>
Thu, 23 Sep 2010 17:25:06 +0000 (17:25 +0000)
"external" even when doing lazy bitcode loading.  This was broken because
a function that is not materialized fails the !isDeclaration() test.

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

lib/Transforms/IPO/ExtractGV.cpp
test/Other/extract.ll

index bb041697a5c6bfc0a435ee5733f1a8fb68bf3b32..9d432de9fa7b7fd7704ba3291c735e6e8ff85783 100644 (file)
@@ -50,24 +50,22 @@ namespace {
 
       // Visit the GlobalVariables.
       for (Module::global_iterator I = M.global_begin(), E = M.global_end();
-           I != E; ++I)
-        if (!I->isDeclaration()) {
-          if (I->hasLocalLinkage())
-            I->setVisibility(GlobalValue::HiddenVisibility);
-          I->setLinkage(GlobalValue::ExternalLinkage);
-          if (deleteStuff == (bool)Named.count(I))
-            I->setInitializer(0);
-        }
+           I != E; ++I) {
+        if (I->hasLocalLinkage())
+          I->setVisibility(GlobalValue::HiddenVisibility);
+        I->setLinkage(GlobalValue::ExternalLinkage);
+        if (deleteStuff == (bool)Named.count(I) && !I->isDeclaration())
+          I->setInitializer(0);
+      }
 
       // Visit the Functions.
-      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-        if (!I->isDeclaration()) {
-          if (I->hasLocalLinkage())
-            I->setVisibility(GlobalValue::HiddenVisibility);
-          I->setLinkage(GlobalValue::ExternalLinkage);
-          if (deleteStuff == (bool)Named.count(I))
-            I->deleteBody();
-        }
+      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
+        if (I->hasLocalLinkage())
+          I->setVisibility(GlobalValue::HiddenVisibility);
+        I->setLinkage(GlobalValue::ExternalLinkage);
+        if (deleteStuff == (bool)Named.count(I) && !I->isDeclaration())
+          I->deleteBody();
+      }
 
       return true;
     }
index 46962d094fdbf8595bd123a14b0425ace98bb33e..57573ed76f9a9064df905e7bd2535f6d192c9623 100644 (file)
 ; CHECK: define void @foo() {
 ; CHECK:   ret void
 ; CHECK: }
+
+; The linkonce_odr linkage for foo() should be changed to external linkage.
+; DELETE: declare void @foo()
 ; DELETE: define void @bar() {
+; DELETE:   call void @foo()
 ; DELETE:   ret void
 ; DELETE: }
 
-define void @foo() {
+define linkonce_odr void @foo() {
   ret void
 }
 define void @bar() {
+  call void @foo()
   ret void
 }