diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index ab479540407194..910a4d6846aaac 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -547,6 +547,12 @@ class TargetInfo : public virtual TransferrableTargetInfo, return (getPointerWidth(0) >= 64) || getTargetOpts().ForceEnableInt128; } // FIXME + /// Determine whether the _ExtInt type is supported on this target. This + /// limitation is put into place for ABI reasons. + virtual bool hasExtIntType() const { + return false; + } + /// Determine whether _Float16 is supported on this target. virtual bool hasLegalHalfType() const { return HasLegalHalfType; } diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index a68109a604d598..39ccac96a49d8a 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -435,6 +435,8 @@ class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo { } ArrayRef getTargetBuiltins() const override; + + bool hasExtIntType() const override { return true; } }; class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo @@ -737,6 +739,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } ArrayRef getTargetBuiltins() const override; + + bool hasExtIntType() const override { return true; } }; // x86-64 Windows target diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index a96e1c1e657237..338e33589b1d96 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1443,6 +1443,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { break; } case DeclSpec::TST_extint: { + if (!S.Context.getTargetInfo().hasExtIntType()) + S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) + << "_ExtInt"; Result = S.BuildExtIntType(DS.getTypeSpecSign() == TSS_unsigned, DS.getRepAsExpr(), DS.getBeginLoc()); if (Result.isNull()) { diff --git a/clang/test/Sema/ext-int-not-supported.c b/clang/test/Sema/ext-int-not-supported.c new file mode 100644 index 00000000000000..23610b9941e4cd --- /dev/null +++ b/clang/test/Sema/ext-int-not-supported.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify %s + +void foo() { + _ExtInt(33) a; // expected-error{{_ExtInt is not supported on this target}} +}