]> granicus.if.org Git - clang/commitdiff
Reject uses of __int128 on platforms that don't support it. Also move the ugly
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 29 Nov 2012 05:41:51 +0000 (05:41 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 29 Nov 2012 05:41:51 +0000 (05:41 +0000)
'getPointerWidth(0) >= 64' test to be a method on TargetInfo, ready to be
properly cleaned up.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168856 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Basic/TargetInfo.h
lib/Frontend/InitPreprocessor.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaType.cpp
test/Sema/128bitint.c
test/SemaCXX/overloaded-builtin-operators.cpp

index 0ee99f5cedf9d06aa991e9b57944843a2c694c0f..46a3bbc987bc77598af98f28979e0a5d031745af 100644 (file)
@@ -5869,6 +5869,8 @@ def err_c99_array_usage_cxx : Error<
   "feature, not permitted in C++">;
 def err_double_requires_fp64 : Error<
   "use of type 'double' requires cl_khr_fp64 extension to be enabled">;
+def err_int128_unsupported : Error<
+  "__int128 is not supported on this target">;
 def err_nsconsumed_attribute_mismatch : Error<
   "overriding method has mismatched ns_consumed attribute on its"
   " parameter">;
index 4a12381e273e22f7f86690299393aa747a58911d..2e59ad52d8683e1af154a32de9cddbf1dd562bae 100644 (file)
@@ -270,6 +270,9 @@ public:
   unsigned getLongLongWidth() const { return LongLongWidth; }
   unsigned getLongLongAlign() const { return LongLongAlign; }
 
+  /// \brief Determine whether the __int128 type is supported on this target.
+  bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // FIXME
+
   /// \brief Return the alignment that is suitable for storing any
   /// object with a fundamental alignment requirement.
   unsigned getSuitableAlign() const { return SuitableAlign; }
index 4bbd033f1c2e3162c468044e92c8774be2c4d435..7da73532782952dc76443179ce3246377e7e98ff 100644 (file)
@@ -507,6 +507,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
                    TI.getTypeWidth(TI.getWCharType()), TI, Builder);
   DefineTypeSizeof("__SIZEOF_WINT_T__",
                    TI.getTypeWidth(TI.getWIntType()), TI, Builder);
+  if (TI.hasInt128Type())
+    DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
 
   DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
   DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
index 13a33b785b437f8e5057321aee80e15566b33c6e..f9666f4832c9b624807e321fea412e6698108621 100644 (file)
@@ -128,7 +128,7 @@ void Sema::Initialize() {
     ExternalSema->InitializeSema(*this);
 
   // Initialize predefined 128-bit integer types, if needed.
-  if (PP.getTargetInfo().getPointerWidth(0) >= 64) {
+  if (PP.getTargetInfo().hasInt128Type()) {
     // If either of the 128-bit integer types are unavailable to name lookup,
     // define them now.
     DeclarationName Int128 = &Context.Idents.get("__int128_t");
index 66beb34128ef94ca8df7eebf46fd389d988aa7d8..dd1bc0b6577b1abdeab827f44b6e1234465280f5 100644 (file)
@@ -2841,7 +2841,10 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
     unsigned MaxWidth = Context.getTargetInfo().getIntMaxTWidth();
     // The microsoft literal suffix extensions support 128-bit literals, which
     // may be wider than [u]intmax_t.
-    if (Literal.isMicrosoftInteger && MaxWidth < 128)
+    // FIXME: Actually, they don't. We seem to have accidentally invented the
+    //        i128 suffix.
+    if (Literal.isMicrosoftInteger && MaxWidth < 128 &&
+        PP.getTargetInfo().hasInt128Type())
       MaxWidth = 128;
     llvm::APInt ResultVal(MaxWidth, 0);
 
@@ -2911,7 +2914,8 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
         
       // 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) {
+      if (Ty.isNull() && Literal.isMicrosoftInteger &&
+          PP.getTargetInfo().hasInt128Type()) {
         if (Literal.isUnsigned)
           Ty = Context.UnsignedInt128Ty;
         else
index 4b23167951aa13cd55bbe5591c58cde9a7d74a4d..17a6922190ac6659b74b7e72be97330a3de5536d 100644 (file)
@@ -742,6 +742,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
     break;
   }
   case DeclSpec::TST_int128:
+    if (!S.PP.getTargetInfo().hasInt128Type())
+      S.Diag(DS.getTypeSpecTypeLoc(), diag::err_int128_unsupported);
     if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned)
       Result = Context.UnsignedInt128Ty;
     else
index 600c25a630c2418cc6ccb665c8f8e1fee69d4449..bb8e3d155e572f2887b5af9ddf9797ab6e70c5eb 100644 (file)
@@ -1,9 +1,13 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 -fms-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 -fms-extensions %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -fms-extensions %s -DHAVE_NOT
+
+#ifdef HAVE
 typedef int i128 __attribute__((__mode__(TI)));
 typedef unsigned u128 __attribute__((__mode__(TI)));
 
 int a[((i128)-1 ^ (i128)-2) == 1 ? 1 : -1];
 int a[(u128)-1 > 1LL ? 1 : -1];
+int a[__SIZEOF_INT128__ == 16 ? 1 : -1];
 
 // PR5435
 __uint128_t b = (__uint128_t)-1;
@@ -36,4 +40,12 @@ void test(int *buf)
 {
   MPI_Send(buf, 0x10000000000000001i128); // expected-warning {{implicit conversion from '__int128' to 'int' changes value}}
 }
+#else
+
+__int128 n; // expected-error {{__int128 is not supported on this target}}
+
+#if defined(__SIZEOF_INT128__)
+#error __SIZEOF_INT128__ should not be defined
+#endif
 
+#endif
index 19dc338716301cc6b6688cf0795fe2c17fb971b9..fed84de360488992e1ea52f3c2f4079985a1e956 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify %s 
+// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu %s
 // REQUIRES: LP64
 
 struct yes;