[PATCH] D127363: [Lex] Fix for char32_t literal truncation on 16 bit architectures
Tom Honermann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 14:39:03 PDT 2022
tahonermann requested changes to this revision.
tahonermann added a comment.
This revision now requires changes to proceed.
When submitting patches, please create the diff with context so that the code can be navigated in Phabricator. See https://llvm.org/docs/Phabricator.html#phabricator-request-review-web for details on how to do so.
================
Comment at: clang/lib/Lex/LiteralSupport.cpp:1600
- llvm::APInt LitVal(PP.getTargetInfo().getIntWidth(), 0);
+ llvm::APInt LitVal(PP.getTargetInfo().getChar32Width(), 0);
----------------
I don't think this is quite right. For the code that follows this change to work as intended and issue the "Character constant too long for its type" diagnostic, the width needs to match that of `int`. This is required for multicharacter literals (they have type `int`) so that an appropriate diagnostic is issued for `'xxxxx'` for targets that have a 32-bit int (or for `'xxx'` for targets that have a 16-bit int)`.
Additionally, the type of a character constant in C is `int`.
I think what is needed is something like:
unsigned BitWidth = getCharWidth(Kind, PP.getTargetInfo());
if (IsMultiChar || !PP.getLangOpts().CPlusPlus)
BitWidth = PP.getTargetInfo().getIntWidth();
llvm::APInt LitVal(BitWidth, 0);
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127363/new/
https://reviews.llvm.org/D127363
More information about the cfe-commits
mailing list