r231494 - Sema: The i8 suffix should yield a literal of type char

David Majnemer david.majnemer at gmail.com
Fri Mar 6 10:04:22 PST 2015


Author: majnemer
Date: Fri Mar  6 12:04:22 2015
New Revision: 231494

URL: http://llvm.org/viewvc/llvm-project?rev=231494&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=231494&r1=231493&r2=231494&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Mar  6 12:04:22 2015
@@ -1069,7 +1069,8 @@ void StmtPrinter::VisitIntegerLiteral(In
   // Emit suffixes.  Integer literals are always a builtin integer type.
   switch (Node->getType()->getAs<BuiltinType>()->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;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=231494&r1=231493&r2=231494&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar  6 12:04:22 2015
@@ -3324,6 +3324,9 @@ ExprResult Sema::ActOnNumericConstant(co
           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,

Modified: cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp?rev=231494&r1=231493&r2=231494&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp Fri Mar  6 12:04:22 2015
@@ -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__, "");





More information about the cfe-commits mailing list