[clang] [CIR] handle __builtin_coro_noop (PR #222928)
Letu Ren via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 04:35:39 PDT 2026
https://github.com/FantasqueX created https://github.com/llvm/llvm-project/pull/222928
Add cir.coro.intrinsic.noop Op.
Assisted-by: Cursor / grok-4.6
>From 7d55bf6b8ce75a4f26edb55f00a697fc9b21a830 Mon Sep 17 00:00:00 2001
From: Letu Ren <fantasquex at gmail.com>
Date: Fri, 11 Sep 2026 19:31:44 +0800
Subject: [PATCH] [CIR] handle __builtin_coro_noop
Add cir.coro.intrinsic.noop Op.
Assisted-by: Cursor / grok-4.6
Signed-off-by: Letu Ren <fantasquex at gmail.com>
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 14 ++++++++++++++
clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 3 +--
clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp | 5 +++++
clang/lib/CIR/CodeGen/CIRGenFunction.h | 1 +
clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp | 5 +++--
5 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 449af063cf9ac..cf23a39981f97 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5062,6 +5062,20 @@ def CIR_CoroDoneOp : CIR_CoroIntrinsicOp<"done", (ins CIR_VoidPtrType:$handle),
let llvmOp = "CoroDoneOp";
}
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic NoopOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CoroNoopOp : CIR_CoroIntrinsicOp<"noop", (ins),
+ (outs CIR_VoidPtrType:$result)> {
+ let summary = "Represents llvm.coro.noop";
+ let description = [{
+ Returns a handle to a coroutine that does nothing when resumed or
+ destroyed.
+ }];
+ let llvmOp = "CoroNoopOp";
+}
+
//===----------------------------------------------------------------------===//
// CopyOp
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index ee0b4fa49d4c6..afd1251c7d6a8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -1740,8 +1740,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
return RValue::get(nullptr);
}
case Builtin::BI__builtin_coro_noop:
- cgm.errorNYI(e->getSourceRange(), "BI__builtin_coro_noop NYI");
- return getUndefRValue(e->getType());
+ return RValue::get(emitCoroNoopBuiltinCall(e).getResult());
case Builtin::BI__builtin_coro_destroy: {
emitCoroDestroyBuiltinCall(e);
return RValue::get(nullptr);
diff --git a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
index 6f2c0e33ce1d9..24de5e81fdb5b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
@@ -309,6 +309,11 @@ cir::CoroSizeOp CIRGenFunction::emitCoroSizeBuiltinCall(const CallExpr *e) {
return cir::CoroSizeOp::create(cgm.getBuilder(), loc);
}
+cir::CoroNoopOp CIRGenFunction::emitCoroNoopBuiltinCall(const CallExpr *e) {
+ mlir::Location loc = getLoc(e->getBeginLoc());
+ return cir::CoroNoopOp::create(cgm.getBuilder(), loc);
+}
+
cir::CoroPromiseOp
CIRGenFunction::emitCoroPromiseBuiltinCall(const CallExpr *e) {
mlir::Location loc = getLoc(e->getBeginLoc());
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 5a4529821f5ef..c9c79fd920cd0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -1921,6 +1921,7 @@ class CIRGenFunction : public CIRGenTypeCache {
cir::CoroDestroyOp emitCoroDestroyBuiltinCall(const CallExpr *e);
cir::CoroSizeOp emitCoroSizeBuiltinCall(const CallExpr *e);
+ cir::CoroNoopOp emitCoroNoopBuiltinCall(const CallExpr *e);
cir::CoroFreeOp emitCoroFreeBuiltin(const CallExpr *e);
RValue emitCoroutineFrame();
diff --git a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
index db22a0fbaee8b..acf0ba03a2fa5 100644
--- a/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
+++ b/clang/test/CIR/CodeGenCoroutines/coro-builtins.cpp
@@ -29,8 +29,9 @@ void f(int n) {
// LLVM: call i1 @llvm.coro.alloc(token %[[COROID]])
- // TODO
- //__builtin_coro_noop();
+ __builtin_coro_noop();
+ // CIR: cir.coro.intrinsic.noop()
+ // LLVM: call ptr @llvm.coro.noop()
__builtin_coro_begin(myAlloc(__builtin_coro_size()));
// TODO(CIR): Support both variants of the coroutine size intrinsic, matching
More information about the cfe-commits
mailing list