[llvm] [CoroSplit] Fix use after free of coro.suspend (PR #156572)

Weibo He via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 19:21:49 PDT 2025


https://github.com/NewSigma created https://github.com/llvm/llvm-project/pull/156572

Fix #156444 

>From 6961a22d5d34f19ff4bca4fd6f6b8e7dcd637094 Mon Sep 17 00:00:00 2001
From: NewSigma <NewSigma at 163.com>
Date: Wed, 3 Sep 2025 10:17:02 +0800
Subject: [PATCH] [CoroSplit] Fix use after free of coro.suspend

---
 llvm/lib/Transforms/Coroutines/Coroutines.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index ac93f748ce65c..28a89a8f87dbd 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -356,9 +356,9 @@ void coro::Shape::invalidateCoroutine(
     // present.
     for (AnyCoroSuspendInst *CS : CoroSuspends) {
       CS->replaceAllUsesWith(PoisonValue::get(CS->getType()));
-      CS->eraseFromParent();
       if (auto *CoroSave = CS->getCoroSave())
         CoroSave->eraseFromParent();
+      CS->eraseFromParent();
     }
     CoroSuspends.clear();
 



More information about the llvm-commits mailing list