Skip to content

Commit

Permalink
Check isDiscardableIfUnused, rather than hasLocalLinkage, when bumping
Browse files Browse the repository at this point in the history
GlobalValue linkage up to ExternalLinkage in the ExtractGV pass. This
prevents linkonce and linkonce_odr symbols from being DCE'd.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176459 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Mar 4, 2013
1 parent 1ae08e0 commit 880e8c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Transforms/IPO/ExtractGV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace {
continue;
}

bool Local = I->hasLocalLinkage();
bool Local = I->isDiscardableIfUnused();
if (Local)
I->setVisibility(GlobalValue::HiddenVisibility);

Expand All @@ -80,7 +80,7 @@ namespace {
continue;
}

bool Local = I->hasLocalLinkage();
bool Local = I->isDiscardableIfUnused();
if (Local)
I->setVisibility(GlobalValue::HiddenVisibility);

Expand All @@ -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);
}
Expand Down
23 changes: 23 additions & 0 deletions test/Other/extract-linkonce.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 880e8c0

Please sign in to comment.