Fix the ASTPrinter output for ascii char literals >127.
authorSteven Watanabe <steven@providere-consulting.com>
Sat, 13 Feb 2016 02:31:28 +0000 (02:31 +0000)
committerSteven Watanabe <steven@providere-consulting.com>
Sat, 13 Feb 2016 02:31:28 +0000 (02:31 +0000)
Differential Revision: http://reviews.llvm.org/D17206

llvm-svn: 260795

clang/lib/AST/StmtPrinter.cpp
clang/test/Misc/ast-print-char-literal.cpp

index a45b9a2..3ee63e0 100644 (file)
@@ -1250,6 +1250,12 @@ void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
     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)
index bb5daa2..614b3ca 100644 (file)
@@ -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';