From e6a56db2e62eeaa62ec6cfaa099298ba3356b9fd Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Nov 2012 05:41:51 +0000 Subject: [PATCH] Reject uses of __int128 on platforms that don't support it. Also move the ugly 'getPointerWidth(0) >= 64' test to be a method on TargetInfo, ready to be properly cleaned up. llvm-svn: 168856 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/include/clang/Basic/TargetInfo.h | 3 +++ clang/lib/Frontend/InitPreprocessor.cpp | 2 ++ clang/lib/Sema/Sema.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 8 ++++++-- clang/lib/Sema/SemaType.cpp | 2 ++ clang/test/Sema/128bitint.c | 14 +++++++++++++- clang/test/SemaCXX/overloaded-builtin-operators.cpp | 2 +- 8 files changed, 30 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 0ee99f5..46a3bbc 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 4a12381..2e59ad5 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -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; } diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 4bbd033..7da7353 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -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); diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 13a33b7..f9666f4 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -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"); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 66beb34..dd1bc0b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -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 diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 4b23167..17a6922 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -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 diff --git a/clang/test/Sema/128bitint.c b/clang/test/Sema/128bitint.c index 600c25a..bb8e3d1 100644 --- a/clang/test/Sema/128bitint.c +++ b/clang/test/Sema/128bitint.c @@ -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 diff --git a/clang/test/SemaCXX/overloaded-builtin-operators.cpp b/clang/test/SemaCXX/overloaded-builtin-operators.cpp index 19dc338..fed84de 100644 --- a/clang/test/SemaCXX/overloaded-builtin-operators.cpp +++ b/clang/test/SemaCXX/overloaded-builtin-operators.cpp @@ -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; -- 2.7.4