PR42182: Allow thread-local to use __cxa_thread_atexit when
-fno-use-cxx-atexit is used
This matches the GCC behavior, __cxa_thread_atexit should be permissible
even though cxa_atexit is disabled.
Differential Revision: https://reviews.llvm.org/D63283/
llvm-svn: 363288
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index bd399b2..a12f08f 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2270,6 +2270,8 @@
static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
llvm::FunctionCallee dtor,
llvm::Constant *addr, bool TLS) {
+ assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
const char *Name = "__cxa_atexit";
if (TLS) {
const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2363,13 +2365,13 @@
if (D.isNoDestroy(CGM.getContext()))
return;
- // Use __cxa_atexit if available.
- if (CGM.getCodeGenOpts().CXAAtExit)
+ // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit
+ // or __cxa_atexit depending on whether this VarDecl is a thread-local storage
+ // or not. CXAAtExit controls only __cxa_atexit, so use it if it is enabled.
+ // We can always use __cxa_thread_atexit.
+ if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
- if (D.getTLSKind())
- CGM.ErrorUnsupported(&D, "non-trivial TLS destruction");
-
// In Apple kexts, we want to add a global destructor entry.
// FIXME: shouldn't this be guarded by some variable?
if (CGM.getLangOpts().AppleKext) {