diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -3799,6 +3799,20 @@ /// because TrailingObjects cannot handle repeated types. struct ExceptionType { QualType Type; }; + /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number + /// of function type attributes that can be set on function types, including + /// function pointers. + enum AArch64SMETypeAttributes : unsigned { + SME_NormalFunction = 0, + SME_PStateSMEnabledMask = 1, + SME_PStateSMCompatibleMask = 2, + SME_PStateZANewMask = 4, + SME_PStateZASharedMask = 8, + SME_PStateZAPreservedMask = 16, + SME_AttributeMask = 255 // We only support maximum 8 bits because of the + // bitmask in FunctionTypeExtraBitfields + }; + /// A simple holder for various uncommon bits which do not fit in /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the /// alignment of subsequent objects in TrailingObjects. @@ -3807,6 +3821,13 @@ /// A whole unsigned is not needed here and according to /// [implimits] 8 bits would be enough here. unsigned NumExceptionType = 0; + + /// Any AArch64 SME ACLE type attributes that need to be propagated + /// on declarations and function pointers. + unsigned AArch64SMEAttributes : 8; + + FunctionTypeExtraBitfields() + : AArch64SMEAttributes(SME_NormalFunction) {} }; protected: @@ -3984,16 +4005,20 @@ FunctionType::ExtInfo ExtInfo; bool Variadic : 1; bool HasTrailingReturn : 1; + unsigned AArch64SMEAttributes : 8; Qualifiers TypeQuals; RefQualifierKind RefQualifier = RQ_None; ExceptionSpecInfo ExceptionSpec; const ExtParameterInfo *ExtParameterInfos = nullptr; SourceLocation EllipsisLoc; - ExtProtoInfo() : Variadic(false), HasTrailingReturn(false) {} + ExtProtoInfo() + : Variadic(false), HasTrailingReturn(false), + AArch64SMEAttributes(SME_NormalFunction) {} ExtProtoInfo(CallingConv CC) - : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {} + : ExtInfo(CC), Variadic(false), HasTrailingReturn(false), + AArch64SMEAttributes(SME_NormalFunction) {} ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI) { ExtProtoInfo Result(*this); @@ -4002,7 +4027,12 @@ } bool requiresFunctionProtoTypeExtraBitfields() const { - return ExceptionSpec.Type == EST_Dynamic; + return ExceptionSpec.Type == EST_Dynamic || + AArch64SMEAttributes != SME_NormalFunction; + } + + void setArmSMEAttribute(AArch64SMETypeAttributes Kind) { + AArch64SMEAttributes |= Kind; } }; @@ -4129,6 +4159,7 @@ EPI.TypeQuals = getMethodQuals(); EPI.RefQualifier = getRefQualifier(); EPI.ExtParameterInfos = getExtParameterInfosOrNull(); + EPI.AArch64SMEAttributes = getAArch64SMEAttributes(); return EPI; } @@ -4311,6 +4342,14 @@ return getTrailingObjects(); } + /// Return a bitmask describing the SME attributes on the function type, see + /// AArch64SMETypeAttributes for their values. + unsigned getAArch64SMEAttributes() const { + if (!hasExtraBitfields()) + return SME_NormalFunction; + return getTrailingObjects()->AArch64SMEAttributes; + } + ExtParameterInfo getExtParameterInfo(unsigned I) const { assert(I < getNumParams() && "parameter index out of range"); if (hasExtParameterInfos()) diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -323,6 +323,9 @@ ? node->getExtParameterInfos() : llvm::ArrayRef() }]; } + def : Property<"AArch64SMEAttributes", UInt32> { + let Read = [{ node->getAArch64SMEAttributes() }]; + } def : Creator<[{ auto extInfo = FunctionType::ExtInfo(noReturn, hasRegParm, regParm, @@ -338,6 +341,7 @@ epi.ExceptionSpec = exceptionSpecifier; epi.ExtParameterInfos = extParameterInfo.empty() ? nullptr : extParameterInfo.data(); + epi.AArch64SMEAttributes = AArch64SMEAttributes; return ctx.getFunctionType(returnType, parameters, epi); }]>; } diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -372,6 +372,9 @@ } def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>; def TargetAArch64 : TargetArch<["aarch64"]>; +def TargetAArch64SME : TargetArch<["aarch64"]> { + let CustomCode = [{ Target.hasFeature("sme") }]; +} def TargetAnyArm : TargetArch; def TargetAVR : TargetArch<["avr"]>; def TargetBPF : TargetArch<["bpfel", "bpfeb"]>; @@ -2319,6 +2322,42 @@ let Documentation = [AArch64VectorPcsDocs]; } +def ArmStreamingCompatible : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_streaming_compatible">]; + let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>; + let Documentation = [ArmSmeStreamingCompatibleDocs]; +} + +def ArmStreaming : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_streaming">]; + let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>; + let Documentation = [ArmSmeStreamingDocs]; +} + +def ArmLocallyStreaming : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_locally_streaming">]; + let Subjects = SubjectList<[Function], ErrorDiag>; + let Documentation = [ArmSmeLocallyStreamingDocs]; +} + +def ArmSharedZA : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_shared_za">]; + let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>; + let Documentation = [ArmSmeSharedZADocs]; +} + +def ArmPreservesZA : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_preserves_za">]; + let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>; + let Documentation = [ArmSmePreservesZADocs]; +} + +def ArmNewZA : DeclOrTypeAttr, TargetSpecificAttr { + let Spellings = [Clang<"arm_new_za">]; + let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>; + let Documentation = [ArmSmeNewZADocs]; +} + def AArch64SVEPcs: DeclOrTypeAttr { let Spellings = [Clang<"aarch64_sve_pcs">]; let Documentation = [AArch64SVEPcsDocs]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -6208,6 +6208,89 @@ }]; } +def ArmSmeStreamingDocs : Documentation { + let Category = DocCatType; + let Content = [{ +The ``arm_streaming`` attribute is defined by the Arm C Language Extensions +(ACLE) for SME. It is used to mark a function as being a streaming function for +which ``PSTATE.SM`` must be ``1`` on entry and on exit of the function. + +By adding this attribute, Clang will insert the appropriate ``smstart`` and +``smstop`` instructions before and after the call to guarantee that these +conditions are satisfied. + }]; +} + +def ArmSmeLocallyStreamingDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``arm_locally_streaming`` attribute is defined by the Arm C Language Extensions +(ACLE) for SME. It is used to mark a function's body (not the interface) as requiring +``PSTATE.SM`` to be ``1``, although the function is expected to be called with +``PSTATE.SM=0`` and return with ``PSTATE.SM`` unchanged. + +By adding this attribute, Clang will insert the appropriate ``smstart`` and +``smstop`` instructions in the prologue and epilogue of the function. + }]; +} + +def ArmSmeStreamingCompatibleDocs : Documentation { + let Category = DocCatType; + let Content = [{ +The ``arm_streaming_compatible`` attribute is defined by the Arm C Language +Extensions (ACLE) for SME. It is used to mark a function as being a streaming +compatible function for which ``PSTATE.SM`` can either be ``0`` or ``1`` at +runtime. Additionally, the ABI specifies that the value of ``PSTATE.SM`` is +passed in register ``X0``. + +By adding this attribute, Clang will pass an implicit parameter with the value +of ``PSTATE.SM`` in ``X0`` to streaming-compatible functions and will insert the +appropriate ``smstart`` and ``smstop`` instructions when there are calls to +other functions that are not streaming compatible. + +Clang will also avoid generating instructions that are illegal in either +streaming mode or normal mode. + }]; +} + +def ArmSmeSharedZADocs : Documentation { + let Category = DocCatType; + let Content = [{ +The ``arm_shared_za`` attribute is defined by the Arm C Language Extensions +(ACLE) for SME. It is used to mark a function as sharing the state of ZA, the +acculator array, with that of it's callers. + +By adding this attribute, callers of this function will know that the contents +of ZA may be used for passing or returning data, and can be modified. Clang may +assume that ``PSTATE.ZA`` is ``1`` and will avoid setting up a lazy-save +mechanism for calls to functions marked as ``arm_shared_za``. + }]; +} + +def ArmSmeNewZADocs : Documentation { + let Category = DocCatType; + let Content = [{ +The ``arm_new_za`` attribute is defined by the Arm C Language Extensions (ACLE) +for SME. It is used to mark a function as a private ZA function that requires a +new state for ZA. + +By adding this attribute, Clang emits the appropriate ``smstart`` instruction to +allow the use of ZA and will additionally commit a lazy-save if the state of ZA +is dormant. It also emits the appropriate ``smstop`` in the function's epilogue. + }]; +} + +def ArmSmePreservesZADocs : Documentation { + let Category = DocCatType; + let Content = [{ +The ``arm_preserves_za`` attribute is defined by the Arm C Language Extensions +(ACLE) for SME. If a function is marked as ``arm_preserves_za``, it is a hint to +the compiler that the function and any of it's callees will preserve the state +of ZA. + }]; +} + + def ArmMveStrictPolymorphismDocs : Documentation { let Category = DocCatType; let Content = [{ diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3230,6 +3230,12 @@ argSlot[i] = params[i]; } + // Propagate the SME ACLE attributes. + if (epi.AArch64SMEAttributes != SME_NormalFunction) { + auto &ExtraBits = *getTrailingObjects(); + ExtraBits.AArch64SMEAttributes = epi.AArch64SMEAttributes; + } + // Fill in the exception type array if present. if (getExceptionSpecType() == EST_Dynamic) { auto &ExtraBits = *getTrailingObjects(); @@ -3423,6 +3429,8 @@ for (unsigned i = 0; i != NumParams; ++i) ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue()); } + ID.AddInteger(epi.AArch64SMEAttributes); + epi.ExtInfo.Profile(ID); ID.AddBoolean(epi.HasTrailingReturn); } diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -898,6 +898,24 @@ FunctionType::ExtInfo Info = T->getExtInfo(); + if ((T->getAArch64SMEAttributes() & + FunctionType::SME_PStateSMCompatibleMask) && + !InsideCCAttribute) + OS << " __attribute__((arm_streaming_compatible))"; + if ((T->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask) && + !InsideCCAttribute) + OS << " __attribute__((arm_streaming))"; + if ((T->getAArch64SMEAttributes() & FunctionType::SME_PStateZANewMask) && + !InsideCCAttribute) + OS << " __attribute__((arm_new_za))"; + if ((T->getAArch64SMEAttributes() & FunctionType::SME_PStateZASharedMask) && + !InsideCCAttribute) + OS << " __attribute__((arm_shared_za))"; + if ((T->getAArch64SMEAttributes() & + FunctionType::SME_PStateZAPreservedMask) && + !InsideCCAttribute) + OS << " __attribute__((arm_preserves_za))"; + printFunctionAfter(Info, OS); if (!T->getMethodQuals().empty()) @@ -1756,6 +1774,12 @@ break; } case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break; + case attr::ArmStreaming: OS << "arm_streaming"; break; + case attr::ArmStreamingCompatible: OS << "arm_streaming_compatible"; break; + case attr::ArmLocallyStreaming: OS << "arm_locally_streaming"; break; + case attr::ArmNewZA: OS << "arm_new_za"; break; + case attr::ArmPreservesZA: OS << "arm_preserves_za"; break; + case attr::ArmSharedZA: OS << "arm_shared_za"; break; case attr::AArch64SVEPcs: OS << "aarch64_sve_pcs"; break; case attr::AMDGPUKernelCall: OS << "amdgpu_kernel"; break; case attr::IntelOclBicc: OS << "inteloclbicc"; break; diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -54,6 +54,7 @@ bool HasLSE; bool HasFlagM; bool HasMOPS; + bool HasSME; llvm::AArch64::ArchKind ArchKind; diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -513,6 +513,7 @@ .Cases("aarch64", "arm64", "arm", true) .Case("neon", FPU & NeonMode) .Cases("sve", "sve2", "sve2-bitperm", "sve2-aes", "sve2-sha3", "sve2-sm4", "f64mm", "f32mm", "i8mm", "bf16", FPU & SveMode) + .Case("sme", HasSME) .Case("ls64", HasLS64) .Default(false); } @@ -544,12 +545,18 @@ HasMatmulFP32 = false; HasLSE = false; HasMOPS = false; + HasSME = false; ArchKind = llvm::AArch64::ArchKind::INVALID; for (const auto &Feature : Features) { if (Feature == "+neon") FPU |= NeonMode; + if (Feature == "+sme") { + HasSME = true; + HasBFloat16 = true; + HasFullFP16 = true; + } if (Feature == "+sve") { FPU |= SveMode; HasFullFP16 = true; diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1763,6 +1763,17 @@ if (!isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) && FPT->isNothrow()) FuncAttrs.addAttribute(llvm::Attribute::NoUnwind); + + if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateSMEnabledMask) + FuncAttrs.addAttribute("aarch64_pstate_sm_enabled"); + if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateSMCompatibleMask) + FuncAttrs.addAttribute("aarch64_pstate_sm_compatible"); + if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateZANewMask) + FuncAttrs.addAttribute("aarch64_pstate_za_new"); + if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateZASharedMask) + FuncAttrs.addAttribute("aarch64_pstate_za_shared"); + if (FPT->getAArch64SMEAttributes() & FunctionType::SME_PStateZAPreservedMask) + FuncAttrs.addAttribute("aarch64_pstate_za_preserved"); } static void AddAttributesFromAssumes(llvm::AttrBuilder &FuncAttrs, @@ -2186,6 +2197,24 @@ llvm::toStringRef(CodeGenOpts.UniformWGSize)); } } + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_sm_enabled"); + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_sm_body"); + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_sm_compatible"); + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_za_shared"); + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_za_preserved"); + + if (TargetDecl->hasAttr()) + FuncAttrs.addAttribute("aarch64_pstate_za_new"); } // Attach "no-builtins" attributes to: diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1919,6 +1919,12 @@ return; } + // We only need to handle the 'arm_locally_streaming' attribute as a + // special case here (as opposed to e.g. 'arm_streaming'), because it + // is not set from the prototype, but rather from the definition. + if (D->hasAttr()) + B.addAttribute("aarch64_pstate_sm_body"); + // Track whether we need to add the optnone LLVM attribute, // starting with the default for this optimization level. bool ShouldAddOptNone = diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -274,6 +274,7 @@ if (const auto *A = D->getAttr()) { S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << A; S.Diag(A->getLocation(), diag::note_conflicting_attribute); + AL.setInvalid(); return true; } return false; @@ -8086,6 +8087,46 @@ handleSimpleAttribute(S, D, A); } +static void handleSMEAttrs(Sema &S, Decl *D, const ParsedAttr &A) { + // Handle mutually exclusive SME function attributes: + // - arm_streaming & arm_streaming_compatible + // - arm_new_za & arm_preserves_za + // - arm_new_za & arm_shared_za + switch (A.getKind()) { + case ParsedAttr::AT_ArmStreaming: + if (checkAttrMutualExclusion(S, D, A)) + return; + handleSimpleAttribute(S, D, A); + break; + case ParsedAttr::AT_ArmStreamingCompatible: + if (checkAttrMutualExclusion(S, D, A)) + return; + handleSimpleAttribute(S, D, A); + break; + case ParsedAttr::AT_ArmLocallyStreaming: + handleSimpleAttribute(S, D, A); + break; + case ParsedAttr::AT_ArmSharedZA: + if (checkAttrMutualExclusion(S, D, A)) + return; + handleSimpleAttribute(S, D, A); + break; + case ParsedAttr::AT_ArmPreservesZA: + if (checkAttrMutualExclusion(S, D, A)) + return; + handleSimpleAttribute(S, D, A); + break; + case ParsedAttr::AT_ArmNewZA: + if (checkAttrMutualExclusion(S, D, A) || + checkAttrMutualExclusion(S, D, A)) + return; + handleSimpleAttribute(S, D, A); + break; + default: + llvm_unreachable("unexpected attribute kind"); + } +} + static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { assert(cast(D)->getStorageDuration() == SD_Automatic && "uninitialized is only valid on automatic duration variables"); @@ -9016,6 +9057,15 @@ handleArmBuiltinAliasAttr(S, D, AL); break; + case ParsedAttr::AT_ArmStreaming: + case ParsedAttr::AT_ArmStreamingCompatible: + case ParsedAttr::AT_ArmLocallyStreaming: + case ParsedAttr::AT_ArmSharedZA: + case ParsedAttr::AT_ArmPreservesZA: + case ParsedAttr::AT_ArmNewZA: + handleSMEAttrs(S, D, AL); + break; + case ParsedAttr::AT_AcquireHandle: handleAcquireHandleAttr(S, D, AL); break; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9181,6 +9181,21 @@ ColonLoc, result, VK, OK); } +// Check that the SME attributes for PSTATE.ZA and PSTATE.SM are compatible. +static bool IsInvalidSMECallConversion(Sema &S, QualType FromType, + QualType ToType) { + if (const auto *ToFn = + dyn_cast(S.Context.getCanonicalType(ToType))) + if (const auto *FromFn = + dyn_cast(S.Context.getCanonicalType(FromType))) + return (ToFn->getAArch64SMEAttributes() & + FunctionType::SME_AttributeMask) != + (FromFn->getAArch64SMEAttributes() & + FunctionType::SME_AttributeMask); + + return false; +} + // Check if we have a conversion between incompatible cmse function pointer // types, that is, a conversion between a function pointer with the // cmse_nonsecure_call attribute and one without. @@ -9339,6 +9354,8 @@ return Sema::IncompatibleFunctionPointer; if (IsInvalidCmseNSCallConversion(S, ltrans, rtrans)) return Sema::IncompatibleFunctionPointer; + if (IsInvalidSMECallConversion(S, ltrans, rtrans)) + return Sema::IncompatibleFunctionPointer; return ConvTy; } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -136,6 +136,11 @@ case ParsedAttr::AT_NoReturn: \ case ParsedAttr::AT_Regparm: \ case ParsedAttr::AT_CmseNSCall: \ + case ParsedAttr::AT_ArmStreaming: \ + case ParsedAttr::AT_ArmStreamingCompatible: \ + case ParsedAttr::AT_ArmNewZA: \ + case ParsedAttr::AT_ArmSharedZA: \ + case ParsedAttr::AT_ArmPreservesZA: \ case ParsedAttr::AT_AnyX86NoCallerSavedRegisters: \ case ParsedAttr::AT_AnyX86NoCfCheck: \ CALLING_CONV_ATTRS_CASELIST @@ -7650,6 +7655,53 @@ return true; } + if (attr.getKind() == ParsedAttr::AT_ArmStreaming || + attr.getKind() == ParsedAttr::AT_ArmStreamingCompatible || + attr.getKind() == ParsedAttr::AT_ArmNewZA || + attr.getKind() == ParsedAttr::AT_ArmSharedZA || + attr.getKind() == ParsedAttr::AT_ArmPreservesZA){ + if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr)) + return true; + + if (!unwrapped.isFunctionType()) + return false; + + const FunctionProtoType *FnTy = unwrapped.get()->getAs(); + if (!FnTy) { + // SME ACLE attributes are not supported on K&R-style unprototyped C + // functions. + S.Diag(attr.getLoc(), diag::warn_attribute_ignored) << attr; + attr.setInvalid(); + return false; + } + + FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo(); + switch (attr.getKind()) { + case ParsedAttr::AT_ArmStreaming: + EPI.setArmSMEAttribute(FunctionType::SME_PStateSMEnabledMask); + break; + case ParsedAttr::AT_ArmStreamingCompatible: + EPI.setArmSMEAttribute(FunctionType::SME_PStateSMCompatibleMask); + break; + case ParsedAttr::AT_ArmNewZA: + EPI.setArmSMEAttribute(FunctionType::SME_PStateZANewMask); + break; + case ParsedAttr::AT_ArmSharedZA: + EPI.setArmSMEAttribute(FunctionType::SME_PStateZASharedMask); + break; + case ParsedAttr::AT_ArmPreservesZA: + EPI.setArmSMEAttribute(FunctionType::SME_PStateZAPreservedMask); + break; + default: + llvm_unreachable("Unsupported attribute"); + } + + QualType newtype = S.Context.getFunctionType(FnTy->getReturnType(), + FnTy->getParamTypes(), EPI); + type = unwrapped.wrap(S, newtype->getAs()); + return true; + } + if (attr.getKind() == ParsedAttr::AT_NoThrow) { // Delay if this is not a function type. if (!unwrapped.isFunctionType()) diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.c b/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.c @@ -0,0 +1,195 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme \ +// RUN: -fallow-half-arguments-and-returns -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s + +extern int normal_callee(); + +// == FUNCTION DECLARATIONS == + +__attribute__((arm_streaming)) int streaming_decl(void); +__attribute__((arm_streaming_compatible)) int streaming_compatible_decl(void); +__attribute__((arm_locally_streaming)) int locally_streaming_decl(void); +__attribute__((arm_shared_za)) int shared_za_decl(void); +__attribute__((arm_preserves_za)) int preserves_za_decl(void); +__attribute__((arm_new_za)) int new_za_decl(void); + +// == FUNCTION DEFINITIONS == + +// CHECK-LABEL: @streaming_caller({{.*}}#0 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_streaming)) int streaming_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @streaming_callee({{.*}}#0 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @streaming_decl() #[[ATTR15:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_streaming)) int streaming_callee(void) { + return streaming_decl(); +} + +// CHECK: declare i32 @streaming_decl(){{.*}}#2 + +// CHECK-LABEL: @streaming_compatible_caller({{.*}}#3 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_streaming_compatible)) int streaming_compatible_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @streaming_compatible_callee({{.*}}#3 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @streaming_compatible_decl() #[[ATTR16:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_streaming_compatible)) int streaming_compatible_callee(void) { + return streaming_compatible_decl(); +} + +// CHECK: declare i32 @streaming_compatible_decl(){{.*}}#4 + +// CHECK-LABEL: @locally_streaming_caller({{.*}}#5 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_locally_streaming)) int locally_streaming_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @locally_streaming_callee({{.*}}#5 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @locally_streaming_decl() #[[ATTR17:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_locally_streaming)) int locally_streaming_callee(void) { + return locally_streaming_decl(); +} + +// CHECK: declare i32 @locally_streaming_decl(){{.*}}#6 + +// CHECK-LABEL: @shared_za_caller({{.*}}#7 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_shared_za)) int shared_za_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @shared_za_callee({{.*}}#7 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @shared_za_decl() #[[ATTR18:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_shared_za)) int shared_za_callee(void) { + return shared_za_decl(); +} + +// CHECK: declare i32 @shared_za_decl(){{.*}}#8 + +// CHECK-LABEL: @preserves_za_caller({{.*}}#9 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_preserves_za)) int preserves_za_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @preserves_za_callee({{.*}}#9 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @preserves_za_decl() #[[ATTR19:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_preserves_za)) int preserves_za_callee(void) { + return preserves_za_decl(); +} + +// CHECK: declare i32 @preserves_za_decl(){{.*}}#10 + +// CHECK-LABEL: @new_za_caller({{.*}}#11 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @normal_callee() #[[ATTR14]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_new_za)) int new_za_caller(void) { + return normal_callee(); +} + +// CHECK-LABEL: @new_za_callee({{.*}}#11 +// CHECK-NEXT: entry: +// CHECK-NEXT: [[CALL:%.*]] = call i32 @new_za_decl() #[[ATTR20:[0-9]+]] +// CHECK-NEXT: ret i32 [[CALL]] +// +__attribute__((arm_new_za)) int new_za_callee(void) { + return new_za_decl(); +} + +// CHECK: declare i32 @new_za_decl(){{.*}}#12 + +// Ensure that the attributes are correctly propagated to function types +// and also to callsites. +typedef void __attribute__((arm_streaming)) (*s_ptrty) (int, int); +typedef void __attribute__((arm_streaming_compatible)) (*sc_ptrty) (int, int); +typedef void __attribute__((arm_new_za)) (*nz_ptrty) (int, int); +typedef void __attribute__((arm_shared_za)) (*sz_ptrty) (int, int); +typedef void __attribute__((arm_preserves_za)) (*pz_ptrty) (int, int); + +// CHECK-LABEL: @test_streaming_ptrty( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void [[F:%.*]](i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR15]] +// CHECK-NEXT: ret void +// +void test_streaming_ptrty(s_ptrty f, int x, int y) { return f(x, y); } +// CHECK-LABEL: @test_streaming_compatible_ptrty( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void [[F:%.*]](i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR16]] +// CHECK-NEXT: ret void +// +void test_streaming_compatible_ptrty(sc_ptrty f, int x, int y) { return f(x, y); } +// CHECK-LABEL: @test_new_za( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void [[F:%.*]](i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR20]] +// CHECK-NEXT: ret void +// +void __attribute__((arm_shared_za)) test_new_za(nz_ptrty f, int x, int y) { return f(x, y); } +// CHECK-LABEL: @test_shared_za( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void [[F:%.*]](i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR18]] +// CHECK-NEXT: ret void +// +void __attribute__((arm_shared_za)) test_shared_za(sz_ptrty f, int x, int y) { return f(x, y); } +// CHECK-LABEL: @test_preserved_za( +// CHECK-NEXT: entry: +// CHECK-NEXT: call void [[F:%.*]](i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR19]] +// CHECK-NEXT: ret void +// +void __attribute__((arm_shared_za)) test_preserved_za(pz_ptrty f, int x, int y) { return f(x, y); } + + +// CHECK: attributes #0 = { {{.*}}"aarch64_pstate_sm_enabled"{{.*}} } +// CHECK: attributes #2 = { {{.*}}"aarch64_pstate_sm_enabled"{{.*}} } +// CHECK: attributes #3 = { {{.*}}"aarch64_pstate_sm_compatible"{{.*}} } +// CHECK: attributes #4 = { {{.*}}"aarch64_pstate_sm_compatible"{{.*}} } +// CHECK: attributes #5 = { {{.*}}"aarch64_pstate_sm_body"{{.*}} } +// CHECK: attributes #6 = { {{.*}}"aarch64_pstate_sm_body"{{.*}} } +// CHECK: attributes #7 = { {{.*}}"aarch64_pstate_za_shared"{{.*}} } +// CHECK: attributes #8 = { {{.*}}"aarch64_pstate_za_shared"{{.*}} } +// CHECK: attributes #9 = { {{.*}}"aarch64_pstate_za_preserved"{{.*}} } +// CHECK: attributes #10 = { {{.*}}"aarch64_pstate_za_preserved"{{.*}} } +// CHECK: attributes #11 = { {{.*}}"aarch64_pstate_za_new"{{.*}} } +// CHECK: attributes #12 = { {{.*}}"aarch64_pstate_za_new"{{.*}} } +// CHECK: attributes #15 = { {{.*}}"aarch64_pstate_sm_enabled"{{.*}} } +// CHECK: attributes #16 = { {{.*}}"aarch64_pstate_sm_compatible"{{.*}} } +// CHECK: attributes #17 = { {{.*}}"aarch64_pstate_sm_body"{{.*}} } +// CHECK: attributes #18 = { {{.*}}"aarch64_pstate_za_shared"{{.*}} } +// CHECK: attributes #19 = { {{.*}}"aarch64_pstate_za_preserved"{{.*}} } +// CHECK: attributes #20 = { {{.*}}"aarch64_pstate_za_new"{{.*}} } diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -18,6 +18,7 @@ // CHECK-NEXT: AnyX86NoCfCheck (SubjectMatchRule_hasType_functionType) // CHECK-NEXT: ArcWeakrefUnavailable (SubjectMatchRule_objc_interface) // CHECK-NEXT: ArmBuiltinAlias (SubjectMatchRule_function) +// CHECK-NEXT: ArmLocallyStreaming (SubjectMatchRule_function) // CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function) // CHECK-NEXT: Assumption (SubjectMatchRule_function, SubjectMatchRule_objc_method) // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable)) diff --git a/clang/test/Sema/aarch64-sme-attrs-no-sme.c b/clang/test/Sema/aarch64-sme-attrs-no-sme.c new file mode 100644 --- /dev/null +++ b/clang/test/Sema/aarch64-sme-attrs-no-sme.c @@ -0,0 +1,36 @@ +// Test that the attribute is ignored if we don't compile for both AArch64 with +sme. +// +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s + +extern int normal_callee(void); + +// expected-warning@+1 {{unknown attribute 'arm_streaming' ignored}} +__attribute__((arm_streaming)) +int streaming_caller(void) { + return normal_callee(); +} + +// expected-warning@+1 {{unknown attribute 'arm_locally_streaming' ignored}} +__attribute__((arm_locally_streaming)) +int locally_streaming_caller(void) { + return normal_callee(); +} + +// expected-warning@+1 {{unknown attribute 'arm_shared_za' ignored}} +__attribute__((arm_shared_za)) +int shared_za_caller(void) { + return normal_callee(); +} + +// expected-warning@+1 {{unknown attribute 'arm_preserves_za' ignored}} +__attribute__((arm_preserves_za)) +int preserves_za_caller(void) { + return normal_callee(); +} + +// expected-warning@+1 {{unknown attribute 'arm_new_za' ignored}} +__attribute__((arm_new_za)) +int new_za_caller(void) { + return normal_callee(); +} diff --git a/clang/test/Sema/aarch64-sme-func-attrs.c b/clang/test/Sema/aarch64-sme-func-attrs.c new file mode 100644 --- /dev/null +++ b/clang/test/Sema/aarch64-sme-func-attrs.c @@ -0,0 +1,166 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s + +// Valid attributes + +__attribute__((arm_streaming)) void sme_arm_streaming(void); +__attribute__((arm_streaming_compatible)) void sme_arm_streaming_compatible(void); + +__attribute__((arm_new_za)) void sme_arm_new_za(void); +__attribute__((arm_shared_za)) void sme_arm_shared_za(void); +__attribute__((arm_preserves_za)) void sme_arm_preserves_za(void); + +__attribute__((arm_streaming, arm_new_za)) void sme_arm_streaming_new_za(void); +__attribute__((arm_streaming, arm_shared_za)) void sme_arm_streaming_shared_za(void); +__attribute__((arm_streaming, arm_preserves_za)) void sme_arm_streaming_preserves_za(void); + +__attribute__((arm_streaming_compatible, arm_new_za)) void sme_arm_sc_new_za(void); +__attribute__((arm_streaming_compatible, arm_shared_za)) void sme_arm_sc_shared_za(void); +__attribute__((arm_streaming_compatible, arm_preserves_za)) void sme_arm_sc_preserves_za(void); + +__attribute__((arm_shared_za, arm_preserves_za)) void sme_arm_shared_preserves_za(void); + +__attribute__((arm_locally_streaming)) void sme_arm_locally_streaming(void) { } +__attribute__((arm_locally_streaming, arm_streaming)) void sme_arm_streaming_and_locally_streaming(void) { } +__attribute__((arm_locally_streaming, arm_streaming_compatible)) void sme_arm_streaming_and_streaming_compatible(void) { } + +__attribute__((arm_locally_streaming, arm_new_za)) void sme_arm_ls_new_za(void) { } +__attribute__((arm_locally_streaming, arm_shared_za)) void sme_arm_ls_shared_za(void) { } +__attribute__((arm_locally_streaming, arm_preserves_za)) void sme_arm_ls_preserves_za(void) { } + +// Valid attributes on function pointers + +void __attribute__((arm_streaming)) streaming_ptr(void); +typedef __attribute__((arm_streaming)) void (*fptrty1) (void); +fptrty1 call_streaming_func() { return streaming_ptr; } + +void __attribute__((arm_streaming_compatible)) streaming_compatible_ptr(void); +typedef __attribute__((arm_streaming_compatible)) void (*fptrty2) (void); +fptrty2 call_sc_func() { return streaming_compatible_ptr; } + +void __attribute__((arm_new_za)) new_za_ptr(void); +typedef __attribute__((arm_new_za)) void (*fptrty3) (void); +fptrty3 call_new_za_func() { return new_za_ptr; } + +void __attribute__((arm_shared_za)) shared_za_ptr(void); +typedef __attribute__((arm_shared_za)) void (*fptrty4) (void); +fptrty4 call_shared_za_func() { return shared_za_ptr; } + +void __attribute__((arm_preserves_za)) preserves_za_ptr(void); +typedef __attribute__((arm_preserves_za)) void (*fptrty5) (void); +fptrty5 call_preserve_za_func() { return preserves_za_ptr; } + +void __attribute__((arm_shared_za, arm_preserves_za)) shared_preserves_za_ptr(void); +typedef __attribute__((arm_shared_za, arm_preserves_za)) void (*fptrty6) (void); +fptrty6 call_shared_preserve_za_func() { return shared_preserves_za_ptr; } + +typedef void (*fptrty7) (void); +fptrty7 cast_ls_func_to_normal() { return sme_arm_locally_streaming; } + +// FIXME: Add invalid function pointer assignments such as assigning: +// 1. A streaming compatible function to a normal function pointer, +// 2. A locally streaming function to a streaming function pointer, +// etc. + +// Invalid attributes + +// expected-error@+2 {{'arm_streaming_compatible' and 'arm_streaming' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_streaming, arm_streaming_compatible)) void streaming_mode(void); + +// expected-error@+2 {{'arm_streaming' and 'arm_streaming_compatible' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_streaming_compatible, arm_streaming)) void streaming_compatible(void); + +// expected-error@+2 {{'arm_shared_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_new_za, arm_shared_za)) void new_shared_za(void); + +// expected-error@+2 {{'arm_new_za' and 'arm_shared_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_shared_za, arm_new_za)) void shared_new_za(void); + +// expected-error@+2 {{'arm_preserves_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_new_za, arm_preserves_za)) void new_preserves_za(void); + +// expected-error@+2 {{'arm_new_za' and 'arm_preserves_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +__attribute__((arm_preserves_za, arm_new_za)) void preserves_new_za(void); + +// Invalid attributes on function pointers + +// expected-error@+2 {{'arm_streaming_compatible' and 'arm_streaming' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +void __attribute__((arm_streaming, arm_streaming_compatible)) streaming_ptr_invalid(void); +// expected-error@+2 {{'arm_streaming_compatible' and 'arm_streaming' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +typedef __attribute__((arm_streaming, arm_streaming_compatible)) void (*fptrty8) (void); +fptrty8 invalid_streaming_func() { return streaming_ptr_invalid; } + +// expected-error@+2 {{'arm_shared_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +void __attribute__((arm_new_za, arm_shared_za)) shared_za_ptr_invalid(void); +// expected-error@+2 {{'arm_shared_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +typedef __attribute__((arm_new_za, arm_shared_za)) void (*fptrty9) (void); +fptrty9 invalid_shared_za_func() { return shared_za_ptr_invalid; } + +// expected-error@+2 {{'arm_preserves_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +void __attribute__((arm_new_za, arm_preserves_za)) preserves_za_ptr_invalid(void); +// expected-error@+2 {{'arm_preserves_za' and 'arm_new_za' attributes are not compatible}} +// expected-note@+1 {{conflicting attribute is here}} +typedef __attribute__((arm_new_za, arm_preserves_za)) void (*fptrty10) (void); +fptrty10 invalid_preserve_za_func() { return preserves_za_ptr_invalid; } + +// expected-error@+1 {{'arm_locally_streaming' attribute only applies to functions}} +typedef __attribute__((arm_locally_streaming)) void (*fptrty11) (void); + +// expected-warning@+2 {{'arm_streaming' attribute ignored}} +// expected-warning@+1 {{'arm_streaming' only applies to function types; type here is 'void ()'}} +__attribute__((arm_streaming)) void function_no_prototype(); + +// +// Check for incorrect conversions of function pointers with the attributes +// + +typedef void (*n_ptrty) (void); +typedef __attribute__((arm_streaming)) void (*s_ptrty) (void); +s_ptrty return_valid_streaming_fptr(s_ptrty f) { return f; } + +// expected-warning@+1 {{incompatible function pointer types returning 'n_ptrty' (aka 'void (*)(void)') from a function with result type 's_ptrty' (aka 'void (*)(void) __attribute__((arm_streaming))')}} +s_ptrty return_invalid_fptr_streaming_normal(n_ptrty f) { return f; } +// expected-warning@+1 {{incompatible function pointer types returning 's_ptrty' (aka 'void (*)(void) __attribute__((arm_streaming))') from a function with result type 'n_ptrty' (aka 'void (*)(void)')}} +n_ptrty return_invalid_fptr_normal_streaming(s_ptrty f) { return f; } + +typedef __attribute__((arm_streaming_compatible)) void (*sc_ptrty) (void); +sc_ptrty return_valid_streaming_compatible_fptr(sc_ptrty f) { return f; } + +// expected-warning@+1 {{incompatible function pointer types returning 'n_ptrty' (aka 'void (*)(void)') from a function with result type 'sc_ptrty' (aka 'void (*)(void) __attribute__((arm_streaming_compatible))')}} +sc_ptrty return_invalid_fptr_streaming_compatible_normal(n_ptrty f) { return f; } +// expected-warning@+1 {{incompatible function pointer types returning 'sc_ptrty' (aka 'void (*)(void) __attribute__((arm_streaming_compatible))') from a function with result type 'n_ptrty' (aka 'void (*)(void)')}} +n_ptrty return_invalid_fptr_normal_streaming_compatible(sc_ptrty f) { return f; } + +typedef __attribute__((arm_new_za)) void (*nz_ptrty) (void); +nz_ptrty return_valid_new_za_fptr(nz_ptrty f) { return f; } + +// expected-warning@+1 {{incompatible function pointer types returning 'n_ptrty' (aka 'void (*)(void)') from a function with result type 'nz_ptrty' (aka 'void (*)(void) __attribute__((arm_new_za))')}} +nz_ptrty return_invalid_fptr_new_za_normal(n_ptrty f) { return f; } +// expected-warning@+1 {{incompatible function pointer types returning 'nz_ptrty' (aka 'void (*)(void) __attribute__((arm_new_za))') from a function with result type 'n_ptrty' (aka 'void (*)(void)')}} +n_ptrty return_invalid_fptr_normal_new_za(nz_ptrty f) { return f; } + +typedef __attribute__((arm_shared_za)) void (*sz_ptrty) (void); +sz_ptrty return_valid_shared_za_fptr(sz_ptrty f) { return f; } + +// expected-warning@+1 {{incompatible function pointer types returning 'n_ptrty' (aka 'void (*)(void)') from a function with result type 'sz_ptrty' (aka 'void (*)(void) __attribute__((arm_shared_za))')}} +sz_ptrty return_invalid_fptr_shared_za_normal(n_ptrty f) { return f; } +// expected-warning@+1 {{incompatible function pointer types returning 'sz_ptrty' (aka 'void (*)(void) __attribute__((arm_shared_za))') from a function with result type 'n_ptrty' (aka 'void (*)(void)')}} +n_ptrty return_invalid_fptr_normal_shared_za(sz_ptrty f) { return f; } + +typedef __attribute__((arm_preserves_za)) void (*pz_ptrty) (void); +pz_ptrty return_valid_preserves_za_fptr(pz_ptrty f) { return f; } + +// expected-warning@+1 {{incompatible function pointer types returning 'n_ptrty' (aka 'void (*)(void)') from a function with result type 'pz_ptrty' (aka 'void (*)(void) __attribute__((arm_preserves_za))')}} +pz_ptrty return_invalid_fptr_preserves_za_normal(n_ptrty f) { return f; } +// expected-warning@+1 {{incompatible function pointer types returning 'pz_ptrty' (aka 'void (*)(void) __attribute__((arm_preserves_za))') from a function with result type 'n_ptrty' (aka 'void (*)(void)')}} +n_ptrty return_invalid_fptr_normal_preserves_za(pz_ptrty f) { return f; }