[Coro] Handle aliases to coroutines#204408
Merged
Merged
Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Jun 17, 2026
mtrofin
marked this pull request as ready for review
June 17, 2026 18:17
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-coroutines Author: Mircea Trofin (mtrofin) ChangesAliases to coroutines appear to not be handled, this PR addresses that. 5 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Coroutines/CoroInstr.h b/llvm/include/llvm/Transforms/Coroutines/CoroInstr.h
index cfdf831709adc..71632a46dcde1 100644
--- a/llvm/include/llvm/Transforms/Coroutines/CoroInstr.h
+++ b/llvm/include/llvm/Transforms/Coroutines/CoroInstr.h
@@ -215,7 +215,8 @@ class CoroIdInst : public AnyCoroIdInst {
void setInfo(Constant *C) { setArgOperand(InfoArg, C); }
Function *getCoroutine() const {
- return cast<Function>(getArgOperand(CoroutineArg)->stripPointerCasts());
+ return cast<Function>(
+ getArgOperand(CoroutineArg)->stripPointerCastsAndAliases());
}
void setCoroutineSelf() {
if (!isa<ConstantPointerNull>(getArgOperand(CoroutineArg)))
@@ -254,17 +255,20 @@ class AnyCoroIdRetconInst : public AnyCoroIdInst {
/// attributes, and calling convention of the continuation function(s)
/// are taken from this declaration.
Function *getPrototype() const {
- return cast<Function>(getArgOperand(PrototypeArg)->stripPointerCasts());
+ return cast<Function>(
+ getArgOperand(PrototypeArg)->stripPointerCastsAndAliases());
}
/// Return the function to use for allocating memory.
Function *getAllocFunction() const {
- return cast<Function>(getArgOperand(AllocArg)->stripPointerCasts());
+ return cast<Function>(
+ getArgOperand(AllocArg)->stripPointerCastsAndAliases());
}
/// Return the function to use for deallocating memory.
Function *getDeallocFunction() const {
- return cast<Function>(getArgOperand(DeallocArg)->stripPointerCasts());
+ return cast<Function>(
+ getArgOperand(DeallocArg)->stripPointerCastsAndAliases());
}
// Methods to support type inquiry through isa, cast, and dyn_cast:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e247582bb57ea..f542a5e82c6fd 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6276,7 +6276,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
Check(isa<ConstantPointerNull>(Promise) || isa<AllocaInst>(Promise),
"promise argument must refer to an alloca");
- auto *CoroAddr = Call.getArgOperand(2)->stripPointerCasts();
+ auto *CoroAddr = Call.getArgOperand(2)->stripPointerCastsAndAliases();
bool BeforeCoroEarly = isa<ConstantPointerNull>(CoroAddr);
Check(BeforeCoroEarly || isa<Function>(CoroAddr),
"coro argument must refer to a function");
diff --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
index 1078fbffb13e3..fc8a6277893a3 100644
--- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -140,10 +140,12 @@ bool Lowerer::lower(Function &F) {
break;
case Intrinsic::coro_async_size_replace:
auto *Target = cast<ConstantStruct>(
- cast<GlobalVariable>(II->getArgOperand(0)->stripPointerCasts())
+ cast<GlobalVariable>(
+ II->getArgOperand(0)->stripPointerCastsAndAliases())
->getInitializer());
auto *Source = cast<ConstantStruct>(
- cast<GlobalVariable>(II->getArgOperand(1)->stripPointerCasts())
+ cast<GlobalVariable>(
+ II->getArgOperand(1)->stripPointerCastsAndAliases())
->getInitializer());
auto *TargetSize = Target->getOperand(1);
auto *SourceSize = Source->getOperand(1);
diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index 9e798ccbaacee..a922099a1f43f 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -555,7 +555,7 @@ void coro::Shape::emitDealloc(IRBuilder<> &Builder, Value *Ptr,
/// Check that the given value is a well-formed prototype for the
/// llvm.coro.id.retcon.* intrinsics.
static void checkWFRetconPrototype(const AnyCoroIdRetconInst *I, Value *V) {
- auto F = dyn_cast<Function>(V->stripPointerCasts());
+ auto F = dyn_cast<Function>(V->stripPointerCastsAndAliases());
if (!F)
fail(I, "llvm.coro.id.retcon.* prototype not a Function", V);
@@ -591,7 +591,7 @@ static void checkWFRetconPrototype(const AnyCoroIdRetconInst *I, Value *V) {
/// Check that the given value is a well-formed allocator.
static void checkWFAlloc(const Instruction *I, Value *V) {
- auto F = dyn_cast<Function>(V->stripPointerCasts());
+ auto F = dyn_cast<Function>(V->stripPointerCastsAndAliases());
if (!F)
fail(I, "llvm.coro.* allocator not a Function", V);
@@ -606,7 +606,7 @@ static void checkWFAlloc(const Instruction *I, Value *V) {
/// Check that the given value is a well-formed deallocator.
static void checkWFDealloc(const Instruction *I, Value *V) {
- auto F = dyn_cast<Function>(V->stripPointerCasts());
+ auto F = dyn_cast<Function>(V->stripPointerCastsAndAliases());
if (!F)
fail(I, "llvm.coro.* deallocator not a Function", V);
@@ -637,7 +637,8 @@ void AnyCoroIdRetconInst::checkWellFormed() const {
}
static void checkAsyncFuncPointer(const Instruction *I, Value *V) {
- auto *AsyncFuncPtrAddr = dyn_cast<GlobalVariable>(V->stripPointerCasts());
+ auto *AsyncFuncPtrAddr =
+ dyn_cast<GlobalVariable>(V->stripPointerCastsAndAliases());
if (!AsyncFuncPtrAddr)
fail(I, "llvm.coro.id.async async function pointer not a global", V);
}
diff --git a/llvm/test/Transforms/Coroutines/coro-id-alias.ll b/llvm/test/Transforms/Coroutines/coro-id-alias.ll
new file mode 100644
index 0000000000000..86381e58a58b4
--- /dev/null
+++ b/llvm/test/Transforms/Coroutines/coro-id-alias.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -passes=coro-early -S | FileCheck %s
+
+declare token @llvm.coro.id(i32, ptr, ptr, ptr)
+
+@foo_alias = alias void (), ptr @foo
+
+define void @foo() presplitcoroutine {
+entry:
+ %id = call token @llvm.coro.id(i32 0, ptr null, ptr @foo_alias, ptr null)
+ ret void
+}
+; CHECK-LABEL: define void @foo()
+; CHECK: call token @llvm.coro.id(i32 0, ptr null, ptr @foo, ptr null)
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
mtrofin
force-pushed
the
users/mtrofin/06-17-_coro_handle_aliases
branch
from
June 17, 2026 21:36
7834ddf to
8cce117
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Aliases to coroutines appear to not be handled, this PR addresses that.