<div dir="ltr">Thanks for the revert, it was an older version of the code I intended for submission which didn't properly work on 32-bit targets.<div><br></div><div>It should be rectified with r211441.</div>







</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jun 21, 2014 at 5:48 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sorry, I reverted this since it broke the arm bots.<br>
<br>
You can reproduce the crash with<br>
<br>
./bin/clang -cc1  -fsyntax-only -verify -fms-extensions<br>
~/llvm/clang/test/Lexer/ms-extensions.c -triple arm-linux<br>
<div class="HOEnZb"><div class="h5"><br>
On 20 June 2014 20:52, David Majnemer <<a href="mailto:david.majnemer@gmail.com">david.majnemer@gmail.com</a>> wrote:<br>
> Author: majnemer<br>
> Date: Fri Jun 20 19:51:59 2014<br>
> New Revision: 211426<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211426&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=211426&view=rev</a><br>
> Log:<br>
> Lex: Use the correct types for MS integer suffixes<br>
><br>
> We didn't properly implement support for the sized integer suffixes.<br>
> Suffixes like i16 were essentially ignored instead of mapping them to<br>
> the appropriately sized integer type.<br>
><br>
> This fixes PR20008.<br>
><br>
> Differential Revision: <a href="http://reviews.llvm.org/D4132" target="_blank">http://reviews.llvm.org/D4132</a><br>
><br>
> Added:<br>
>     cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp<br>
> Modified:<br>
>     cfe/trunk/include/clang/Lex/LiteralSupport.h<br>
>     cfe/trunk/lib/AST/StmtPrinter.cpp<br>
>     cfe/trunk/lib/Lex/LiteralSupport.cpp<br>
>     cfe/trunk/lib/Sema/SemaExpr.cpp<br>
>     cfe/trunk/unittests/AST/StmtPrinterTest.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=211426&r1=211425&r2=211426&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=211426&r1=211425&r2=211426&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/LiteralSupport.h Fri Jun 20 19:51:59 2014<br>
> @@ -63,7 +63,7 @@ public:<br>
>    bool isLongLong;<br>
>    bool isFloat;       // 1.0f<br>
>    bool isImaginary;   // 1.0i<br>
> -  bool isMicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.<br>
> +  uint8_t MicrosoftInteger;  // Microsoft suffix extension i8, i16, i32, or i64.<br>
><br>
>    bool isIntegerLiteral() const {<br>
>      return !saw_period && !saw_exponent;<br>
><br>
> Modified: cfe/trunk/lib/AST/StmtPrinter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211426&r1=211425&r2=211426&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211426&r1=211425&r2=211426&view=diff</a><br>

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

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

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

> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp (added)<br>
> +++ cfe/trunk/test/SemaCXX/ms_integer_suffix.cpp Fri Jun 20 19:51:59 2014<br>
> @@ -0,0 +1,8 @@<br>
> +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-compatibility -verify %s<br>
> +// expected-no-diagnostics<br>
> +<br>
> +static_assert(sizeof(0i8  ) == sizeof(__INT8_TYPE__ ), "");<br>
> +static_assert(sizeof(0i16 ) == sizeof(__INT16_TYPE__), "");<br>
> +static_assert(sizeof(0i32 ) == sizeof(__INT32_TYPE__), "");<br>
> +static_assert(sizeof(0i64 ) == sizeof(__INT64_TYPE__), "");<br>
> +static_assert(sizeof(0i128) >  sizeof(__INT64_TYPE__), "");<br>
><br>
> Modified: cfe/trunk/unittests/AST/StmtPrinterTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/StmtPrinterTest.cpp?rev=211426&r1=211425&r2=211426&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/StmtPrinterTest.cpp?rev=211426&r1=211425&r2=211426&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/unittests/AST/StmtPrinterTest.cpp (original)<br>
> +++ cfe/trunk/unittests/AST/StmtPrinterTest.cpp Fri Jun 20 19:51:59 2014<br>
> @@ -134,6 +134,8 @@ PrintedStmtCXX11Matches(StringRef Code,<br>
>                                                StringRef ContainingFunction,<br>
>                                                StringRef ExpectedPrinted) {<br>
>    std::vector<std::string> Args;<br>
> +  Args.push_back("-target");<br>
> +  Args.push_back("i686-pc-win32");<br>
>    Args.push_back("-std=c++98");<br>
>    Args.push_back("-fms-extensions");<br>
>    Args.push_back("-Wno-unused-value");<br>
> @@ -169,9 +171,9 @@ TEST(StmtPrinter, TestMSIntegerLiteral)<br>
>      "  1i64, -1i64, 1ui64;"<br>
>      "}",<br>
>      "A",<br>
> +    "1i8 , -1i8 , 1Ui8 , "<br>
> +    "1i16 , -1i16 , 1Ui16 , "<br>
>      "1 , -1 , 1U , "<br>
> -    "1 , -1 , 1U , "<br>
> -    "1L , -1L , 1UL , "<br>
>      "1LL , -1LL , 1ULL"));<br>
>      // Should be: with semicolon<br>
>  }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>