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
This commit is contained in:
Richard Smith 2012-11-29 05:41:51 +00:00
parent 6be9b25cb6
commit e6a56db2e6
8 changed files with 30 additions and 5 deletions

View 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">;

View 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; }

View 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);

View 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");

View 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

View 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

View 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

View 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;