diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp index b76450152203d..fc5dfe5f50c44 100644 --- a/clang/lib/CodeGen/CGCoroutine.cpp +++ b/clang/lib/CodeGen/CGCoroutine.cpp @@ -975,9 +975,6 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) { cast(Ret)->setRetValue(PreviousRetValue); } - // LLVM require the frontend to mark the coroutine. - CurFn->setPresplitCoroutine(); - if (CXXRecordDecl *RD = FnRetTy->getAsCXXRecordDecl(); RD && RD->hasAttr()) CurFn->setCoroDestroyOnlyWhenComplete(); diff --git a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp index cdb58523d1e0e..37e50a1a3af98 100644 --- a/llvm/lib/Transforms/Coroutines/CoroEarly.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroEarly.cpp @@ -236,9 +236,8 @@ void Lowerer::lowerEarlyIntrinsics(Function &F) { case Intrinsic::coro_id: if (auto *CII = cast(&I)) { if (CII->getInfo().isPreSplit()) { - assert(F.isPresplitCoroutine() && - "The frontend uses Switch-Resumed ABI should emit " - "\"presplitcoroutine\" attribute for the coroutine."); + // Infer `presplitcoroutine` attribute for Switch-Resumed ABI + F.setPresplitCoroutine(); setCannotDuplicate(CII); CII->setCoroutineSelf(); CoroId = cast(&I); diff --git a/llvm/test/Transforms/Coroutines/coro-early-presplit.ll b/llvm/test/Transforms/Coroutines/coro-early-presplit.ll new file mode 100644 index 0000000000000..7f7af060d51a8 --- /dev/null +++ b/llvm/test/Transforms/Coroutines/coro-early-presplit.ll @@ -0,0 +1,17 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 +; Check that coro-early can infer presplitcoroutine attribute +; RUN: opt < %s -passes='module(coro-early)' -S | FileCheck %s + +define void @f() { +; CHECK-LABEL: define void @f( +; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: [[TMP0:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null) +; CHECK-NEXT: ret void +; +entry: + call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null) + ret void +} + +; CHECK: attributes #0 = { presplitcoroutine }