[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 18:35:54 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL260795: Fix the ASTPrinter output for ascii char literals >127. (authored by steven_watanabe).

Changed prior to commit:
  http://reviews.llvm.org/D17206?vs=47822&id=47887#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17206

Files:
  cfe/trunk/lib/AST/StmtPrinter.cpp
  cfe/trunk/test/Misc/ast-print-char-literal.cpp

Index: cfe/trunk/test/Misc/ast-print-char-literal.cpp
===================================================================
--- cfe/trunk/test/Misc/ast-print-char-literal.cpp
+++ cfe/trunk/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: cfe/trunk/lib/AST/StmtPrinter.cpp
===================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp
+++ cfe/trunk/lib/AST/StmtPrinter.cpp
@@ -1250,6 +1250,12 @@
     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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17206.47887.patch
Type: text/x-patch
Size: 1176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160213/3d697504/attachment-0001.bin>


More information about the cfe-commits mailing list