================
@@ -181,6 +182,16 @@ RValue 
CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
     Args.push_back(Arg);
   }
 
+  // The expansion reads the format from the initializer of the global it 
points
+  // to, which may not be emitted yet for a deferred constant array. Pass a 
copy
+  // of the evaluated format instead.
+  StringRef FmtStr;
+  if (!llvm::getConstantStringInfo(Args[0], FmtStr))
+    if (std::optional<std::string> Fmt =
+            E->getArg(0)->tryEvaluateString(getContext()))
----------------
steffenlarsen wrote:

> I assume you also need some kind of special handling for %n.

Absolutely, but it doesn't seem to be something we support today at all.

> If you want to specifically say "if printf has a pointer argument, the format 
> string must be a string literal", that could work, I guess. I don't want to 
> leave a hole here where we miscompile if we fail to fold the format string.

I'll make another patch. I suspect it should be fine to require that the format 
is evaluable if there is a pointer argument. Users that want to print the 
address of a pointer should either make the format evaluable or cast the 
pointer to an integer.

https://github.com/llvm/llvm-project/pull/231967
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to