[cfe-commits] r147385 - in /cfe/trunk: lib/AST/StmtPrinter.cpp test/SemaCXX/constexpr-printing.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Fri Dec 30 15:37:31 PST 2011
Author: rsmith
Date: Fri Dec 30 17:37:31 2011
New Revision: 147385
URL: http://llvm.org/viewvc/llvm-project?rev=147385&view=rev
Log:
Fix crash when trying to pretty-print unicode or wide string literals.
Modified:
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/test/SemaCXX/constexpr-printing.cpp
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=147385&r1=147384&r2=147385&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Dec 30 17:37:31 2011
@@ -710,16 +710,27 @@
case StringLiteral::UTF32: OS << 'U'; break;
}
OS << '"';
+ static char Hex[] = "0123456789ABCDEF";
- // FIXME: this doesn't print wstrings right.
- StringRef StrData = Str->getString();
- for (StringRef::iterator I = StrData.begin(), E = StrData.end();
- I != E; ++I) {
- unsigned char Char = *I;
-
- switch (Char) {
+ for (unsigned I = 0, N = Str->getLength(); I != N; ++I) {
+ switch (uint32_t Char = Str->getCodeUnit(I)) {
default:
- if (isprint(Char))
+ // FIXME: Is this the best way to print wchar_t?
+ if (Char > 0xff) {
+ // char32_t values are <= 0x10ffff.
+ if (Char > 0xffff)
+ OS << "\\U00"
+ << Hex[(Char >> 20) & 15]
+ << Hex[(Char >> 16) & 15];
+ else
+ OS << "\\u";
+ OS << Hex[(Char >> 12) & 15]
+ << Hex[(Char >> 8) & 15]
+ << Hex[(Char >> 4) & 15]
+ << Hex[(Char >> 0) & 15];
+ break;
+ }
+ if (Char <= 0xff && isprint(Char))
OS << (char)Char;
else // Output anything hard as an octal escape.
OS << '\\'
Modified: cfe/trunk/test/SemaCXX/constexpr-printing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constexpr-printing.cpp?rev=147385&r1=147384&r2=147385&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constexpr-printing.cpp (original)
+++ cfe/trunk/test/SemaCXX/constexpr-printing.cpp Fri Dec 30 17:37:31 2011
@@ -73,3 +73,17 @@
}
static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), ""); // expected-error {{constant expression}} \
expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}}
+
+template<typename CharT>
+constexpr CharT get(const CharT *p) { return p[-1]; } // expected-note 5{{}}
+
+constexpr char c = get("test\0\\\"\t\a\b\234"); // \
+ expected-error {{}} expected-note {{"test\000\\\"\t\a\b\234"}}
+constexpr char c8 = get(u8"test\0\\\"\t\a\b\234"); // \
+ expected-error {{}} expected-note {{u8"test\000\\\"\t\a\b\234"}}
+constexpr char16_t c16 = get(u"test\0\\\"\t\a\b\234\u1234"); // \
+ expected-error {{}} expected-note {{u"test\000\\\"\t\a\b\234\u1234"}}
+constexpr char32_t c32 = get(U"test\0\\\"\t\a\b\234\u1234\U00101234"); // \
+ expected-error {{}} expected-note {{U"test\000\\\"\t\a\b\234\u1234\U00101234"}}
+constexpr wchar_t wc = get(L"test\0\\\"\t\a\b\234\u1234"); // \
+ expected-error {{}} expected-note {{L"test\000\\\"\t\a\b\234\u1234"}}
More information about the cfe-commits
mailing list