[PATCH] D127363: [Lex] Fix for char32_t literal truncation on 16 bit architectures
Sebastian Perta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 8 16:41:40 PDT 2022
SebastianPerta created this revision.
SebastianPerta added reviewers: aaron.ballman, sammccall, DaanDeMeyer.
Herald added a subscriber: dylanmckay.
Herald added a project: All.
SebastianPerta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
On 16 bit architectures char32_t literals are truncated, for example U'\U00064321' will be truncated to 0x4321.
The issue can be seen using the RL78 backend which I announced a while ago (https://lists.llvm.org/pipermail/llvm-dev/2020-April/140546.html) and I'm ready to upstream.
Upstream, the problem can be observed on MSP430, however this patch is not sufficient in case of MSP430 since Char32Type is left to the default type UnsignedInt which is 16 bit in case of MSP430 (set in TargetInfo.cpp). On RL78 I set it to UnsignedLong just like in case of AVR (see AVR.h).
Regarding testing, I found the problem using the following test from the GCC regression:
gcc/testsuite/g++.dg/ext/utf32-1.C
I'm happy to write a new test if I can get any pointers where and how to write it (the test fails at execution so not sure how to test it without executing it).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127363
Files:
clang/lib/Lex/LiteralSupport.cpp
Index: clang/lib/Lex/LiteralSupport.cpp
===================================================================
--- clang/lib/Lex/LiteralSupport.cpp
+++ clang/lib/Lex/LiteralSupport.cpp
@@ -1597,7 +1597,7 @@
IsMultiChar = false;
}
- llvm::APInt LitVal(PP.getTargetInfo().getIntWidth(), 0);
+ llvm::APInt LitVal(PP.getTargetInfo().getChar32Width(), 0);
// Narrow character literals act as though their value is concatenated
// in this implementation, but warn on overflow.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127363.435374.patch
Type: text/x-patch
Size: 488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220608/0a3ca5bc/attachment.bin>
More information about the cfe-commits
mailing list