Skip to content

Commit fe28db8

Browse files
committed
Replace non-working scope handling with a missing feature
1 parent 99507ad commit fe28db8

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
@@ -226,6 +226,7 @@ struct MissingFeatures {
226226
static bool cleanupAppendInsts() { return false; }
227227
static bool cleanupBranchThrough() { return false; }
228228
static bool cleanupIndexAndBIAdjustment() { return false; }
229+
static bool cleanupWithPreservedValues() { return false; }
229230
static bool cleanupsToDeactivate() { return false; }
230231
static bool constEmitterAggILE() { return false; }
231232
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
@@ -923,31 +923,9 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
923923
return emitCallExprLValue(cast<CallExpr>(e));
924924
case Expr::ExprWithCleanupsClass: {
925925
const auto *cleanups = cast<ExprWithCleanups>(e);
926-
LValue lv;
927-
928-
mlir::Location scopeLoc = getLoc(e->getSourceRange());
929-
[[maybe_unused]] auto scope = cir::ScopeOp::create(
930-
builder, scopeLoc, /*scopeBuilder=*/
931-
[&](mlir::OpBuilder &b, mlir::Location loc) {
932-
CIRGenFunction::LexicalScope lexScope{*this, loc,
933-
builder.getInsertionBlock()};
934-
935-
lv = emitLValue(cleanups->getSubExpr());
936-
if (lv.isSimple()) {
937-
// Defend against branches out of gnu statement expressions
938-
// surrounded by cleanups.
939-
Address addr = lv.getAddress();
940-
mlir::Value v = addr.getPointer();
941-
assert(!cir::MissingFeatures::addressIsKnownNonNull());
942-
assert(!cir::MissingFeatures::opTBAA());
943-
assert(!cir::MissingFeatures::objCGC());
944-
lv = LValue::makeAddr(addr.withPointer(v), lv.getType(),
945-
lv.getBaseInfo());
946-
}
947-
});
948-
949-
// FIXME: Is it possible to create an ExprWithCleanups that produces a
950-
// bitfield lvalue or some other non-simple lvalue?
926+
RunCleanupsScope scope(*this);
927+
LValue lv = emitLValue(cleanups->getSubExpr());
928+
assert(!cir::MissingFeatures::cleanupWithPreservedValues());
951929
return lv;
952930
}
953931
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)