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

Steffen Larsen via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 22 22:58:24 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:

Testing locally, it doesn't seem to. I'll happily add validation as a follow-up patch. Would a diagnostic close to here be sufficient or would it be more appropriate to do it somewhere else?

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


More information about the llvm-commits mailing list