[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 14 14:26:45 PDT 2024


https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/88670

Instead of directly pushing the `Destroy`, we should use `pushFullExprCleanup` which handles conditional branches.
This fixes a backend crash due to 89ba7e183e6e2c64370ed1b963e54c06352211db.

Tested:
```
CLANG_DIR=/usr/local/google/home/usx/build

$CLANG_DIR/bin/clang++ \
  -Itools/clang/tools/extra/clangd \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/../include-cleaner/include \
  -Itools/clang/tools/extra/clangd/../clang-tidy \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang/include \
  -Itools/clang/include \
  -Iinclude \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/llvm/include \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/pseudo/lib/../include \
  -isystem$CLANG_DIR/lib/clang/19/include \
  -o  /usr/local/google/home/usx/build/bootstrap/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o \
  -c  /usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp
```

>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] 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) {



More information about the cfe-commits mailing list