[llvm] [AMDGPU] Fix use-after-erase in OpenCL printf runtime binding (PR #177356)

Steffen Larsen via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 04:21:06 PST 2026


================
@@ -416,9 +416,13 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
     }
   }
 
-  // erase the printf calls
-  for (auto *CI : Printfs)
+  // Erase the printf calls and replace all uses with 0, signaling success.
+  // Since OpenCL only specifies undefined behaviors and not success criteria,
+  // returning 0 sinalling success always is valid.
+  for (auto *CI : Printfs) {
+    CI->replaceAllUsesWith(ConstantInt::get(I32Ty, 0));
----------------
steffenlarsen wrote:

Sounds good to me! Addressed in https://github.com/llvm/llvm-project/pull/177573.

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


More information about the llvm-commits mailing list