[clang] 7a38468 - Only destroy static locals if they have non-trivial destructors.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 15:18:46 PST 2020
Author: Richard Smith
Date: 2020-01-10T15:18:36-08:00
New Revision: 7a38468e34eeeb59e80b176b97213d205d8d9b41
URL: https://github.com/llvm/llvm-project/commit/7a38468e34eeeb59e80b176b97213d205d8d9b41
DIFF: https://github.com/llvm/llvm-project/commit/7a38468e34eeeb59e80b176b97213d205d8d9b41.diff
LOG: Only destroy static locals if they have non-trivial destructors.
This fixes a regression introduced in
2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 that caused us to emit
shutdown-time destruction for variables with ARC ownership, using
C++-specific functions that don't exist in C implementations.
Added:
clang/test/CodeGenObjC/initialize-function-static.m
Modified:
clang/lib/CodeGen/CGDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 61fb8fa384cf..86e02d2d7e4a 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -366,7 +366,8 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
emitter.finalize(GV);
- if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
+ if (D.needsDestruction(getContext()) == QualType::DK_cxx_destructor &&
+ HaveInsertPoint()) {
// We have a constant initializer, but a nontrivial destructor. We still
// need to perform a guarded "initialization" in order to register the
// destructor.
diff --git a/clang/test/CodeGenObjC/initialize-function-static.m b/clang/test/CodeGenObjC/initialize-function-static.m
new file mode 100644
index 000000000000..21ad320f7820
--- /dev/null
+++ b/clang/test/CodeGenObjC/initialize-function-static.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.15 -emit-llvm -fobjc-arc -o - %s | FileCheck %s
+
+ at interface I
+ at end
+
+I *i() {
+ static I *i = ((void *)0);
+ return i;
+}
+
+// CHECK-NOT: __cxa_guard_acquire
+// CHECK-NOT: __cxa_guard_release
More information about the cfe-commits
mailing list