Skip to content

Commit 0eb560a

Browse files
authored
[Coroutines] Don't assert if coro-early runs more than once (#134854)
The pass may run more than once during ThinLTO for example (see bug). Maybe that means those pass pipelines aren't optimal, but the pass should be resilient against that. Fixes #134054
1 parent f0131c3 commit 0eb560a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

llvm/include/llvm/Transforms/Coroutines/CoroInstr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ class CoroIdInst : public AnyCoroIdInst {
217217
return cast<Function>(getArgOperand(CoroutineArg)->stripPointerCasts());
218218
}
219219
void setCoroutineSelf() {
220-
assert(isa<ConstantPointerNull>(getArgOperand(CoroutineArg)) &&
221-
"Coroutine argument is already assigned");
220+
if (!isa<ConstantPointerNull>(getArgOperand(CoroutineArg)))
221+
assert(getCoroutine() == getFunction() && "Don't change coroutine.");
222222
setArgOperand(CoroutineArg, getFunction());
223223
}
224224

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: opt < %s -passes='module(coro-early,coro-early)' -S | FileCheck %s
2+
3+
; Check that coro-early can run twice without asserting/crashing.
4+
5+
; CHECK-LABEL: define ptr @f
6+
; CHECK: call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null)
7+
8+
define ptr @f(i32 %n) presplitcoroutine {
9+
entry:
10+
%id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
11+
%size = call i32 @llvm.coro.size.i32()
12+
%alloc = call ptr @malloc(i32 %size)
13+
%hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
14+
15+
%sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
16+
switch i8 %sp1, label %suspend [i8 0, label %resume1
17+
i8 1, label %cleanup]
18+
resume1:
19+
br label %cleanup
20+
cleanup:
21+
%mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
22+
call void @free(ptr %mem)
23+
br label %suspend
24+
suspend:
25+
call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
26+
ret ptr %hdl
27+
}
28+
29+
declare token @llvm.coro.id(i32, ptr, ptr, ptr)
30+
declare i32 @llvm.coro.size.i32()
31+
declare noalias ptr @malloc(i32)
32+
declare ptr @llvm.coro.begin(token, ptr)
33+
declare i8 @llvm.coro.suspend(token, i1)
34+
declare ptr @llvm.coro.free(token, ptr)
35+
declare void @free(ptr)
36+
declare i1 @llvm.coro.end(ptr, i1, token)

0 commit comments

Comments
 (0)