[PATCH] D132848: [clang] Fix checking for emulated TLS in shouldAssumeDSOLocal in CodeGen
Martin Storsjö via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 29 05:24:56 PDT 2022
mstorsjo created this revision.
mstorsjo added a reviewer: aaron.ballman.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: clang.
We shouldn't just check the clang options, we also should check
`Triple::hasDefaultEmulatedTLS()`.
This doesn't make any testable difference in this commit, because
the check for emulated TLS is within a block for
`TT.isWindowsGNUEnvironment()`, and `hasDefaultEmulatedTLS()` returns
false for any such environment - but it makes the code from
0e4cf807aeaf54a10e02176498a7df13ac722b37 <https://reviews.llvm.org/rG0e4cf807aeaf54a10e02176498a7df13ac722b37> / D102970 <https://reviews.llvm.org/D102970> more correct and
generic.
Some mingw distributions carry a downstream patch, that enables
emulated TLS by default for mingw targets in `hasDefaultEmulatedTLS()`
- and for such cases, this patch does make a difference and fixes the
detection of emulated TLS, if it is implicitly enabled.
I'm open for better suggestions on where to place the `useEmulatedTLS()`
helper function; it's a parallel to the preexisting
`TargetMachine::useEmulatedTLS()` which does the same, within llvm.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132848
Files:
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
Index: clang/lib/CodeGen/CodeGenModule.h
===================================================================
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -746,6 +746,12 @@
const TargetCodeGenInfo &getTargetCodeGenInfo();
+ bool useEmulatedTLS() const {
+ if (CodeGenOpts.ExplicitEmulatedTLS)
+ return CodeGenOpts.EmulatedTLS;
+ return getTriple().hasDefaultEmulatedTLS();
+ }
+
CodeGenTypes &getTypes() { return Types; }
CodeGenVTables &getVTables() { return VTables; }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1154,7 +1154,7 @@
// such variables can't be marked as DSO local. (Native TLS variables
// can't be dllimported at all, though.)
if (GV->isDeclarationForLinker() && isa<llvm::GlobalVariable>(GV) &&
- (!GV->isThreadLocal() || CGM.getCodeGenOpts().EmulatedTLS))
+ (!GV->isThreadLocal() || CGM.useEmulatedTLS()))
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132848.456319.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220829/1f61f9db/attachment.bin>
More information about the cfe-commits
mailing list