Skip to content

[Coro] Handle aliases to coroutines#204408

Merged
mtrofin merged 1 commit into
mainfrom
users/mtrofin/06-17-_coro_handle_aliases
Jun 18, 2026
Merged

[Coro] Handle aliases to coroutines#204408
mtrofin merged 1 commit into
mainfrom
users/mtrofin/06-17-_coro_handle_aliases

Conversation

@mtrofin

@mtrofin mtrofin commented Jun 17, 2026

Copy link
Copy Markdown
Member

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

mtrofin commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

@mtrofin
mtrofin requested a review from ChuanqiXu9 June 17, 2026 18:16
@mtrofin mtrofin changed the title [Coro] Handle aliases [Coro] Handle aliases to coroutines Jun 17, 2026
@mtrofin
mtrofin marked this pull request as ready for review June 17, 2026 18:17
@llvmorg-github-actions

llvmorg-github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-coroutines

Author: Mircea Trofin (mtrofin)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/204408.diff

5 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Coroutines/CoroInstr.h (+8-4)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Coroutines/CoroCleanup.cpp (+4-2)
  • (modified) llvm/lib/Transforms/Coroutines/Coroutines.cpp (+5-4)
  • (added) llvm/test/Transforms/Coroutines/coro-id-alias.ll (+13)
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)

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 135969 tests passed
  • 3455 tests skipped

✅ The build succeeded and all tests passed.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 197048 tests passed
  • 5393 tests skipped

✅ The build succeeded and all tests passed.

@mtrofin
mtrofin force-pushed the users/mtrofin/06-17-_coro_handle_aliases branch from 7834ddf to 8cce117 Compare June 17, 2026 21:36

@ChuanqiXu9 ChuanqiXu9 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtrofin
mtrofin merged commit ee2c896 into main Jun 18, 2026
11 checks passed
@mtrofin
mtrofin deleted the users/mtrofin/06-17-_coro_handle_aliases branch June 18, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants