Skip to content

Commit cb7bb71

Browse files
committed
Only emit coro.promise if CoroBegin is nonnull
1 parent e1008df commit cb7bb71

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

llvm/lib/Transforms/Coroutines/CoroEarly.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,9 @@ void Lowerer::lowerEarlyIntrinsics(Function &F) {
236236
case Intrinsic::coro_destroy:
237237
lowerResumeOrDestroy(*CB, CoroSubFnInst::DestroyIndex);
238238
break;
239-
case Intrinsic::coro_promise: {
239+
case Intrinsic::coro_promise:
240240
lowerCoroPromise(cast<CoroPromiseInst>(&I));
241241
break;
242-
}
243242
case Intrinsic::coro_done:
244243
lowerCoroDone(cast<IntrinsicInst>(&I));
245244
break;
@@ -253,9 +252,9 @@ void Lowerer::lowerEarlyIntrinsics(Function &F) {
253252
for (CoroFreeInst *CF : CoroFrees)
254253
CF->setArgOperand(0, CoroId);
255254

256-
if (auto *PA = CoroId->getPromise()) {
257-
assert(CoroBegin && "Use Switch-Resumed ABI but missing coro.begin");
258-
255+
auto *PA = CoroId->getPromise();
256+
if (PA && CoroBegin) {
257+
assert(isa<AllocaInst>(PA) && "Must pass alloca to coro.id");
259258
Builder.SetInsertPoint(*CoroBegin->getInsertionPointAfterDef());
260259

261260
auto *Alignment = Builder.getInt32(PA->getAlign().value());

llvm/test/Instrumentation/AddressSanitizer/skip-coro.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ define ptr @foo() #0 {
1515
entry:
1616
%__promise = alloca %struct.Promise, align 8
1717
%0 = call token @llvm.coro.id(i32 16, ptr nonnull %__promise, ptr null, ptr null)
18-
%1 = call ptr @llvm.coro.begin(token %0, ptr null)
19-
%2 = call ptr @llvm.coro.noop()
20-
ret ptr %2
18+
%1 = call ptr @llvm.coro.noop()
19+
ret ptr %1
2120
}
2221

2322
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)

0 commit comments

Comments
 (0)