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

Alex Voicu via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 03:21:06 PDT 2026


================
@@ -639,11 +640,8 @@ 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))
-      C->handleOperandChange(F, NewF);
-    else
-      U->replaceUsesOfWith(F, NewF);
   }
+  F->replaceAllUsesWith(NewF);
----------------
AlexVlx wrote:

> While I agree, that RAUW should be the way to fix, one part I don't understand is that if pre-existing check "`&& CI->getCalledFunction() == F`" still relevant. also the entire `make_early_inc_range` feels a bit pointless...
> 
> ... and this tickle my senses as there is something off, therefore ...

Technically RAUW is not the way to fix, because `F` and `NewF` have different types, and RAUW is not supposed to work on that. The loop that tickles you existed because of that, it was using interfaces that do the unsafe replacement. Having said that, at the moment the impl checks on `getType` (which simply returns `ptr`) and doesn't deal with `FunctionType` separately, so this might be fine unless someone comes at a later time and tweaks the asserts. 

> While I agree, that RAUW should be the way to fix, one part I don't understand is that if pre-existing check "`&& CI->getCalledFunction() == F`" still relevant. also the entire `make_early_inc_range` feels a bit pointless...
> 
> ... and this tickle my senses as there is something off, therefore ...

Technically RAUW is not the way to fix, because `F` and `NewF` have different types, and RAUW is not supposed to work on that. The loop that tickles you existed because of that, it was using interfaces that do the unsafe replacement. Having said that, at the moment the impl checks on `getType` (which simply returns `ptr`) and doesn't deal with `FunctionType` separately, so this might be fine unless someone comes at a later time and tweaks the asserts. 

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


More information about the llvm-commits mailing list