[clang] Add ParserConversionAction (PR #169803)

Sean Perry via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 3 13:19:34 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);
----------------
perry-ca wrote:

We did consider the opposite conversion but as you noted all of the switch statements would need to be rewritten.  We felt the performance impact would be too high and wasn't likely to be acceptable from maintenance perspective either.

The original code already has a baked in property of not handling utf-8 sequences (the args are const char * and the code uses ++ to step to next char).  All that is required here is a convert function that returns the correct char for printable characters.  The conversion function can return `'\0'` for any non-printable character.  What about changing the name of the function to emphasize this nature of the function?  That should help avoid someone comparing the result to zero.

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


More information about the cfe-commits mailing list