[clang] [clang][HIP] Disallow non-constant format string with pointer argument (PR #238287)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 03:49:10 PST 2026


================
@@ -181,6 +183,21 @@ RValue CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E) {
     Args.push_back(Arg);
   }
 
+  // The lowering can only find %s specifiers in a constant format string, so
+  // with a non-constant format a string argument would cause wrong behavior.
+  // Instead we reject it.
+  StringRef FmtStr;
+  if (!llvm::getConstantStringInfo(Args[0], FmtStr)) {
+    for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {
+      if (Args[I]->getType()->isPointerTy()) {
+        CGM.getDiags().Report(E->getArg(0)->getExprLoc(),
----------------
Fznamznon wrote:

Shouldn't that be Sema diagnostic? I thought `DiagnosticFrontendKinds` is for messages emitted from Frontend library

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


More information about the cfe-commits mailing list