[llvm] df9d64e - [IR] Add missing GlobalAlias copying of ThreadLocalMode attribute
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 20:15:40 PDT 2020
Author: Itay Bookstein
Date: 2020-06-16T20:15:27-07:00
New Revision: df9d64ed9c1d819bc0a040e3ef4c4a4003bf5c93
URL: https://github.com/llvm/llvm-project/commit/df9d64ed9c1d819bc0a040e3ef4c4a4003bf5c93
DIFF: https://github.com/llvm/llvm-project/commit/df9d64ed9c1d819bc0a040e3ef4c4a4003bf5c93.diff
LOG: [IR] Add missing GlobalAlias copying of ThreadLocalMode attribute
Summary:
Previously, GlobalAlias::copyAttributesFrom did not preserve ThreadLocalMode,
causing incorrect IR generation in IR linking flows. This patch pushes the code
responsible for copying this attribute from GlobalVariable::copyAttributesFrom
down to GlobalValue::copyAttributesFrom so that it is shared by GlobalAlias.
Fixes PR46297.
Reviewers: tejohnson, pcc, hans
Reviewed By: tejohnson, hans
Subscribers: hiraditya, ibookstein, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81605
Added:
llvm/test/Linker/Inputs/alias-threadlocal-defs.ll
llvm/test/Linker/alias-threadlocal.ll
Modified:
llvm/lib/IR/Globals.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index eefd221ec389..34c767ff3672 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -65,6 +65,7 @@ Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
setVisibility(Src->getVisibility());
setUnnamedAddr(Src->getUnnamedAddr());
+ setThreadLocalMode(Src->getThreadLocalMode());
setDLLStorageClass(Src->getDLLStorageClass());
setDSOLocal(Src->isDSOLocal());
setPartition(Src->getPartition());
@@ -419,7 +420,6 @@ void GlobalVariable::setInitializer(Constant *InitVal) {
/// from the GlobalVariable Src to this one.
void GlobalVariable::copyAttributesFrom(const GlobalVariable *Src) {
GlobalObject::copyAttributesFrom(Src);
- setThreadLocalMode(Src->getThreadLocalMode());
setExternallyInitialized(Src->isExternallyInitialized());
setAttributes(Src->getAttributes());
}
diff --git a/llvm/test/Linker/Inputs/alias-threadlocal-defs.ll b/llvm/test/Linker/Inputs/alias-threadlocal-defs.ll
new file mode 100644
index 000000000000..7b7062cc3cd1
--- /dev/null
+++ b/llvm/test/Linker/Inputs/alias-threadlocal-defs.ll
@@ -0,0 +1,2 @@
+ at tlsvar1 = thread_local global i32 0, align 4
+ at tlsvar2 = hidden thread_local alias i32, i32* @tlsvar1
diff --git a/llvm/test/Linker/alias-threadlocal.ll b/llvm/test/Linker/alias-threadlocal.ll
new file mode 100644
index 000000000000..3e50a62770b0
--- /dev/null
+++ b/llvm/test/Linker/alias-threadlocal.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-link %s %p/Inputs/alias-threadlocal-defs.ll -S -o - | FileCheck %s
+
+; PR46297
+; Verify that linking GlobalAliases preserves the thread_local attribute
+
+; CHECK: @tlsvar1 = thread_local global i32 0, align 4
+; CHECK: @tlsvar2 = hidden thread_local alias i32, i32* @tlsvar1
+
+ at tlsvar2 = external thread_local global i32, align 4
More information about the llvm-commits
mailing list