diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 8bdafa7c569b0..3f05ebb561da5 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( - 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) { diff --git a/clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp b/clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp index ffde1bd6a724d..95deee8bb1f1f 100644 --- a/clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp +++ b/clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 --std=c++20 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 --std=c++20 -fexceptions -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck -check-prefixes=EH %s +// RUN: %clang_cc1 --std=c++20 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck -check-prefixes=NOEH,CHECK %s struct Printy { Printy(const char *name) : name(name) {} @@ -349,6 +350,34 @@ void NewArrayInit() { // CHECK-NEXT: br label %return } +void DestroyInConditionalCleanup() { + // EH-LABEL: DestroyInConditionalCleanupv() + // NOEH-LABEL: DestroyInConditionalCleanupv() + struct A { + A() {} + ~A() {} + }; + + struct Value { + Value(A) {} + ~Value() {} + }; + + struct V2 { + Value K; + Value V; + }; + // Verify we use conditional cleanups. + (void)(foo() ? V2{A(), A()} : V2{A(), A()}); + // NOEH: cond.true: + // NOEH: call void @_ZZ27DestroyInConditionalCleanupvEN1AC1Ev + // NOEH: store ptr %{{.*}}, ptr %cond-cleanup.save + + // EH: cond.true: + // EH: invoke void @_ZZ27DestroyInConditionalCleanupvEN1AC1Ev + // EH: store ptr %{{.*}}, ptr %cond-cleanup.save +} + void ArrayInitWithContinue() { // CHECK-LABEL: @_Z21ArrayInitWithContinuev // Verify that we start to emit the array destructor.