llvm.org GIT mirror llvm / 880e8c0
Check isDiscardableIfUnused, rather than hasLocalLinkage, when bumping 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 Lang Hames 6 years ago
2 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
5959 continue;
6060 }
6161
62 bool Local = I->hasLocalLinkage();
62 bool Local = I->isDiscardableIfUnused();
6363 if (Local)
6464 I->setVisibility(GlobalValue::HiddenVisibility);
6565
7979 continue;
8080 }
8181
82 bool Local = I->hasLocalLinkage();
82 bool Local = I->isDiscardableIfUnused();
8383 if (Local)
8484 I->setVisibility(GlobalValue::HiddenVisibility);
8585
9696 Module::alias_iterator CurI = I;
9797 ++I;
9898
99 if (CurI->hasLocalLinkage()) {
99 if (CurI->isDiscardableIfUnused()) {
100100 CurI->setVisibility(GlobalValue::HiddenVisibility);
101101 CurI->setLinkage(GlobalValue::ExternalLinkage);
102102 }
0 ; RUN: llvm-extract -func foo -S < %s | FileCheck %s
1 ; RUN: llvm-extract -delete -func foo -S < %s | FileCheck --check-prefix=DELETE %s
2
3 ; Test that we don't convert weak_odr to external definitions.
4
5 ; CHECK: @bar = external hidden global i32
6 ; CHECK: define hidden i32* @foo() {
7 ; CHECK-NEXT: ret i32* @bar
8 ; CHECK-NEXT: }
9
10 ; DELETE: @bar = hidden global i32 42
11 ; DELETE: declare hidden i32* @foo()
12
13 @bar = linkonce global i32 42
14
15 define linkonce i32* @foo() {
16 ret i32* @bar
17 }
18
19 define void @g() {
20 call i32* @foo()
21 ret void
22 }