[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 15 05:42:07 PDT 2024
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/88670
>From 599283c1845a25afe90163a5f0a7a809c622a521 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Sun, 14 Apr 2024 21:21:21 +0000
Subject: [PATCH 1/2] Use pushFullExprCleanup for deferred destroy
---
clang/lib/CodeGen/CGDecl.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8bdafa7c569b08..3f05ebb561da57 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2216,8 +2216,11 @@ void CodeGenFunction::pushDestroyAndDeferDeactivation(
void CodeGenFunction::pushDestroyAndDeferDeactivation(
CleanupKind cleanupKind, Address addr, QualType type, Destroyer *destroyer,
bool useEHCleanupForArray) {
- pushCleanupAndDeferDeactivation<DestroyObject>(
- cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+ llvm::Instruction *DominatingIP =
+ Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
+ pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+ DeferredDeactivationCleanupStack.push_back(
+ {EHStack.stable_begin(), DominatingIP});
}
void CodeGenFunction::pushStackRestore(CleanupKind Kind, Address SPMem) {
>From a27c77a1506d8044d55eb6961ba69229cb9c1fd7 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Mon, 15 Apr 2024 12:41:27 +0000
Subject: [PATCH 2/2] Add tests
---
.../CodeGenCXX/destory-with-init-list.cpp | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 clang/test/CodeGenCXX/destory-with-init-list.cpp
diff --git a/clang/test/CodeGenCXX/destory-with-init-list.cpp b/clang/test/CodeGenCXX/destory-with-init-list.cpp
new file mode 100644
index 00000000000000..b9495db3a23d6f
--- /dev/null
+++ b/clang/test/CodeGenCXX/destory-with-init-list.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -emit-llvm -fexceptions -o - %s -triple x86_64-linux-gnu | FileCheck -check-prefixes=EH,CHECK %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck -check-prefixes=NOEH,CHECK %s
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+
+ // libc++'s implementation
+ template <class _E>
+ class initializer_list
+ {
+ const _E* __begin_;
+ size_t __size_;
+ initializer_list(const _E* __b, size_t __s);
+ };
+}
+
+class Object {
+public:
+ Object() = default;
+ struct KV;
+ explicit Object(std::initializer_list<KV> Properties);
+};
+
+class Value {
+public:
+ Value(std::initializer_list<Value> Elements);
+ Value(const char *V);
+ ~Value();
+};
+
+class ObjectKey {
+public:
+ ObjectKey(const char *S);
+ ~ObjectKey();
+};
+
+struct Object::KV {
+ ObjectKey K;
+ Value V;
+};
+
+bool foo();
+void bar() {
+ // Verify we use conditional cleanups.
+ foo() ? Object{{"key1", {"val1", "val2"}}} : Object{{"key2", "val2"}};
+ // CHECK: cond.true:
+ // EH: invoke void @_ZN9ObjectKeyC1EPKc
+ // NOEH: call void @_ZN9ObjectKeyC1EPKc
+ // CHECK: store ptr %K, ptr %cond-cleanup.save
+}
More information about the cfe-commits
mailing list