Skip to content

Commit 03d718c

Browse files
Apply review feedback
1 parent b9fdcce commit 03d718c

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ def CIR_FuncOp : CIR_Op<"func", [
23442344
A compiler builtin function must be marked as `builtin` for further
23452345
processing when lowering from CIR.
23462346

2347-
The `coroutine` keyword is used to mark coroutine function, which requires
2347+
The `coroutine` keyword is used to mark a coroutine function, which requires
23482348
at least one `cir.await` instruction to be used in its body.
23492349

23502350
The `lambda` translates to a C++ `operator()` that implements a lambda, this

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
439439
case Builtin::BI__builtin_coro_end:
440440
case Builtin::BI__builtin_coro_suspend:
441441
case Builtin::BI__builtin_coro_align:
442-
llvm_unreachable("BI__builtin_coro_id like NYI");
442+
llvm_unreachable("Error NYI");
443443

444444
case Builtin::BI__builtin_coro_frame: {
445445
cgm.errorNYI(e->getSourceRange(), "BI__builtin_coro_frame NYI");

clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ CIRGenFunction::CGCoroInfo::~CGCoroInfo() {}
3232
static void createCoroData(CIRGenFunction &cgf,
3333
CIRGenFunction::CGCoroInfo &curCoro,
3434
cir::CallOp coroId) {
35-
if (curCoro.data) {
36-
llvm_unreachable("EmitCoroutineBodyStatement called twice?");
37-
return;
38-
}
35+
assert(!curCoro.data && "EmitCoroutineBodyStatement called twice?");
3936

40-
curCoro.data = std::unique_ptr<CGCoroData>(new CGCoroData);
37+
curCoro.data = std::make_unique<CGCoroData>();
4138
curCoro.data->coroId = coroId;
4239
}
4340

@@ -57,8 +54,9 @@ cir::CallOp CIRGenFunction::emitCoroIDBuiltinCall(mlir::Location loc,
5754
cir::FuncType::get({int32Ty, VoidPtrTy, VoidPtrTy, VoidPtrTy}, int32Ty),
5855
/*FD=*/nullptr);
5956
assert(fnOp && "should always succeed");
60-
} else
57+
} else {
6158
fnOp = cast<cir::FuncOp>(builtin);
59+
}
6260

6361
return builder.createCallOp(loc, fnOp,
6462
mlir::ValueRange{builder.getUInt32(newAlign, loc),
@@ -70,8 +68,7 @@ CIRGenFunction::emitCoroutineBody(const CoroutineBodyStmt &s) {
7068
mlir::Location openCurlyLoc = getLoc(s.getBeginLoc());
7169
cir::ConstantOp nullPtrCst = builder.getNullPtr(VoidPtrTy, openCurlyLoc);
7270

73-
auto fn = dyn_cast<cir::FuncOp>(curFn);
74-
assert(fn && "other callables are NYI");
71+
auto fn = mlir::cast<cir::FuncOp>(curFn);
7572
fn.setCoroutine(true);
7673
cir::CallOp coroId = emitCoroIDBuiltinCall(openCurlyLoc, nullPtrCst);
7774
createCoroData(*this, curCoro, coroId);

clang/test/CIR/IR/func.cir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,15 @@ cir.func @ullfunc() -> !u64i {
9999
// CHECK: %[[VAL:.*]] = cir.const #cir.int<42> : !u64i
100100
// CHECK: cir.return %[[VAL:.*]] : !u64i
101101
// CHECK: }
102+
103+
cir.func coroutine @coro() {
104+
cir.return
105+
}
106+
// CHECK: cir.func{{.*}} coroutine @coro()
107+
108+
cir.func builtin @builtin() {
109+
cir.return
110+
}
111+
// CHECK: cir.func{{.*}} builtin @builtin()
112+
102113
}

0 commit comments

Comments
 (0)