================
@@ -17,11 +17,29 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FormatString.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/Support/TextEncoding.h"
 
 namespace clang {
 
 class LangOptions;
 
+/// Creates a TextEncodingConverter for format string character comparisons.
+/// On z/OS format strings are IBM-1047 encoded, so each byte must be converted
----------------
hubert-reinterpretcast wrote:

> The format string is stored in the literal encoding specified by 
> -fexec-charset

A point in favour: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20110 (still 
open) expresses the opinion that the format checking should be done based on 
the literal encoding.

> every target should convert characters back to the internal/host UTF-8 
> encoding before comparing them.

At least wholesale conversion of the format string from the literal encoding is 
not the correct mechanism. A conversion-based approach would fall apart because 
C's format strings are partially "character"-based, where a "character" means a 
byte. This is most noticeable in relation to the `[` conversion specifier of 
the `scanf` family, where a multibyte character whose encoding includes a byte 
matching the value of `]` can be used to specify the "characters" preceding the 
`]` as members of the scanset — some (but not all) C library 
implementations do behave this way. Also, conversion specifications in general 
are "character"-based, so redundant shift sequences that encode no characters 
should be observed within them (and not ignored) — this is actually also 
true when matching ordinary multibyte characters from the input (see 
https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_018.html).

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

Reply via email to