r260795 - Fix the ASTPrinter output for ascii char literals >127.
Steven Watanabe via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 12 18:31:28 PST 2016
Author: steven_watanabe
Date: Fri Feb 12 20:31:28 2016
New Revision: 260795
URL: http://llvm.org/viewvc/llvm-project?rev=260795&view=rev
Log:
Fix the ASTPrinter output for ascii char literals >127.
Differential Revision: http://reviews.llvm.org/D17206
Modified:
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/test/Misc/ast-print-char-literal.cpp
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=260795&r1=260794&r2=260795&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Feb 12 20:31:28 2016
@@ -1250,6 +1250,12 @@ void StmtPrinter::VisitCharacterLiteral(
OS << "'\\v'";
break;
default:
+ // A character literal might be sign-extended, which
+ // would result in an invalid \U escape sequence.
+ // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF'
+ // are not correctly handled.
+ if ((value & ~0xFFu) == ~0xFFu && Node->getKind() == CharacterLiteral::Ascii)
+ value &= 0xFFu;
if (value < 256 && isPrintable((unsigned char)value))
OS << "'" << (char)value << "'";
else if (value < 256)
Modified: cfe/trunk/test/Misc/ast-print-char-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-char-literal.cpp?rev=260795&r1=260794&r2=260795&view=diff
==============================================================================
--- cfe/trunk/test/Misc/ast-print-char-literal.cpp (original)
+++ cfe/trunk/test/Misc/ast-print-char-literal.cpp Fri Feb 12 20:31:28 2016
@@ -13,6 +13,8 @@ void i() {
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 @@ void i() {
// CHECK: template <char c = u8'1'>
// CHECK: h<u8'2'>();
+// CHECK: char j = '\xff';
More information about the cfe-commits
mailing list