[llvm] 4f1de83 - [Clang][NFC][Coroutine] Do not leave dangling pointers after removing CoroBegin (#98546)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 19:46:38 PDT 2024
Author: Yuxuan Chen
Date: 2024-07-11T19:46:35-07:00
New Revision: 4f1de83d537f62070cde85e09e88bc229316b3e1
URL: https://github.com/llvm/llvm-project/commit/4f1de83d537f62070cde85e09e88bc229316b3e1
DIFF: https://github.com/llvm/llvm-project/commit/4f1de83d537f62070cde85e09e88bc229316b3e1.diff
LOG: [Clang][NFC][Coroutine] Do not leave dangling pointers after removing CoroBegin (#98546)
Added:
Modified:
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 0b52d1e4490cb..9e4da5f8ca961 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1248,6 +1248,7 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) {
}
CoroBegin->eraseFromParent();
+ Shape.CoroBegin = nullptr;
}
// SimplifySuspendPoint needs to check that there is no calls between
@@ -1970,9 +1971,17 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
}
/// Remove calls to llvm.coro.end in the original function.
-static void removeCoroEnds(const coro::Shape &Shape) {
- for (auto *End : Shape.CoroEnds) {
- replaceCoroEnd(End, Shape, Shape.FramePtr, /*in resume*/ false, nullptr);
+static void removeCoroEndsFromRampFunction(const coro::Shape &Shape) {
+ if (Shape.ABI != coro::ABI::Switch) {
+ for (auto *End : Shape.CoroEnds) {
+ replaceCoroEnd(End, Shape, Shape.FramePtr, /*in resume*/ false, nullptr);
+ }
+ } else {
+ for (llvm::AnyCoroEndInst *End : Shape.CoroEnds) {
+ auto &Context = End->getContext();
+ End->replaceAllUsesWith(ConstantInt::getFalse(Context));
+ End->eraseFromParent();
+ }
}
}
@@ -1981,18 +1990,6 @@ static void updateCallGraphAfterCoroutineSplit(
const SmallVectorImpl<Function *> &Clones, LazyCallGraph::SCC &C,
LazyCallGraph &CG, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR,
FunctionAnalysisManager &FAM) {
- if (!Shape.CoroBegin)
- return;
-
- if (Shape.ABI != coro::ABI::Switch)
- removeCoroEnds(Shape);
- else {
- for (llvm::AnyCoroEndInst *End : Shape.CoroEnds) {
- auto &Context = End->getContext();
- End->replaceAllUsesWith(ConstantInt::getFalse(Context));
- End->eraseFromParent();
- }
- }
if (!Clones.empty()) {
switch (Shape.ABI) {
@@ -2120,6 +2117,7 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
const coro::Shape Shape =
splitCoroutine(F, Clones, FAM.getResult<TargetIRAnalysis>(F),
OptimizeFrame, MaterializableCallback);
+ removeCoroEndsFromRampFunction(Shape);
updateCallGraphAfterCoroutineSplit(*N, Shape, Clones, C, CG, AM, UR, FAM);
ORE.emit([&]() {
More information about the llvm-commits
mailing list