[PATCH] D132413: [NFC] Make format() more amenable to format attributes
FĂ©lix Cloutier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 8 14:57:19 PDT 2022
fcloutier added a comment.
Clang is being more zealous than the standard by warning you about this because integer-type variadic arguments undergo integer promotion (6.5.2.2:6 in n2310 numbering). It is effectively impossible to pass an integer smaller than `int` to a variadic function. This means `%hu` and `%hhu` are constraints that the format function needs to read an `unsigned short` or `unsigned char` from the `va_list`, but anything smaller than `unsigned` will be converted to `unsigned` as it is being passed to the variadic function, and `va_arg(ap, unsigned char)` is necessarily equivalent to `(unsigned char)va_arg(ap, unsigned)`. This is reiterated and explicitly spelled out in 7.21.6.1:7, which describes format strings:
> `hh`: Specifies that a following `d`, `I`, `o`, `u`, `x`, or `X` conversion specifier applies to a `signed char` or `unsigned char` argument (the argument will have been promoted according to the integer promotions, but its value shall be converted to `signed char` or `unsigned char` before printing); or that a following `n` conversion specifier applies to a pointer to a `signed char` argument.
This is the rationale for which `EnsureCompatible` lets you "confuse" any integer size up to `int`. The bar chosen is whether it would be undefined behavior to proceed, and in this case it isn't.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132413/new/
https://reviews.llvm.org/D132413
More information about the llvm-commits
mailing list