diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 94e97a891baed..2c87d8eb2a5ae 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3146,6 +3146,8 @@ def err_attribute_bad_neon_vector_size : Error< "Neon vector size must be 64 or 128 bits">; def err_attribute_invalid_sve_type : Error< "%0 attribute applied to non-SVE type %1">; +def err_attribute_x86_feature_gro_vector_size_unsupported : Error< + "vector_size is not supported when '-mgeneral-regs-only' is specified on x86">; def err_attribute_bad_sve_vector_size : Error< "invalid SVE vector size '%0', must match value set by " "'-msve-vector-bits' ('%1')">; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 83610503ed9b1..0a24c9325dfa6 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -8251,6 +8251,25 @@ static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr, return; } + // check -mgeneral-regs-only is specified + const TargetInfo &targetInfo = S.getASTContext().getTargetInfo(); + llvm::Triple::ArchType arch = targetInfo.getTriple().getArch(); + const auto HasFeature = [](const clang::TargetOptions &targetOpts, + const std::string &feature) { + return std::find(targetOpts.Features.begin(), targetOpts.Features.end(), + feature) != targetOpts.Features.end(); + }; + if (CurType->isSpecificBuiltinType(BuiltinType::LongDouble)) { + if (arch == llvm::Triple::x86_64 && + HasFeature(targetInfo.getTargetOpts(), "-x87") && + HasFeature(targetInfo.getTargetOpts(), "-mmx") && + HasFeature(targetInfo.getTargetOpts(), "-sse")) { + S.Diag(Attr.getLoc(), + diag::err_attribute_x86_feature_gro_vector_size_unsupported); + Attr.setInvalid(); + return; + } + } Expr *SizeExpr = Attr.getArgAsExpr(0); QualType T = S.BuildVectorType(CurType, SizeExpr, Attr.getLoc()); if (!T.isNull())