diff --git a/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp b/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp index 5d4199fb42bb..242aee079f22 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp @@ -613,6 +613,10 @@ void CIRGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { // Emit the EH cleanup if required. if (RequiresEHCleanup) { cir::TryOp tryOp = ehEntry->getParentOp()->getParentOfType(); + + if (EHParent == EHStack.stable_end() && !tryOp) + return; + auto *nextAction = getEHDispatchBlock(EHParent, tryOp); (void)nextAction; diff --git a/clang/test/CIR/CodeGen/try-catch-dtors.cpp b/clang/test/CIR/CodeGen/try-catch-dtors.cpp index c24240b72605..36d4430e764c 100644 --- a/clang/test/CIR/CodeGen/try-catch-dtors.cpp +++ b/clang/test/CIR/CodeGen/try-catch-dtors.cpp @@ -339,3 +339,37 @@ void bar() { // CIR: cir.store %[[V3]], %[[V1]] : !s32i, !cir.ptr // CIR: cir.call @_ZN1AD2Ev(%[[V0]]) : (!cir.ptr) -> () extra(#fn_attr) // CIR: cir.return + +class C { +public: + ~C(); + void operator=(C); +}; + +void d() { + C a, b; + a = b; +} + +// CIR: %[[V0:.*]] = cir.alloca !ty_C, !cir.ptr, ["a"] {alignment = 1 : i64} +// CIR: %[[V1:.*]] = cir.alloca !ty_C, !cir.ptr, ["b"] {alignment = 1 : i64} +// CIR: cir.scope { +// CIR: %[[V2:.*]] = cir.alloca !ty_C, !cir.ptr, ["agg.tmp0"] {alignment = 1 : i64} +// CIR: cir.call @_ZN1CC2ERKS_(%[[V2]], %[[V1]]) : (!cir.ptr, !cir.ptr) -> () extra(#fn_attr) +// CIR: %[[V3:.*]] = cir.load %[[V2]] : !cir.ptr, !ty_C +// CIR: cir.try synthetic cleanup { +// CIR: cir.call exception @_ZN1CaSES_(%[[V0]], %[[V3]]) : (!cir.ptr, !ty_C) -> () cleanup { +// CIR: cir.call @_ZN1CD1Ev(%[[V2]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: cir.call @_ZN1CD1Ev(%[[V1]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: cir.yield +// CIR: } +// CIR: cir.yield +// CIR: } catch [#cir.unwind { +// CIR: cir.resume +// CIR: }] +// CIR: cir.call @_ZN1CD1Ev(%[[V2]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: cir.call @_ZN1CD1Ev(%[[V1]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: } +// CIR: cir.call @_ZN1CD1Ev(%[[V1]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: cir.call @_ZN1CD1Ev(%[[V0]]) : (!cir.ptr) -> () extra(#fn_attr) +// CIR: cir.return