Author: rsmith Date: Mon Sep 30 18:23:23 2019 New Revision: 373289 URL: http://llvm.org/viewvc/llvm-project?rev=373289&view=rev Log: Don't elide the use of the thread wrapper for a thread_local constinit variable with non-trivial destruction.
We still need to invoke the thread wrapper to trigger registration of the destructor call on thread shutdown. Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=373289&r1=373288&r2=373289&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Sep 30 18:23:23 2019 @@ -360,7 +360,8 @@ public: } bool usesThreadWrapperFunction(const VarDecl *VD) const override { - return !isEmittedWithConstantInitializer(VD); + return !isEmittedWithConstantInitializer(VD) || + VD->needsDestruction(getContext()); } LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, const VarDecl *VD, QualType LValType) override; @@ -2606,7 +2607,7 @@ void ItaniumCXXABI::EmitThreadLocalInitF llvm::GlobalValue *Init = nullptr; bool InitIsInitFunc = false; bool HasConstantInitialization = false; - if (isEmittedWithConstantInitializer(VD)) { + if (!usesThreadWrapperFunction(VD)) { HasConstantInitialization = true; } else if (VD->hasDefinition()) { InitIsInitFunc = true; Modified: cfe/trunk/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp?rev=373289&r1=373288&r2=373289&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp (original) +++ cfe/trunk/test/CodeGenCXX/cxx2a-thread-local-constinit.cpp Mon Sep 30 18:23:23 2019 @@ -33,11 +33,6 @@ extern thread_local int c; // CHECK: } int h() { return c; } -thread_local int c = 0; - -int d_init(); -thread_local int d = d_init(); - // Note: use of 'c' does not trigger initialization of 'd', because 'c' has a // constant initializer. // CHECK-LABEL: define weak_odr {{.*}} @_ZTW1c() @@ -45,3 +40,30 @@ thread_local int d = d_init(); // CHECK-NOT: call // CHECK: ret i32* @c // CHECK: } + +thread_local int c = 0; + +int d_init(); + +// CHECK: define {{.*}}[[D_INIT:@__cxx_global_var_init[^(]*]]( +// CHECK: call {{.*}} @_Z6d_initv() +thread_local int d = d_init(); + +struct Destructed { + int n; + ~Destructed(); +}; + +extern thread_local constinit Destructed e; +// CHECK-LABEL: define i32 @_Z1iv() +// CHECK: call {{.*}}* @_ZTW1e() +// CHECK: } +int i() { return e.n; } + +// CHECK: define {{.*}}[[E2_INIT:@__cxx_global_var_init[^(]*]]( +// CHECK: call {{.*}} @__cxa_thread_atexit({{.*}} @_ZN10DestructedD1Ev {{.*}} @e2 +thread_local constinit Destructed e2; + +// CHECK-LABEL: define {{.*}}__tls_init +// CHECK: call {{.*}} [[D_INIT]] +// CHECK: call {{.*}} [[E2_INIT]] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits