[clang] [AMDGPU] Treat printf as builtin for OpenCL (PR #72554)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 13:01:13 PST 2023


================
@@ -2458,6 +2458,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
     BuiltinID = mutateLongDoubleBuiltin(BuiltinID);
 
+   // Mutate the printf builtin ID so that we use the same CodeGen path for
+   // HIP and OpenCL with AMDGPU targets.
+   if (getTarget().getTriple().isAMDGCN() && BuiltinID == AMDGPU::BIprintf)
+     BuiltinID = Builtin::BIprintf;
----------------
jhuber6 wrote:

If we do the eager replacement of `printf` that HIP and OpenCL uses currently then it won't be linked in. So users should still be able to link in stuff like `strcmp` or whatever without it interfering. This would require the new driver however, and if they attempted to use something like `fputs` it would segfault because no one initialized the buffer, which isn't a terrible failure mode all things considered.

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


More information about the cfe-commits mailing list