[llvm] fix cratch in tail call return type (PR #210579)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 19 01:11:11 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: SomeFlyingThing

<details>
<summary>Changes</summary>

fixes a crash in tail-call return type eligibility handling for an empty aggregate return path and adds regression tests

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


2 Files Affected:

- (modified) llvm/lib/CodeGen/Analysis.cpp (+4-2) 
- (added) llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll (+9) 


``````````diff
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index 9ece9f0c187a2..c4d50b38479a5 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -692,8 +692,10 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F,
       // We've exhausted the values produced by the tail call instruction, the
       // rest are essentially undef. The type doesn't really matter, but we need
       // *something*.
-      Type *SlotType =
-          ExtractValueInst::getIndexedType(RetSubTypes.back(), RetPath.back());
+      Type *SlotType = RetVal->getType();
+      if (!RetPath.empty())
+        SlotType = ExtractValueInst::getIndexedType(RetSubTypes.back(),
+                                                    RetPath.back());
       CallVal = UndefValue::get(SlotType);
     }
 
diff --git a/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll b/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll
new file mode 100644
index 0000000000000..1b2e86af6f79b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll
@@ -0,0 +1,9 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -o /dev/null
+
+declare { {} } @callee()
+
+define i32 @caller() {
+entry:
+  %call = tail call { {} } @callee()
+  ret i32 0
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/210579


More information about the llvm-commits mailing list