[cfe-dev] [Clang-Sema] Renaming function and refactoring the formatting function handling code

MLJ1991 via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 4 06:17:59 PST 2021


Hey guys,

I'm working on a proposal to ISO WG14 for C2x to add support for char16_t and char32_t string and character specifiers for the printf and scanf family of functions.

In working on this proposal for WG14, I came across an issue in Clang.

the problem is that C11 defines char16_t and char32_t as typedefs in uchar.h; while C++11 defines them as new builtin types.

The real problem with this difference, is that the printf and scanf string checking code in Sema is built with the implicit assumption that any string type passed to a printf or scanf family function will be a built in type.

for example, isAnyCharacterType() in the class clang::Type, only checks builtin types.

so when C code is compiled, char16_t and char32_t are not seen as valid string types and Clang errors out.

So to fix this mess, I've been implementing a new function called isTypedefCharacterType(ASTContext &AST) in clang:Type which will use getLangOpts() in ASTContext to check the language mode, and if we're compiling in C mode, it will desugar the type all the way down until it finds a typedef for char16_t or char32_t.

But I still have a few questions for the community.

1: How should wchar_t be treated when it's been disabled as a builtin type?

2: isAnyCharacterType() as a name does not reflect what it actually does, it only checks builtin types, I've renamed this to isBuiltinCharacterType() in my fork, there are 17 instances throughout the LLVM codebase of "isAnyCharacterType", is it ok to change this name, and if so is my choice of isBuiltinCharacterType acceptable?

3: Any other comments o concerns?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210204/649020e6/attachment.html>


More information about the cfe-dev mailing list