[PATCH] D17206: Fix AST printing of ascii char literals above 127.
Steven Watanabe via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 12 11:32:18 PST 2016
steven_watanabe created this revision.
steven_watanabe added a reviewer: rsmith.
steven_watanabe added a subscriber: cfe-commits.
Currently literals like '\xff' may be sign extended, resulting in output like '\Uffffffff', which is not valid.
http://reviews.llvm.org/D17206
Files:
lib/AST/StmtPrinter.cpp
test/Misc/ast-print-char-literal.cpp
Index: test/Misc/ast-print-char-literal.cpp
===================================================================
--- test/Misc/ast-print-char-literal.cpp
+++ test/Misc/ast-print-char-literal.cpp
@@ -13,6 +13,8 @@
h<u8'2'>();
}
+char j = '\xFF';
+
// CHECK: char c = u8'1';
// CHECK-NEXT: char d = '1';
// CHECK-NEXT: char e = U'1';
@@ -22,3 +24,4 @@
// CHECK: template <char c = u8'1'>
// CHECK: h<u8'2'>();
+// CHECK: char j = '\xff';
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp
+++ lib/AST/StmtPrinter.cpp
@@ -1250,6 +1250,10 @@
OS << "'\\v'";
break;
default:
+ // A character literal might be sign-extended, which
+ // would result in an invalid \U escape sequence.
+ if ((value & ~0xFFu) == ~0xFFu && Node->getKind() == CharacterLiteral::Ascii)
+ value &= 0xFFu;
if (value < 256 && isPrintable((unsigned char)value))
OS << "'" << (char)value << "'";
else if (value < 256)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17206.47822.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160212/7bbce68b/attachment.bin>
More information about the cfe-commits
mailing list