r283227 - [MS] Move hex long long sign compat hack to -fms-compatibility

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 4 08:57:50 PDT 2016


Author: rnk
Date: Tue Oct  4 10:57:49 2016
New Revision: 283227

URL: http://llvm.org/viewvc/llvm-project?rev=283227&view=rev
Log:
[MS] Move hex long long sign compat hack to -fms-compatibility

Treating large 0x*LL literals as signed instead of unsigned is not a
conforming language extension, so move it out of -fms-extensions.

Came up in PR30605

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
    cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=283227&r1=283226&r2=283227&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct  4 10:57:49 2016
@@ -3518,7 +3518,7 @@ ExprResult Sema::ActOnNumericConstant(co
           // To be compatible with MSVC, hex integer literals ending with the
           // LL or i64 suffix are always signed in Microsoft mode.
           if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
-              (getLangOpts().MicrosoftExt && Literal.isLongLong)))
+              (getLangOpts().MSVCCompat && Literal.isLongLong)))
             Ty = Context.LongLongTy;
           else if (AllowUnsigned)
             Ty = Context.UnsignedLongLongTy;

Modified: cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp?rev=283227&r1=283226&r2=283227&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp Tue Oct  4 10:57:49 2016
@@ -242,3 +242,14 @@ namespace IntToNullPtrConv {
   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
 }
+
+namespace signed_hex_i64 {
+void f(long long);
+void f(int);
+void g() {
+  // This is an ambiguous call in standard C++.
+  // This calls f(long long) in Microsoft mode because LL is always signed.
+  f(0xffffffffffffffffLL);
+  f(0xffffffffffffffffi64);
+}
+}

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=283227&r1=283226&r2=283227&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Tue Oct  4 10:57:49 2016
@@ -158,19 +158,16 @@ void m1() {
 }
 
 
-
-
-
-void f(long long);
-void f(int);
-
-int main()
-{
-  // This is an ambiguous call in standard C++.
-  // This calls f(long long) in Microsoft mode because LL is always signed.
-  f(0xffffffffffffffffLL);
+namespace signed_hex_i64 {
+void f(long long); // expected-note {{candidate function}}
+void f(int); // expected-note {{candidate function}}
+void g() {
+  // This used to be controlled by -fms-extensions, but it is now under
+  // -fms-compatibility.
+  f(0xffffffffffffffffLL); // expected-error {{call to 'f' is ambiguous}}
   f(0xffffffffffffffffi64);
 }
+}
 
 // Enumeration types with a fixed underlying type.
 const int seventeen = 17;




More information about the cfe-commits mailing list