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)
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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits