[llvm-branch-commits] [clang] [llvm] Continuation of fexec-charset (PR #169803)

Sergei Barannikov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon May 4 18:51:10 PDT 2026


================
@@ -33,16 +33,17 @@ FormatStringHandler::~FormatStringHandler() {}
 // scanf format strings.
 //===----------------------------------------------------------------------===//
 
-OptionalAmount
-clang::analyze_format_string::ParseAmount(const char *&Beg, const char *E) {
+OptionalAmount clang::analyze_format_string::ParseAmount(
+    const char *&Beg, const char *E,
+    const llvm::TextEncodingConverter &FormatStrConverter) {
   const char *I = Beg;
   UpdateOnReturn <const char*> UpdateBeg(Beg, I);
 
   unsigned accumulator = 0;
   bool hasDigits = false;
 
   for ( ; I != E; ++I) {
-    char c = *I;
+    char c = FormatStrConverter.convert(*I);
----------------
s-barannikov wrote:

> If this is the only issue, returning `std::optional` from `convert` would solve it. Or it should be documented that 'all zeros' input is a special value and should not be passed in (and asserted in the implementation).

I tried adding the assertion, but that didn't work out. Null character can appear anywhere in the format string, and the assertion may trigger on any call to `convert`. I guess returning 0 for non-ascii characters (as it is now) is the simpliest solution; we only need to make sure we don't use the result of the conversion in comparison against zero.


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


More information about the llvm-branch-commits mailing list