Check isDiscardableIfUnused, rather than hasLocalLinkage, when bumping
authorLang Hames <lhames@gmail.com>
Mon, 4 Mar 2013 22:40:44 +0000 (22:40 +0000)
committerLang Hames <lhames@gmail.com>
Mon, 4 Mar 2013 22:40:44 +0000 (22:40 +0000)
GlobalValue linkage up to ExternalLinkage in the ExtractGV pass. This
prevents linkonce and linkonce_odr symbols from being DCE'd.

llvm-svn: 176459

llvm/lib/Transforms/IPO/ExtractGV.cpp
llvm/test/Other/extract-linkonce.ll [new file with mode: 0644]

index 8a6bfc6..fa3d72d 100644 (file)
@@ -60,7 +60,7 @@ namespace {
             continue;
         }
 
-        bool Local = I->hasLocalLinkage();
+        bool Local = I->isDiscardableIfUnused();
         if (Local)
           I->setVisibility(GlobalValue::HiddenVisibility);
 
@@ -80,7 +80,7 @@ namespace {
             continue;
         }
 
-        bool Local = I->hasLocalLinkage();
+        bool Local = I->isDiscardableIfUnused();
         if (Local)
           I->setVisibility(GlobalValue::HiddenVisibility);
 
@@ -97,7 +97,7 @@ namespace {
         Module::alias_iterator CurI = I;
         ++I;
 
-        if (CurI->hasLocalLinkage()) {
+        if (CurI->isDiscardableIfUnused()) {
           CurI->setVisibility(GlobalValue::HiddenVisibility);
           CurI->setLinkage(GlobalValue::ExternalLinkage);
         }
diff --git a/llvm/test/Other/extract-linkonce.ll b/llvm/test/Other/extract-linkonce.ll
new file mode 100644 (file)
index 0000000..31fbf3a
--- /dev/null
@@ -0,0 +1,23 @@
+; RUN: llvm-extract -func foo -S < %s | FileCheck %s
+; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
+
+; Test that we don't convert weak_odr to external definitions.
+
+; CHECK:      @bar = external hidden global i32
+; CHECK:      define hidden i32* @foo() {
+; CHECK-NEXT:  ret i32* @bar
+; CHECK-NEXT: }
+
+; DELETE: @bar = hidden global i32 42
+; DELETE: declare hidden i32* @foo()
+
+@bar = linkonce global i32 42
+
+define linkonce i32* @foo() {
+  ret i32* @bar
+}
+
+define void @g() {
+  call i32* @foo()
+  ret void
+}