[llvm] [AMDGPU] Skip printf runtime binding if function signature is unexpected (PR #177573)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 24 05:05:02 PST 2026
================
@@ -438,6 +438,20 @@ bool AMDGPUPrintfRuntimeBindingImpl::run(Module &M) {
M.getModuleFlag("openmp"))
return false;
+ // Verify the signature of the printf function and skip if it isn't correct.
+ const FunctionType *PrintfFunctionTy = PrintfFunction->getFunctionType();
+ if (PrintfFunctionTy->getNumParams() != 1 || !PrintfFunctionTy->isVarArg() ||
+ !PrintfFunctionTy->getReturnType()->isIntegerTy(32))
+ return false;
+ Type *PrintfFormatArgTy = PrintfFunctionTy->getParamType(0);
+ if (!PrintfFormatArgTy->isPointerTy() ||
+ !(PrintfFormatArgTy->getPointerAddressSpace() == AMDGPUAS::FLAT_ADDRESS ||
+ PrintfFormatArgTy->getPointerAddressSpace() ==
+ AMDGPUAS::GLOBAL_ADDRESS ||
+ PrintfFormatArgTy->getPointerAddressSpace() ==
+ AMDGPUAS::CONSTANT_ADDRESS))
----------------
arsenm wrote:
```suggestion
!AMDGPU::isFlatGlobalAddrSpace(PrintfFormatArgTy->getPointerAddressSpace())
```
More accurate and shorter
https://github.com/llvm/llvm-project/pull/177573
More information about the llvm-commits
mailing list