From be09e8e5cf8495fc81cee39de028d6f62451fc03 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 6 Mar 2015 18:04:22 +0000 Subject: [PATCH] Sema: The i8 suffix should yield a literal of type char We would make i8 literals turn into signed char instead of char. This is incompatible with MSVC. This fixes PR22824. llvm-svn: 231494 --- clang/lib/AST/StmtPrinter.cpp | 3 ++- clang/lib/Sema/SemaExpr.cpp | 3 +++ clang/test/SemaCXX/ms_integer_suffix.cpp | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index d6e0deb..8f0edd0 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -1069,7 +1069,8 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { // Emit suffixes. Integer literals are always a builtin integer type. switch (Node->getType()->getAs()->getKind()) { default: llvm_unreachable("Unexpected type for integer literal!"); - case BuiltinType::SChar: OS << "i8"; break; + case BuiltinType::Char_S: + case BuiltinType::Char_U: OS << "i8"; break; case BuiltinType::UChar: OS << "Ui8"; break; case BuiltinType::Short: OS << "i16"; break; case BuiltinType::UShort: OS << "Ui16"; break; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 84315be..a793d45 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3324,6 +3324,9 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { Diag(Tok.getLocation(), diag::err_int128_unsupported); Width = MaxWidth; Ty = Context.getIntMaxType(); + } else if (Literal.MicrosoftInteger == 8 && !Literal.isUnsigned) { + Width = 8; + Ty = Context.CharTy; } else { Width = Literal.MicrosoftInteger; Ty = Context.getIntTypeForBitwidth(Width, diff --git a/clang/test/SemaCXX/ms_integer_suffix.cpp b/clang/test/SemaCXX/ms_integer_suffix.cpp index 6b4594d..d65e7f4 100644 --- a/clang/test/SemaCXX/ms_integer_suffix.cpp +++ b/clang/test/SemaCXX/ms_integer_suffix.cpp @@ -3,6 +3,11 @@ #ifdef __SIZEOF_INT8__ static_assert(sizeof(0i8) == __SIZEOF_INT8__, ""); + +constexpr int f(char) { return 1; } +constexpr int f(signed char) { return 2; } + +static_assert(f(0i8) == 1, ""); #endif #ifdef __SIZEOF_INT16__ static_assert(sizeof(0i16) == __SIZEOF_INT16__, ""); -- 2.7.4