Skip to content

Commit ef5d9ba

Browse files
committed
Replace non-working scope handling with a missing feature
1 parent cb5355b commit ef5d9ba

File tree

3 files changed

+8
-41
lines changed

3 files changed

+8
-41
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct MissingFeatures {
225225
static bool cleanupAppendInsts() { return false; }
226226
static bool cleanupBranchThrough() { return false; }
227227
static bool cleanupIndexAndBIAdjustment() { return false; }
228+
static bool cleanupWithPreservedValues() { return false; }
228229
static bool cleanupsToDeactivate() { return false; }
229230
static bool constEmitterAggILE() { return false; }
230231
static bool constEmitterArrayILE() { return false; }

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -914,31 +914,9 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
914914
return emitCallExprLValue(cast<CallExpr>(e));
915915
case Expr::ExprWithCleanupsClass: {
916916
const auto *cleanups = cast<ExprWithCleanups>(e);
917-
LValue lv;
918-
919-
mlir::Location scopeLoc = getLoc(e->getSourceRange());
920-
[[maybe_unused]] auto scope = cir::ScopeOp::create(
921-
builder, scopeLoc, /*scopeBuilder=*/
922-
[&](mlir::OpBuilder &b, mlir::Location loc) {
923-
CIRGenFunction::LexicalScope lexScope{*this, loc,
924-
builder.getInsertionBlock()};
925-
926-
lv = emitLValue(cleanups->getSubExpr());
927-
if (lv.isSimple()) {
928-
// Defend against branches out of gnu statement expressions
929-
// surrounded by cleanups.
930-
Address addr = lv.getAddress();
931-
mlir::Value v = addr.getPointer();
932-
assert(!cir::MissingFeatures::addressIsKnownNonNull());
933-
assert(!cir::MissingFeatures::opTBAA());
934-
assert(!cir::MissingFeatures::objCGC());
935-
lv = LValue::makeAddr(addr.withPointer(v), lv.getType(),
936-
lv.getBaseInfo());
937-
}
938-
});
939-
940-
// FIXME: Is it possible to create an ExprWithCleanups that produces a
941-
// bitfield lvalue or some other non-simple lvalue?
917+
RunCleanupsScope scope(*this);
918+
LValue lv = emitLValue(cleanups->getSubExpr());
919+
assert(!cir::MissingFeatures::cleanupWithPreservedValues());
942920
return lv;
943921
}
944922
case Expr::ParenExprClass:

clang/test/CIR/CodeGen/temporary-materialization.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,16 @@ int test() {
1515
// CIR: cir.func {{.*}} @_Z4testv()
1616
// CIR: %[[TEMP_SLOT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ref.tmp0", init]
1717
// CIR-NEXT: %[[X:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["x", init, const]
18-
// CIR-NEXT: cir.scope {
19-
// CIR-NEXT: %[[TEMP_VALUE:.*]] = cir.call @_Z8make_intv() : () -> !s32i
20-
// CIR-NEXT: cir.store{{.*}} %[[TEMP_VALUE]], %[[TEMP_SLOT]]
21-
// CIR-NEXT: }
18+
// CIR-NEXT: %[[TEMP_VALUE:.*]] = cir.call @_Z8make_intv() : () -> !s32i
19+
// CIR-NEXT: cir.store{{.*}} %[[TEMP_VALUE]], %[[TEMP_SLOT]]
2220
// CIR-NEXT: cir.store{{.*}} %[[TEMP_SLOT]], %[[X]]
2321

2422
// LLVM: define {{.*}} i32 @_Z4testv()
2523
// LLVM: %[[RETVAL:.*]] = alloca i32
2624
// LLVM: %[[TEMP_SLOT:.*]] = alloca i32
2725
// LLVM: %[[X:.*]] = alloca ptr
28-
// LLVM: br label %[[SCOPE_LABEL:.*]]
29-
// LLVM: [[SCOPE_LABEL]]:
3026
// LLVM: %[[TEMP_VALUE:.*]] = call i32 @_Z8make_intv()
3127
// LLVM: store i32 %[[TEMP_VALUE]], ptr %[[TEMP_SLOT]]
32-
// LLVM: br label %[[SCOPE_END_LABEL:.*]]
33-
// LLVM: [[SCOPE_END_LABEL]]:
3428
// LLVM: store ptr %[[TEMP_SLOT]], ptr %[[X]]
3529

3630
// OGCG: define {{.*}} i32 @_Z4testv()
@@ -54,10 +48,8 @@ int test_scoped() {
5448
// CIR: cir.scope {
5549
// CIR-NEXT: %[[TEMP_SLOT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ref.tmp0", init]
5650
// CIR-NEXT: %[[Y_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["y", init, const]
57-
// CIR-NEXT: cir.scope {
58-
// CIR-NEXT: %[[TEMP_VALUE:.*]] = cir.call @_Z8make_intv() : () -> !s32i
59-
// CIR-NEXT: cir.store{{.*}} %[[TEMP_VALUE]], %[[TEMP_SLOT]] : !s32i, !cir.ptr<!s32i>
60-
// CIR-NEXT: }
51+
// CIR-NEXT: %[[TEMP_VALUE:.*]] = cir.call @_Z8make_intv() : () -> !s32i
52+
// CIR-NEXT: cir.store{{.*}} %[[TEMP_VALUE]], %[[TEMP_SLOT]] : !s32i, !cir.ptr<!s32i>
6153
// CIR-NEXT: cir.store{{.*}} %[[TEMP_SLOT]], %[[Y_ADDR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
6254
// CIR-NEXT: %[[Y_REF:.*]] = cir.load %[[Y_ADDR]] : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i>
6355
// CIR-NEXT: %[[Y_VALUE:.*]] = cir.load{{.*}} %[[Y_REF]] : !cir.ptr<!s32i>, !s32i
@@ -73,12 +65,8 @@ int test_scoped() {
7365
// LLVM: store i32 %[[TEMP_VALUE1]], ptr %[[X]]
7466
// LLVM: br label %[[SCOPE_LABEL:.*]]
7567
// LLVM: [[SCOPE_LABEL]]:
76-
// LLVM: br label %[[INNER_SCOPE_LABEL:.*]]
77-
// LLVM: [[INNER_SCOPE_LABEL]]:
7868
// LLVM: %[[TEMP_VALUE2:.*]] = call i32 @_Z8make_intv()
7969
// LLVM: store i32 %[[TEMP_VALUE2]], ptr %[[TEMP_SLOT]]
80-
// LLVM: br label %[[INNER_SCOPE_END_LABEL:.*]]
81-
// LLVM: [[INNER_SCOPE_END_LABEL]]:
8270
// LLVM: store ptr %[[TEMP_SLOT]], ptr %[[Y_ADDR]]
8371
// LLVM: %[[Y_REF:.*]] = load ptr, ptr %[[Y_ADDR]]
8472
// LLVM: %[[Y_VALUE:.*]] = load i32, ptr %[[Y_REF]]

0 commit comments

Comments
 (0)