Skip to content

Commit d5f58a5

Browse files
authored
[CoroSplit] Fix use-after-free related to coro.suspend (#156572)
Fix #156444
1 parent 5850c44 commit d5f58a5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ void coro::Shape::invalidateCoroutine(
356356
// present.
357357
for (AnyCoroSuspendInst *CS : CoroSuspends) {
358358
CS->replaceAllUsesWith(PoisonValue::get(CS->getType()));
359-
CS->eraseFromParent();
360359
if (auto *CoroSave = CS->getCoroSave())
361360
CoroSave->eraseFromParent();
361+
CS->eraseFromParent();
362362
}
363363
CoroSuspends.clear();
364364

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; Tests that coro-split correctly invalidate bad coroutines
3+
; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s
4+
5+
define void @pr156444() presplitcoroutine {
6+
; CHECK-LABEL: define void @pr156444(
7+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: ret void
10+
;
11+
entry:
12+
%0 = call i8 @llvm.coro.suspend(token none, i1 false)
13+
ret void
14+
}

0 commit comments

Comments
 (0)