From: Steven Watanabe Date: Sat, 13 Feb 2016 02:31:28 +0000 (+0000) Subject: Fix the ASTPrinter output for ascii char literals >127. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67be982a79f12b384953701243d7e1d74e6a4510;p=clang Fix the ASTPrinter output for ascii char literals >127. Differential Revision: http://reviews.llvm.org/D17206 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260795 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index a45b9a2727..3ee63e020a 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -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) diff --git a/test/Misc/ast-print-char-literal.cpp b/test/Misc/ast-print-char-literal.cpp index bb5daa2444..614b3ca9d7 100644 --- a/test/Misc/ast-print-char-literal.cpp +++ b/test/Misc/ast-print-char-literal.cpp @@ -13,6 +13,8 @@ void i() { h(); } +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 // CHECK: h(); +// CHECK: char j = '\xff';