[PATCH] D124996: [clang][preprocessor] Fix unsigned-ness of utf8 char literals
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 5 03:13:26 PDT 2022
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
UTF8 char literals are always unsigned.
Fixes https://github.com/llvm/llvm-project/issues/54886
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124996
Files:
clang/lib/Lex/PPExpressions.cpp
clang/test/Lexer/utf8-char-literal.cpp
Index: clang/test/Lexer/utf8-char-literal.cpp
===================================================================
--- clang/test/Lexer/utf8-char-literal.cpp
+++ clang/test/Lexer/utf8-char-literal.cpp
@@ -26,3 +26,10 @@
unsigned char : 1),
"Surprise!");
#endif
+
+/// Test u8 char literal preprocessor behavior
+#if __cplusplus > 201402L || __STDC_VERSION__ > 202000L
+#if u8'\xff' != 0xff
+#error u8 char literal is not unsigned
+#endif
+#endif
Index: clang/lib/Lex/PPExpressions.cpp
===================================================================
--- clang/lib/Lex/PPExpressions.cpp
+++ clang/lib/Lex/PPExpressions.cpp
@@ -407,10 +407,10 @@
llvm::APSInt Val(NumBits);
// Set the value.
Val = Literal.getValue();
- // Set the signedness. UTF-16 and UTF-32 are always unsigned
+ // Set the signedness. UTF-8, UTF-16 and UTF-32 are always unsigned
if (Literal.isWide())
Val.setIsUnsigned(!TargetInfo::isTypeSigned(TI.getWCharType()));
- else if (!Literal.isUTF16() && !Literal.isUTF32())
+ else if (!Literal.isUTF8() && !Literal.isUTF16() && !Literal.isUTF32())
Val.setIsUnsigned(!PP.getLangOpts().CharIsSigned);
if (Result.Val.getBitWidth() > Val.getBitWidth()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124996.427251.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220505/8819987f/attachment.bin>
More information about the cfe-commits
mailing list