Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator si,
"one per call: expected empty region at this point");
dispatchBlock = builder.createBlock(&callWithExceptionCtx.getCleanup());
builder.createYield(callWithExceptionCtx.getLoc());
} else if (currLexScope && currLexScope->isTernary()) {
break;
} else {
// Usually coming from general cir.scope cleanups that aren't
// tried to a specific throwing call.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,7 @@ mlir::Value ScalarExprEmitter::VisitBinLAnd(const clang::BinaryOperator *E) {
auto res = b.create<cir::ConstantOp>(Loc, Builder.getFalseAttr());
b.create<cir::YieldOp>(Loc, res.getRes());
});
LexScope.ForceCleanup();
B.create<cir::YieldOp>(Loc, res.getResult());
},
/*falseBuilder*/
Expand Down Expand Up @@ -2773,6 +2774,7 @@ mlir::Value ScalarExprEmitter::VisitBinLOr(const clang::BinaryOperator *E) {
auto res = b.create<cir::ConstantOp>(Loc, Builder.getFalseAttr());
b.create<cir::YieldOp>(Loc, res.getRes());
});
LexScope.ForceCleanup();
B.create<cir::YieldOp>(Loc, res.getResult());
});

Expand Down
55 changes: 55 additions & 0 deletions clang/test/CIR/CodeGen/dtors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,61 @@ class B : public A
// CHECK: cir.return
// CHECK: }

struct X {
int a;
X(int a) : a(a) {}
~X() {}
};

bool foo(const X &) { return false; }
bool bar() { return foo(1) || foo(2); }

// CHECK: cir.func @_Z3barv()
// CHECK: %[[V0:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["__retval"] {alignment = 1 : i64}
// CHECK: cir.scope {
// CHECK: %[[V2:.*]] = cir.alloca !rec_X, !cir.ptr<!rec_X>, ["ref.tmp0"] {alignment = 4 : i64}
// CHECK: %[[V3:.*]] = cir.const #cir.int<1> : !s32i
// CHECK: cir.call @_ZN1XC2Ei(%[[V2]], %[[V3]]) : (!cir.ptr<!rec_X>, !s32i) -> ()
// CHECK: %[[V4:.*]] = cir.call @_Z3fooRK1X(%[[V2]]) : (!cir.ptr<!rec_X>) -> !cir.bool
// CHECK: %[[V5:.*]] = cir.ternary(%[[V4]], true {
// CHECK: %[[V6:.*]] = cir.const #true
// CHECK: cir.yield %[[V6]] : !cir.bool
// CHECK: }, false {
// CHECK: %[[V6:.*]] = cir.alloca !rec_X, !cir.ptr<!rec_X>, ["ref.tmp1"] {alignment = 4 : i64}
// CHECK: %[[V7:.*]] = cir.const #cir.int<2> : !s32i
// CHECK: cir.call @_ZN1XC2Ei(%[[V6]], %[[V7]]) : (!cir.ptr<!rec_X>, !s32i) -> ()
// CHECK: %[[V8:.*]] = cir.call @_Z3fooRK1X(%[[V6]]) : (!cir.ptr<!rec_X>) -> !cir.bool
// CHECK: %[[V9:.*]] = cir.ternary(%[[V8]], true {
// CHECK: %[[V10:.*]] = cir.const #true
// CHECK: cir.yield %[[V10]] : !cir.bool
// CHECK: }, false {
// CHECK: %[[V10:.*]] = cir.const #false
// CHECK: cir.yield %[[V10]] : !cir.bool
// CHECK: }) : (!cir.bool) -> !cir.bool
// CHECK: cir.call @_ZN1XD2Ev(%[[V6]]) : (!cir.ptr<!rec_X>) -> ()
// CHECK: cir.yield %[[V9]] : !cir.bool
// CHECK: }) : (!cir.bool) -> !cir.bool
// CHECK: cir.store %[[V5]], %[[V0]] : !cir.bool, !cir.ptr<!cir.bool>
// CHECK: cir.call @_ZN1XD2Ev(%[[V2]]) : (!cir.ptr<!rec_X>) -> ()
// CHECK: }
// CHECK: %[[V1:.*]] = cir.load %[[V0]] : !cir.ptr<!cir.bool>, !cir.bool
// CHECK: cir.return %[[V1]] : !cir.bool
// CHECK: }

bool bar2() { return foo(1) && foo(2); }

// CHECK: cir.func @_Z4bar2v()
// CHECK: cir.alloca !rec_X, !cir.ptr<!rec_X>
// CHECK: {{.*}} = cir.ternary({{.*}}, true {
// CHECK: cir.alloca !rec_X, !cir.ptr<!rec_X>
// CHECK: cir.call @_ZN1XD2Ev
// CHECK: cir.yield
// CHECK: }, false {
// CHECK: {{.*}} = cir.const #false
// CHECK: cir.yield
// CHECK: }) : (!cir.bool) -> !cir.bool
// CHECK: cir.call @_ZN1XD2Ev

// @B::~B() #1 definition call into base @A::~A()
// CHECK: cir.func linkonce_odr @_ZN1BD2Ev{{.*}}{
// CHECK: cir.call @_ZN1AD2Ev(
Expand Down
Loading