r211434 - Revert "Lex: Use the correct types for MS integer suffixes"

Rafael Espindola rafael.espindola at gmail.com
Sat Jun 21 05:39:25 PDT 2014


Author: rafael
Date: Sat Jun 21 07:39:25 2014
New Revision: 211434

URL: http://llvm.org/viewvc/llvm-project?rev=211434&view=rev
Log:
Revert "Lex: Use the correct types for MS integer suffixes"

This reverts commit r211426.

This broke the arm bots. The crash can be reproduced on X86 by running.
./bin/clang -cc1  -fsyntax-only -verify -fms-extensions ~/llvm/clang/test/Lexer/ms-extensions.c -triple arm-linux

Removed:
    cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp
Modified:
    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/unittests/AST/StmtPrinterTest.cpp

Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=211434&r1=211433&r2=211434&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Sat Jun 21 07:39:25 2014
@@ -63,7 +63,7 @@ public:
   bool isLongLong;
   bool isFloat;       // 1.0f
   bool isImaginary;   // 1.0i
-  uint8_t MicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.
+  bool isMicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.
 
   bool isIntegerLiteral() const {
     return !saw_period && !saw_exponent;

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211434&r1=211433&r2=211434&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat Jun 21 07:39:25 2014
@@ -947,10 +947,8 @@ void StmtPrinter::VisitIntegerLiteral(In
   // FIXME: The Short and UShort cases are to handle cases where a short
   // integeral literal is formed during template instantiation.  They should
   // be removed when template instantiation no longer needs integer literals.
-  case BuiltinType::SChar:     OS << "i8"; break;
-  case BuiltinType::UChar:     OS << "Ui8"; break;
-  case BuiltinType::Short:     OS << "i16"; break;
-  case BuiltinType::UShort:    OS << "Ui16"; break;
+  case BuiltinType::Short:
+  case BuiltinType::UShort:
   case BuiltinType::Int:       break; // no suffix.
   case BuiltinType::UInt:      OS << 'U'; break;
   case BuiltinType::Long:      OS << 'L'; break;

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=211434&r1=211433&r2=211434&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Sat Jun 21 07:39:25 2014
@@ -522,7 +522,7 @@ NumericLiteralParser::NumericLiteralPars
   isLongLong = false;
   isFloat = false;
   isImaginary = false;
-  MicrosoftInteger = 0;
+  isMicrosoftInteger = false;
   hadError = false;
 
   if (*s == '0') { // parse radix
@@ -606,8 +606,7 @@ NumericLiteralParser::NumericLiteralPars
     case 'i':
     case 'I':
       if (PP.getLangOpts().MicrosoftExt) {
-        if (isLong || isLongLong || MicrosoftInteger)
-          break;
+        if (isLong || isLongLong) break;
 
         // Allow i8, i16, i32, i64, and i128.
         if (s + 1 != ThisTokEnd) {
@@ -615,20 +614,20 @@ NumericLiteralParser::NumericLiteralPars
             case '8':
               if (isFPConstant) break;
               s += 2; // i8 suffix
-              MicrosoftInteger = 8;
+              isMicrosoftInteger = true;
               break;
             case '1':
               if (isFPConstant) break;
               if (s + 2 == ThisTokEnd) break;
               if (s[2] == '6') {
                 s += 3; // i16 suffix
-                MicrosoftInteger = 16;
+                isMicrosoftInteger = true;
               }
               else if (s[2] == '2') {
                 if (s + 3 == ThisTokEnd) break;
                 if (s[3] == '8') {
                   s += 4; // i128 suffix
-                  MicrosoftInteger = 128;
+                  isMicrosoftInteger = true;
                 }
               }
               break;
@@ -637,7 +636,8 @@ NumericLiteralParser::NumericLiteralPars
               if (s + 2 == ThisTokEnd) break;
               if (s[2] == '2') {
                 s += 3; // i32 suffix
-                MicrosoftInteger = 32;
+                isLong = true;
+                isMicrosoftInteger = true;
               }
               break;
             case '6':
@@ -645,13 +645,14 @@ NumericLiteralParser::NumericLiteralPars
               if (s + 2 == ThisTokEnd) break;
               if (s[2] == '4') {
                 s += 3; // i64 suffix
-                MicrosoftInteger = 64;
+                isLongLong = true;
+                isMicrosoftInteger = true;
               }
               break;
             default:
               break;
           }
-          if (MicrosoftInteger)
+          if (isMicrosoftInteger)
             break;
         }
       }
@@ -681,7 +682,7 @@ NumericLiteralParser::NumericLiteralPars
       isLongLong = false;
       isFloat = false;
       isImaginary = false;
-      MicrosoftInteger = 0;
+      isMicrosoftInteger = false;
 
       saw_ud_suffix = true;
       return;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=211434&r1=211433&r2=211434&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Jun 21 07:39:25 2014
@@ -3190,7 +3190,7 @@ ExprResult Sema::ActOnNumericConstant(co
     // may be wider than [u]intmax_t.
     // FIXME: Actually, they don't. We seem to have accidentally invented the
     //        i128 suffix.
-    if (Literal.MicrosoftInteger && MaxWidth < 128 &&
+    if (Literal.isMicrosoftInteger && MaxWidth < 128 &&
         Context.getTargetInfo().hasInt128Type())
       MaxWidth = 128;
     llvm::APInt ResultVal(MaxWidth, 0);
@@ -3211,18 +3211,7 @@ ExprResult Sema::ActOnNumericConstant(co
 
       // Check from smallest to largest, picking the smallest type we can.
       unsigned Width = 0;
-
-      // Microsoft specific integer suffixes are explicitly sized.
-      if (Literal.MicrosoftInteger) {
-        Width = Literal.MicrosoftInteger;
-        if (Width < 128)
-          Ty = Context.getIntTypeForBitwidth(Width,
-                                             /*Signed=*/!Literal.isUnsigned);
-        else
-          Ty = Literal.isUnsigned ? Context.UnsignedInt128Ty : Context.Int128Ty;
-      }
-
-      if (Ty.isNull() && !Literal.isLong && !Literal.isLongLong) {
+      if (!Literal.isLong && !Literal.isLongLong) {
         // Are int/unsigned possibilities?
         unsigned IntSize = Context.getTargetInfo().getIntWidth();
 
@@ -3269,6 +3258,17 @@ ExprResult Sema::ActOnNumericConstant(co
           Width = LongLongSize;
         }
       }
+        
+      // If it doesn't fit in unsigned long long, and we're using Microsoft
+      // extensions, then its a 128-bit integer literal.
+      if (Ty.isNull() && Literal.isMicrosoftInteger &&
+          Context.getTargetInfo().hasInt128Type()) {
+        if (Literal.isUnsigned)
+          Ty = Context.UnsignedInt128Ty;
+        else
+          Ty = Context.Int128Ty;
+        Width = 128;
+      }
 
       // If we still couldn't decide a type, we probably have something that
       // does not fit in a signed long long, but has no U suffix.

Removed: cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp?rev=211433&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp (removed)
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-compatibility -verify %s
-// expected-no-diagnostics
-
-static_assert(sizeof(0i8  ) == sizeof(__INT8_TYPE__ ), "");
-static_assert(sizeof(0i16 ) == sizeof(__INT16_TYPE__), "");
-static_assert(sizeof(0i32 ) == sizeof(__INT32_TYPE__), "");
-static_assert(sizeof(0i64 ) == sizeof(__INT64_TYPE__), "");
-static_assert(sizeof(0i128) >  sizeof(__INT64_TYPE__), "");

Modified: cfe/trunk/unittests/AST/StmtPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/StmtPrinterTest.cpp?rev=211434&r1=211433&r2=211434&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/StmtPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/StmtPrinterTest.cpp Sat Jun 21 07:39:25 2014
@@ -134,8 +134,6 @@ PrintedStmtCXX11Matches(StringRef Code,
                                               StringRef ContainingFunction,
                                               StringRef ExpectedPrinted) {
   std::vector<std::string> Args;
-  Args.push_back("-target");
-  Args.push_back("i686-pc-win32");
   Args.push_back("-std=c++98");
   Args.push_back("-fms-extensions");
   Args.push_back("-Wno-unused-value");
@@ -171,9 +169,9 @@ TEST(StmtPrinter, TestMSIntegerLiteral)
     "  1i64, -1i64, 1ui64;"
     "}",
     "A",
-    "1i8 , -1i8 , 1Ui8 , "
-    "1i16 , -1i16 , 1Ui16 , "
     "1 , -1 , 1U , "
+    "1 , -1 , 1U , "
+    "1L , -1L , 1UL , "
     "1LL , -1LL , 1ULL"));
     // Should be: with semicolon
 }





More information about the cfe-commits mailing list