Skip to content

Commit 7a38468

Browse files
committed
Only destroy static locals if they have non-trivial destructors.
This fixes a regression introduced in 2b4fa53 that caused us to emit shutdown-time destruction for variables with ARC ownership, using C++-specific functions that don't exist in C implementations.
1 parent d3ba1e0 commit 7a38468

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/CodeGen/CGDecl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
366366

367367
emitter.finalize(GV);
368368

369-
if (D.needsDestruction(getContext()) && HaveInsertPoint()) {
369+
if (D.needsDestruction(getContext()) == QualType::DK_cxx_destructor &&
370+
HaveInsertPoint()) {
370371
// We have a constant initializer, but a nontrivial destructor. We still
371372
// need to perform a guarded "initialization" in order to register the
372373
// destructor.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-macos10.15 -emit-llvm -fobjc-arc -o - %s | FileCheck %s
2+
3+
@interface I
4+
@end
5+
6+
I *i() {
7+
static I *i = ((void *)0);
8+
return i;
9+
}
10+
11+
// CHECK-NOT: __cxa_guard_acquire
12+
// CHECK-NOT: __cxa_guard_release

0 commit comments

Comments
 (0)