r257097 - Properly track that a character literal is UTF-8, and pretty print the prefix properly.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 7 12:59:27 PST 2016
Author: aaronballman
Date: Thu Jan 7 14:59:26 2016
New Revision: 257097
URL: http://llvm.org/viewvc/llvm-project?rev=257097&view=rev
Log:
Properly track that a character literal is UTF-8, and pretty print the prefix properly.
Added:
cfe/trunk/test/Misc/ast-print-char-literal.cpp
cfe/trunk/test/PCH/cxx-char-literal.cpp
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Jan 7 14:59:26 2016
@@ -1292,6 +1292,7 @@ public:
enum CharacterKind {
Ascii,
Wide,
+ UTF8,
UTF16,
UTF32
};
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Jan 7 14:59:26 2016
@@ -130,7 +130,7 @@ protected:
friend class CharacterLiteral;
unsigned : NumExprBits;
- unsigned Kind : 2;
+ unsigned Kind : 3;
};
enum APFloatSemantics {
Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Thu Jan 7 14:59:26 2016
@@ -166,6 +166,7 @@ public:
bool hadError() const { return HadError; }
bool isAscii() const { return Kind == tok::char_constant; }
bool isWide() const { return Kind == tok::wide_char_constant; }
+ bool isUTF8() const { return Kind == tok::utf8_char_constant; }
bool isUTF16() const { return Kind == tok::utf16_char_constant; }
bool isUTF32() const { return Kind == tok::utf32_char_constant; }
bool isMultiChar() const { return IsMultiChar; }
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Thu Jan 7 14:59:26 2016
@@ -1165,6 +1165,7 @@ void StmtPrinter::VisitCharacterLiteral(
switch (Node->getKind()) {
case CharacterLiteral::Ascii: break; // no prefix.
case CharacterLiteral::Wide: OS << 'L'; break;
+ case CharacterLiteral::UTF8: OS << "u8"; break;
case CharacterLiteral::UTF16: OS << 'u'; break;
case CharacterLiteral::UTF32: OS << 'U'; break;
}
Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Thu Jan 7 14:59:26 2016
@@ -983,6 +983,7 @@ NumericLiteralParser::GetFloatValue(llvm
/// u' c-char-sequence '
/// U' c-char-sequence '
/// L' c-char-sequence '
+/// u8' c-char-sequence ' [C++1z lex.ccon]
/// c-char-sequence:
/// c-char
/// c-char-sequence c-char
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jan 7 14:59:26 2016
@@ -3084,6 +3084,8 @@ ExprResult Sema::ActOnCharacterConstant(
Kind = CharacterLiteral::UTF16;
else if (Literal.isUTF32())
Kind = CharacterLiteral::UTF32;
+ else if (Literal.isUTF8())
+ Kind = CharacterLiteral::UTF8;
Expr *Lit = new (Context) CharacterLiteral(Literal.getValue(), Kind, Ty,
Tok.getLocation());
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Jan 7 14:59:26 2016
@@ -319,6 +319,7 @@ ExprResult Sema::BuildObjCNumericLiteral
// to use to determine the Objective-c literal kind.
switch (Char->getKind()) {
case CharacterLiteral::Ascii:
+ case CharacterLiteral::UTF8:
NumberType = Context.CharTy;
break;
@@ -577,6 +578,7 @@ ExprResult Sema::BuildObjCBoxedExpr(Sour
// to use to determine the Objective-c literal kind.
switch (Char->getKind()) {
case CharacterLiteral::Ascii:
+ case CharacterLiteral::UTF8:
ValueType = Context.CharTy;
break;
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Jan 7 14:59:26 2016
@@ -5503,6 +5503,8 @@ Sema::BuildExpressionFromIntegralTemplat
Expr *E;
if (T->isAnyCharacterType()) {
+ // This does not need to handle u8 character literals because those are
+ // of type char, and so can also be covered by an ASCII character literal.
CharacterLiteral::CharacterKind Kind;
if (T->isWideCharType())
Kind = CharacterLiteral::Wide;
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=257097&r1=257096&r2=257097&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Jan 7 14:59:26 2016
@@ -2033,7 +2033,7 @@ void ASTWriter::WriteDeclAbbrevs() {
//Character Literal
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
- Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getKind
+ Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
// Abbreviation for EXPR_IMPLICIT_CAST
Added: cfe/trunk/test/Misc/ast-print-char-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-char-literal.cpp?rev=257097&view=auto
==============================================================================
--- cfe/trunk/test/Misc/ast-print-char-literal.cpp (added)
+++ cfe/trunk/test/Misc/ast-print-char-literal.cpp Thu Jan 7 14:59:26 2016
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -ast-print -std=c++1z %s -o - | FileCheck %s
+
+char c = u8'1';
+char d = '1';
+char e = U'1';
+char f = L'1';
+char g = u'1';
+
+template <char c = u8'1'>
+void h();
+
+void i() {
+ h<u8'2'>();
+}
+
+// CHECK: char c = u8'1';
+// CHECK-NEXT: char d = '1';
+// CHECK-NEXT: char e = U'1';
+// CHECK-NEXT: char f = L'1';
+// CHECK-NEXT: char g = u'1';
+
+// CHECK: template <char c = u8'1'>
+
+// CHECK: h<u8'2'>();
Added: cfe/trunk/test/PCH/cxx-char-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-char-literal.cpp?rev=257097&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-char-literal.cpp (added)
+++ cfe/trunk/test/PCH/cxx-char-literal.cpp Thu Jan 7 14:59:26 2016
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t %s
+// RUN: %clang_cc1 -std=c++1z -x ast -ast-print %t | FileCheck %s
+
+// Ensure that character literals are properly surfaced through PCH.
+
+char a = '0';
+// CHECK: char a = '0';
+
+char b = L'1';
+// CHECK: char b = L'1';
+
+char c = u8'2';
+// CHECK: char c = u8'2';
+
+char d = U'3';
+// CHECK: char d = U'3';
+
+char e = u'4';
+// CHECK: char e = u'4';
More information about the cfe-commits
mailing list