From 880e8c0ad41345f353b819c51092baa8f05e1950 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 4 Mar 2013 22:40:44 +0000 Subject: [PATCH] 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 --- lib/Transforms/IPO/ExtractGV.cpp | 6 +++--- test/Other/extract-linkonce.ll | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/Other/extract-linkonce.ll diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index 8a6bfc6d885..fa3d72ddcf1 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -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/test/Other/extract-linkonce.ll b/test/Other/extract-linkonce.ll new file mode 100644 index 00000000000..31fbf3ac463 --- /dev/null +++ b/test/Other/extract-linkonce.ll @@ -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 +}