[llvm] [SPIR-V] Fix crash when a function pointer global is a use of a cloned function (PR #216638)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 16 22:19:31 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>

GlobalValue operands must be updated via replaceUsesOfWith, not Constant::handleOperandChange, which doesn't support them

Fixes LCOMPILER-2616

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


2 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+1-1) 
- (modified) llvm/test/CodeGen/SPIRV/passes/SPIRVPrepareFunctions.ll (+7) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
index 6d54b6c6fa19d..f5d2dbfaf3d40 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
@@ -639,7 +639,7 @@ SPIRVPrepareFunctionsImpl::removeAggregateTypesFromSignature(Function *F) {
     if (CallInst *CI;
         (CI = dyn_cast<CallInst>(U)) && CI->getCalledFunction() == F)
       CI->mutateFunctionType(NewF->getFunctionType());
-    if (auto *C = dyn_cast<Constant>(U))
+    if (auto *C = dyn_cast<Constant>(U); C && !isa<GlobalValue>(C))
       C->handleOperandChange(F, NewF);
     else
       U->replaceUsesOfWith(F, NewF);
diff --git a/llvm/test/CodeGen/SPIRV/passes/SPIRVPrepareFunctions.ll b/llvm/test/CodeGen/SPIRV/passes/SPIRVPrepareFunctions.ll
index 91ba08d682015..d736afb2d3cd4 100644
--- a/llvm/test/CodeGen/SPIRV/passes/SPIRVPrepareFunctions.ll
+++ b/llvm/test/CodeGen/SPIRV/passes/SPIRVPrepareFunctions.ll
@@ -1,5 +1,7 @@
 ; RUN: opt -S -passes=spirv-prepare-functions -mtriple=spirv64-unknown-unknown < %s | FileCheck %s
 
+ at fp = global ptr addrspace(4) @callback
+
 ; @llvm.bswap.* is replaced with a call to a SPIR-V helper function whose
 ; body implements the byte-swap with shifts/masks/ors.
 define i32 @bswap_i32(i32 %x) {
@@ -71,3 +73,8 @@ declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1)
 declare i32 @llvm.bswap.i32(i32)
 declare i32 @llvm.fshl.i32(i32, i32, i32)
 declare i32 @llvm.fshr.i32(i32, i32, i32)
+
+; CHECK-LABEL: define i32 @callback(
+define { float, float } @callback({ float, float } %x) addrspace(4) {
+  ret { float, float } %x
+}

``````````

</details>


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


More information about the llvm-commits mailing list