[llvm] [llubi] Fix invalid printf format specifier for %c (PR #191713)

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 12 07:10:32 PDT 2026


https://github.com/jsji created https://github.com/llvm/llvm-project/pull/191713

Fix ASAN warning about unexpected format specifier %llc introduced
in commit f149ab665a4b. The 'c' format specifier should not have the
'll' length modifier. Separated the 'c' case to use the correct format
without the length modifier, casting to int as required by the standard.


>From 6655bc3266754c1d06b311a0f6062831fb7f51dc Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sun, 12 Apr 2026 15:43:20 +0200
Subject: [PATCH] [llubi] Fix invalid printf format specifier for %c

Fix ASAN warning about unexpected format specifier %llc introduced
in commit f149ab665a4b. The 'c' format specifier should not have the
'll' length modifier. Separated the 'c' case to use the correct format
without the length modifier, casting to int as required by the standard.
---
 llvm/tools/llubi/lib/Library.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llubi/lib/Library.cpp b/llvm/tools/llubi/lib/Library.cpp
index b0b5e3eb2c919..b7596b117daf7 100644
--- a/llvm/tools/llubi/lib/Library.cpp
+++ b/llvm/tools/llubi/lib/Library.cpp
@@ -242,8 +242,7 @@ AnyValue Library::executePrintf(ArrayRef<AnyValue> Args) {
     case 'u':
     case 'o':
     case 'x':
-    case 'X':
-    case 'c': {
+    case 'X': {
       // FIXME: The format specifiers "b" and "B" are not implemented here
       // since currently MSVC doesn't support it.
       std::string HostFmt = CleanChunk + "ll" + Specifier;
@@ -251,6 +250,12 @@ AnyValue Library::executePrintf(ArrayRef<AnyValue> Args) {
                                         Arg.asInteger().getZExtValue()));
       break;
     }
+    case 'c': {
+      std::string HostFmt = CleanChunk + Specifier;
+      OS << format(HostFmt.c_str(),
+                   static_cast<int>(Arg.asInteger().getZExtValue()));
+      break;
+    }
     case 'f':
     case 'e':
     case 'E':



More information about the llvm-commits mailing list