[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
dtemirbulatov wrote: Reverted with 950bb097e11d6ee26533c00519c62df99438 https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
dtemirbulatov wrote: ok, Reverting now. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
bgra8 wrote: @dtemirbulatov could you please revert to green to unblock us and continue the investigation asynchronously? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
bgra8 wrote: @dtemirbulatov this patch causes `clang` to crash. Please revert. repro.cc: ``` typedef __SVFloat32_t a; #pragma clang attribute push(__attribute__((target("+sve"))), \ apply_to = function) template struct b { using c = int; }; template using e = q::c; template a g(b, float); template using h = decltype(g(q(), e())); h> i(b<0, 0>); template using j = decltype(i(q())); template struct m { static void n() { b<0, 0> d; k()(float(), d); } }; template struct p { template void operator()(c, q p2) { int o; int misalignments[]{}; for (int ma : misalignments) for (int mb : misalignments) k()(p2, 0, ma, mb, o); } }; struct D { template void operator()(q, int, int, int, int) { [](j) {}; } void r() { m>::n; } }; #pragma clang attribute pop ``` Compilation command: ``` clang -cc1 -triple aarch64-unknown-linux-gnu \ -fsyntax-only \ -std=gnu++20 \ -x c++ \ repro.cc ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov closed https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode. The streaming and non-streaming vector lengths may be" + " different">, + InGroup, DefaultIgnore; +def warn_sme_locally_streaming_has_vl_args_returns : Warning< + "passing/returning a VL-dependent argument from a __arm_locally_streaming" dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -1390,6 +1390,9 @@ def MultiGPU: DiagGroup<"multi-gpu">; // libc and the CRT to be skipped. def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">; +// A warning group AArch64 related to SME function attribues. dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode. The streaming and non-streaming vector lengths may be" + " different">, + InGroup, DefaultIgnore; +def warn_sme_locally_streaming_has_vl_args_returns : Warning< + "passing/returning a VL-dependent argument from a __arm_locally_streaming" sdesmalen-arm wrote: ```suggestion "passing/returning a VL-dependent argument to/from a __arm_locally_streaming" ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -1390,6 +1390,9 @@ def MultiGPU: DiagGroup<"multi-gpu">; // libc and the CRT to be skipped. def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">; +// A warning group AArch64 related to SME function attribues. sdesmalen-arm wrote: nit: Sorry, just spotted this. ```suggestion // A warning group related to AArch64 SME function attribues. ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7516,28 +7516,23 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } -auto *CallerFD = dyn_cast(CurContext); -bool IsCalleeStreaming = -(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); -bool IsCalleeStreamingCompatible = -(ExtInfo.AArch64SMEAttributes & - FunctionType::SME_PStateSMCompatibleMask); -bool IsBuiltin = (FD && FD->getBuiltinID()); -AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); - -// If the caller is a function and the callee has a different -// non-compitable streaming attribute. If it passed any VL-based arguments -// or return VL-based value, then warn that the streaming and non-streaming -// vector lengths may be different. -if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) { - ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); - if ((CallerFnType != ArmStreaming && - CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) || - (CallerFnType == ArmStreaming && !IsCalleeStreaming && - !IsCalleeStreamingCompatible) || - (CallerFnType == ArmStreamingCompatible && - (IsCalleeStreaming || !IsCalleeStreamingCompatible))) -Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +// If the call requires a streaming-mode change and has scalable vector +// arguments or return values, then warn the user that the streaming and +// non-streaming vector lengths may be different. +bool IsBuiltin = FD && FD->getBuiltinID(); sdesmalen-arm wrote: > Done. It's not though. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3723,8 +3723,8 @@ def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< " different">, InGroup, DefaultIgnore; def warn_sme_locally_streaming_has_vl_args_returns : Warning< - "passing/returning a VL-dependent argument from a function" - " arm_locally_streaming attribute. The streaming and non-streaming vector" + "passing/returning a VL-dependent argument from a arm_locally_streaming" dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7516,28 +7516,23 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } -auto *CallerFD = dyn_cast(CurContext); -bool IsCalleeStreaming = -(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); -bool IsCalleeStreamingCompatible = -(ExtInfo.AArch64SMEAttributes & - FunctionType::SME_PStateSMCompatibleMask); -bool IsBuiltin = (FD && FD->getBuiltinID()); -AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); - -// If the caller is a function and the callee has a different -// non-compitable streaming attribute. If it passed any VL-based arguments -// or return VL-based value, then warn that the streaming and non-streaming -// vector lengths may be different. -if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) { - ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); - if ((CallerFnType != ArmStreaming && - CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) || - (CallerFnType == ArmStreaming && !IsCalleeStreaming && - !IsCalleeStreamingCompatible) || - (CallerFnType == ArmStreamingCompatible && - (IsCalleeStreaming || !IsCalleeStreamingCompatible))) -Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +// If the call requires a streaming-mode change and has scalable vector +// arguments or return values, then warn the user that the streaming and +// non-streaming vector lengths may be different. +bool IsBuiltin = FD && FD->getBuiltinID(); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) { + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if ((CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) || + (CallerFnType == ArmStreaming && !IsCalleeStreaming && + !IsCalleeStreamingCompatible) || + (CallerFnType == ArmStreamingCompatible && + (IsCalleeStreaming || !IsCalleeStreamingCompatible))) dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7516,28 +7516,23 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } -auto *CallerFD = dyn_cast(CurContext); -bool IsCalleeStreaming = -(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); -bool IsCalleeStreamingCompatible = -(ExtInfo.AArch64SMEAttributes & - FunctionType::SME_PStateSMCompatibleMask); -bool IsBuiltin = (FD && FD->getBuiltinID()); -AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); - -// If the caller is a function and the callee has a different -// non-compitable streaming attribute. If it passed any VL-based arguments -// or return VL-based value, then warn that the streaming and non-streaming -// vector lengths may be different. -if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) { - ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); - if ((CallerFnType != ArmStreaming && - CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) || - (CallerFnType == ArmStreaming && !IsCalleeStreaming && - !IsCalleeStreamingCompatible) || - (CallerFnType == ArmStreamingCompatible && - (IsCalleeStreaming || !IsCalleeStreamingCompatible))) -Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +// If the call requires a streaming-mode change and has scalable vector +// arguments or return values, then warn the user that the streaming and +// non-streaming vector lengths may be different. +bool IsBuiltin = FD && FD->getBuiltinID(); sdesmalen-arm wrote: minor nit: this definition can be moved to inside the `if (auto *CallerFD = ..)` block. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3723,8 +3723,8 @@ def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< " different">, InGroup, DefaultIgnore; def warn_sme_locally_streaming_has_vl_args_returns : Warning< - "passing/returning a VL-dependent argument from a function" - " arm_locally_streaming attribute. The streaming and non-streaming vector" + "passing/returning a VL-dependent argument from a arm_locally_streaming" sdesmalen-arm wrote: ```suggestion "passing/returning a VL-dependent argument from a __arm_locally_streaming" ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode. The streaming and non-streaming vector lengths may be" + " different">, + InGroup, DefaultIgnore; +def warn_sme_locally_streaming_has_vl_args_returns : Warning< + "passing/returning a VL-dependent argument from a function" + " arm_locally_streaming attribute. The streaming and non-streaming vector" dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); sdesmalen-arm wrote: Why not initialise the variable with `Proto->getReturnType()->isSizelessVectorType()` and then remove this separate `|=` statement? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. sdesmalen-arm wrote: This comment reads a bit strange. What about: ``` // If the call requires a streaming-mode change and has scalable vector // arguments or return values, then warn the user that the streaming and // non-streaming vector lengths may be different. ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); sdesmalen-arm wrote: nit: parentheses are unnecessary. ```suggestion bool IsCalleeStreamingCompatible = ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMCompatibleMask; ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); sdesmalen-arm wrote: nit: parentheses are unnecessary. ```suggestion ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask; ``` Also, please move these closer to their use (inside the if blocks) https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); sdesmalen-arm wrote: nit: move this closer to its use, preferably wrap the condition, e.g. ``` if (auto *CallerFD = dyn_cast<..>(..)) { ... } ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && !IsBuiltin && AnyScalableArgsOrRet) { + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if ((CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible && IsCalleeStreaming) || + (CallerFnType == ArmStreaming && !IsCalleeStreaming && + !IsCalleeStreamingCompatible) || + (CallerFnType == ArmStreamingCompatible && + (IsCalleeStreaming || !IsCalleeStreamingCompatible))) sdesmalen-arm wrote: This can be simplified to: ``` if (!IsCalleeStreamingCompatible && (CallerFnType == ArmStreamingCompatible || ((CallerFnType == ArmStreaming) ^ IsCalleeStreaming))) ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,30 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); sdesmalen-arm wrote: nit: parentheses are unnecessary. ```suggestion bool IsBuiltin = FD && FD->getBuiltinID(); ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/sdesmalen-arm commented: Thanks for the update. I just left a few more suggestions to clean up the code a bit. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/sdesmalen-arm edited https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode. The streaming and non-streaming vector lengths may be" + " different">, + InGroup, DefaultIgnore; +def warn_sme_locally_streaming_has_vl_args_returns : Warning< + "passing/returning a VL-dependent argument from a function" + " arm_locally_streaming attribute. The streaming and non-streaming vector" sdesmalen-arm wrote: ```suggestion "passing/returning a VL-dependent argument from a __arm_locally_streaming" " function. The streaming and non-streaming vector" ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 01/10] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::wa
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7531,19 +7531,15 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // vector lengths may be different. if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); - if (CallerFnType != ArmStreaming && - CallerFnType != ArmStreamingCompatible) { -if (IsCalleeStreaming && AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } else if (CallerFnType == ArmStreaming && !IsCalleeStreaming && - !IsCalleeStreamingCompatible) { -if (AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } else if (CallerFnType == ArmStreamingCompatible) { -if ((IsCalleeStreaming || !IsCalleeStreamingCompatible) && -AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } + if ((CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible && IsCalleeStreaming && + AnyScalableArgsOrRet) || dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/9] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { sdesmalen-arm wrote: > Done. It is not. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7531,19 +7531,15 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // vector lengths may be different. if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); - if (CallerFnType != ArmStreaming && - CallerFnType != ArmStreamingCompatible) { -if (IsCalleeStreaming && AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } else if (CallerFnType == ArmStreaming && !IsCalleeStreaming && - !IsCalleeStreamingCompatible) { -if (AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } else if (CallerFnType == ArmStreamingCompatible) { -if ((IsCalleeStreaming || !IsCalleeStreamingCompatible) && -AnyScalableArgsOrRet) - Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); - } + if ((CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible && IsCalleeStreaming && + AnyScalableArgsOrRet) || sdesmalen-arm wrote: Can you factor out `AnyScalableArgsOrRet`? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/8] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12230,12 +12230,22 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, } // Check if the function definition uses any AArch64 SME features without - // having the '+sme' feature enabled. + // having the '+sme' feature enabled and warn user if sme locally streaming + // function returns or uses arguments with VL-based types. if (DeclIsDefn) { const auto *Attr = NewFD->getAttr(); bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible) { +if (IsCalleeStreaming && AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } else if (CallerFnType == ArmStreaming && !IsCalleeStreaming && + !IsCalleeStreamingCompatible) { +if (AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } else if (CallerFnType == ArmStreamingCompatible) { +if ((IsCalleeStreaming || !IsCalleeStreamingCompatible) && +AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode, the streaming and non-streaming vector lengths may be" + " different">, + InGroup; sdesmalen-arm wrote: These warnings should be disabled by default, as the user may intentionally pass/return scalable vectors, knowing something about the target they're compiling for. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (CallerFnType != ArmStreaming && + CallerFnType != ArmStreamingCompatible) { +if (IsCalleeStreaming && AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } else if (CallerFnType == ArmStreaming && !IsCalleeStreaming && + !IsCalleeStreamingCompatible) { +if (AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } else if (CallerFnType == ArmStreamingCompatible) { +if ((IsCalleeStreaming || !IsCalleeStreamingCompatible) && +AnyScalableArgsOrRet) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } sdesmalen-arm wrote: Do you think you can simplify this code? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12230,12 +12230,22 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, } // Check if the function definition uses any AArch64 SME features without - // having the '+sme' feature enabled. + // having the '+sme' feature enabled and warn user if sme locally streaming + // function returns or uses arguments with VL-based types. if (DeclIsDefn) { const auto *Attr = NewFD->getAttr(); bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { sdesmalen-arm wrote: Please write this without using `UsesSM`, since that variable is updated further down the line. It seems better to explicitly for `NewFD->hasAttr()`. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,16 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode, the streaming and non-streaming vector lengths may be" sdesmalen-arm wrote: ```suggestion " streaming-mode. The streaming and non-streaming vector lengths may be" ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,36 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = +(ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask); +bool IsCalleeStreamingCompatible = +(ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask); +bool IsBuiltin = (FD && FD->getBuiltinID()); +AnyScalableArgsOrRet |= Proto->getReturnType()->isSizelessVectorType(); + +// If the caller is a function and the callee has a different +// non-compitable streaming attribute. If it passed any VL-based arguments +// or return VL-based value, then warn that the streaming and non-streaming +// vector lengths may be different. +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { sdesmalen-arm wrote: ```suggestion if (CallerFD && !IsBuiltin) { ``` It is valid to compile the following function without `+sme`: ``` void streaming_compatible_fn(svint32_t v, void (*foo)(svint32_t)) __arm_streaming_compatible { foo(v); } ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12239,7 +12239,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, if (UsesSM) { dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/7] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7517,34 +7517,37 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } auto *CallerFD = dyn_cast(CurContext); -if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && -!FD->getBuiltinID()) { +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); +bool IsBuiltin = (FD && FD->getBuiltinID()); + +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { // If the callee has an AArch64 SME __arm_locally_streaming attribute // warn if this function returns VL-based value or pass any such argument, // the streaming and non-streaming vector lengths may be different. - ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); // If the caller is a non-streaming function and the callee has a // streaming attribute. If it passed any VL-based arguments or return // VL-based value, then warn that the streaming and non-streaming vector // lengths may be different. if (CallerFnType != ArmStreaming) { -if (CalleeFnType == ArmStreaming) { +if (IsCalleeStreaming) { if (AnyScalableArgs) -Diag(Loc, - diag::warn_sme_non_streaming_caller_pass_args_to_streaming); - if (FD->getReturnType()->isSizelessVectorType()) -Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + if (Proto->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { + if (NewFD->getReturnType()->isSizelessVectorType()) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); + auto *FPT = NewFD->getType()->castAs(); + bool AnyScalableArgs = false; + for (QualType T : FPT->param_types()) { +if (T->isSizelessVectorType()) { + AnyScalableArgs = true; + break; +} + } + if (AnyScalableArgs) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { + if (NewFD->getReturnType()->isSizelessVectorType()) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); + auto *FPT = NewFD->getType()->castAs(); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); +bool IsBuiltin = (FD && FD->getBuiltinID()); + +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (IsCalleeStreaming) { + if (AnyScalableArgs) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + if (Proto->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +} + } else if (!IsCalleeStreaming) { +// If the callee is a non-streaming function and the caller has +// streaming attribute. If it passed any VL-based arguments or return +// VL-based value, then warn that the streaming and non-streaming vector +// lengths may be different. +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +if (Proto->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,14 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode, is undefined behaviour">, dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/6] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); sdesmalen-arm wrote: Streaming-compatible and streaming are not the same thing. i.e. if the callee is 'streaming-compatible', `IsCalleeStreaming` should be `false`. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12239,7 +12239,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, if (UsesSM) { sdesmalen-arm wrote: The comment on line 12232-12233 needs an update. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { + if (NewFD->getReturnType()->isSizelessVectorType()) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); + auto *FPT = NewFD->getType()->castAs(); + bool AnyScalableArgs = false; + for (QualType T : FPT->param_types()) { +if (T->isSizelessVectorType()) { + AnyScalableArgs = true; + break; +} + } + if (AnyScalableArgs) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); sdesmalen-arm wrote: Can this be written like something along the lines of: ``` if (NewFD->getReturnType()->isSizelessVectorType() || llvm::any_of(FPT->param_types(), [](QualType T) { return T->isSizelessVectorType(); })) Diag(); ``` ? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -445,3 +448,54 @@ void conflicting_state_attrs_preserves_out_zt0(void) __arm_preserves("zt0") __ar // expected-cpp-error@+2 {{conflicting attributes for state 'zt0'}} // expected-error@+1 {{conflicting attributes for state 'zt0'}} void conflicting_state_attrs_preserves_inout_zt0(void) __arm_preserves("zt0") __arm_inout("zt0"); + sdesmalen-arm wrote: I don't see all cases I suggested covered in the tests below. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -12236,6 +12236,23 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, bool UsesSM = NewFD->hasAttr(); bool UsesZA = Attr && Attr->isNewZA(); bool UsesZT0 = Attr && Attr->isNewZT0(); + +if (UsesSM) { + if (NewFD->getReturnType()->isSizelessVectorType()) +Diag(NewFD->getLocation(), + diag::warn_sme_locally_streaming_has_vl_args_returns); + auto *FPT = NewFD->getType()->castAs(); sdesmalen-arm wrote: Is `FunctionPrototype` correct here? That means the check does not happen on unprototyped functions, such as `__arm_locally_streaming void foo() { ... }` in C (not C++). https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,41 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); +bool IsBuiltin = (FD && FD->getBuiltinID()); + +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (IsCalleeStreaming) { + if (AnyScalableArgs) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + if (Proto->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +} + } else if (!IsCalleeStreaming) { +// If the callee is a non-streaming function and the caller has +// streaming attribute. If it passed any VL-based arguments or return +// VL-based value, then warn that the streaming and non-streaming vector +// lengths may be different. +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); +if (Proto->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + } sdesmalen-arm wrote: Does this code support the following case: ``` void test_sc_to_n(sv_ty arg) __arm_streaming_compatible { n(arg); } // expect a diagnostic ``` ? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,14 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_pass_return_vl_to_non_streaming : Warning< + "passing a VL-dependent argument to/from a function that has a different" + " streaming-mode, is undefined behaviour">, sdesmalen-arm wrote: it is only undefined behaviour if the streaming VL != non-streaming VL. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7517,34 +7517,37 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } auto *CallerFD = dyn_cast(CurContext); -if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && -!FD->getBuiltinID()) { +bool IsCalleeStreaming = ((ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMEnabledMask) || + (ExtInfo.AArch64SMEAttributes & + FunctionType::SME_PStateSMCompatibleMask)); +bool IsBuiltin = (FD && FD->getBuiltinID()); + +if (CallerFD && Context.getTargetInfo().hasFeature("sme") && !IsBuiltin) { // If the callee has an AArch64 SME __arm_locally_streaming attribute // warn if this function returns VL-based value or pass any such argument, // the streaming and non-streaming vector lengths may be different. - ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); // If the caller is a non-streaming function and the callee has a // streaming attribute. If it passed any VL-based arguments or return // VL-based value, then warn that the streaming and non-streaming vector // lengths may be different. if (CallerFnType != ArmStreaming) { -if (CalleeFnType == ArmStreaming) { +if (IsCalleeStreaming) { if (AnyScalableArgs) -Diag(Loc, - diag::warn_sme_non_streaming_caller_pass_args_to_streaming); - if (FD->getReturnType()->isSizelessVectorType()) -Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); + if (Proto->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_streaming_pass_return_vl_to_non_streaming); sdesmalen-arm wrote: Do you think this could be simplified further? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -445,3 +448,54 @@ void conflicting_state_attrs_preserves_out_zt0(void) __arm_preserves("zt0") __ar // expected-cpp-error@+2 {{conflicting attributes for state 'zt0'}} // expected-error@+1 {{conflicting attributes for state 'zt0'}} void conflicting_state_attrs_preserves_inout_zt0(void) __arm_preserves("zt0") __arm_inout("zt0"); + dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,38 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (CalleeFnType == ArmStreaming) { + if (AnyScalableArgs) +Diag(Loc, + diag::warn_sme_non_streaming_caller_pass_args_to_streaming); + if (FD->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +} + } else if (CalleeFnType != ArmStreaming) { dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,38 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/5] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,38 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && sdesmalen-arm wrote: This code requires that the function definition is available (`if (FD && ...)`), but the streaming mode is exposed through the interface, meaning that we shouldn't need `FD` in order to emit a diagnostic. For example: ``` // I would expect a warning here. void test_n_to_s( __SVInt32_t arg, void (*sc)(__SVInt32_t arg) __arm_streaming) { sc(arg); } ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -445,3 +448,54 @@ void conflicting_state_attrs_preserves_out_zt0(void) __arm_preserves("zt0") __ar // expected-cpp-error@+2 {{conflicting attributes for state 'zt0'}} // expected-error@+1 {{conflicting attributes for state 'zt0'}} void conflicting_state_attrs_preserves_inout_zt0(void) __arm_preserves("zt0") __arm_inout("zt0"); + sdesmalen-arm wrote: I just wrote some tests manually with all combinations of n (normal), s (streaming), sc (streaming-compatible) and see the current behaviour isn't entirely correct. See the FIXME's below. It also shows that there isn't enough test-coverage in your patch. ``` typedef __SVInt32_t sv_ty; void n(sv_ty arg); void sc(sv_ty arg) __arm_streaming_compatible; void s(sv_ty arg) __arm_streaming; void test_n_to_n(sv_ty arg) { n(arg); } void test_n_to_sc(sv_ty arg) { sc(arg); } void test_n_to_s(sv_ty arg) { s(arg); } // expect a diagnostic void test_sc_to_n(sv_ty arg) __arm_streaming_compatible { n(arg); } // expect a diagnostic void test_sc_to_sc(sv_ty arg) __arm_streaming_compatible { sc(arg); } void test_sc_to_s(sv_ty arg) __arm_streaming_compatible { s(arg); } // expect a diagnostic (FIXME: missing diagnostic) void test_s_to_n(sv_ty arg) __arm_streaming { n(arg); } // expect a diagnostic void test_s_to_sc(sv_ty arg) __arm_streaming { sc(arg); } // FIXME: should not see a diagnostic for this case. void test_s_to_s(sv_ty arg) __arm_streaming { s(arg); } __arm_locally_streaming void ls_arg(sv_ty arg) { } // expect a diagnostic __arm_locally_streaming sv_ty ls_ret() { return {}; } // expect a diagnostic ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; sdesmalen-arm wrote: nit: I think we can use a single message for this, e.g. `"passing a VL-dependent argument to/from a function that has a different streaming-mode, is undefined behaviour"` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,38 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (CalleeFnType == ArmStreaming) { + if (AnyScalableArgs) +Diag(Loc, + diag::warn_sme_non_streaming_caller_pass_args_to_streaming); + if (FD->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +} + } else if (CalleeFnType != ArmStreaming) { sdesmalen-arm wrote: This logic is not correct, because the following example should not result in a warning. ``` void sc_f(sv_ty arg) __arm_streaming_compatible; void test_s_to_sc2(sv_ty arg) __arm_streaming { sc_f(arg); }``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; sdesmalen-arm wrote: These two can become a single message as well. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; dtemirbulatov wrote: Add new warning group AArch64SMEAttributes. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/4] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; sdesmalen-arm wrote: Because the attribute is not ignored. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,44 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr()) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_locally_streaming_returns_vl); + } dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,44 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr()) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_locally_streaming_returns_vl); + } + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (CalleeFnType == ArmStreaming) { + if (AnyScalableArgs) +Diag(Loc, + diag::warn_sme_non_streaming_caller_pass_args_to_streaming); + if (FD->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +} + } else if (!FD->hasAttr()) { dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -1,5 +1,6 @@ -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +#include dtemirbulatov wrote: Done. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/3] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; dtemirbulatov wrote: But why not, There is `warn_riscv_repeated_interrupt_attribute` also uses `IgnoredAttributes`. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov edited https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -1,5 +1,6 @@ -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +#include dtemirbulatov wrote: ok, but then I have to define __clang_svint32x4_t. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,44 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr()) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_locally_streaming_returns_vl); + } + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-based arguments or return + // VL-based value, then warn that the streaming and non-streaming vector + // lengths may be different. + if (CallerFnType != ArmStreaming) { +if (CalleeFnType == ArmStreaming) { + if (AnyScalableArgs) +Diag(Loc, + diag::warn_sme_non_streaming_caller_pass_args_to_streaming); + if (FD->getReturnType()->isSizelessVectorType()) +Diag(Loc, diag::warn_sme_non_streaming_caller_returns_to_streaming); +} + } else if (!FD->hasAttr()) { sdesmalen-arm wrote: This is not correct. I get a diagnostic for this case: ``` svint8_t bar1(void) __arm_streaming; svint8_t foo1() __arm_streaming { return bar1();// incorrectly gives a diagnostic } ``` https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -1,5 +1,6 @@ -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s -// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s +#include sdesmalen-arm wrote: Can you write this test without including `arm_sme.h` ? https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -7513,6 +7516,44 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr()) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_locally_streaming_returns_vl); + } sdesmalen-arm wrote: `__arm_locally_streaming` is not a property of a function interface and therefore unrelated to a function _call_. That's why this code should live somewhere else. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
@@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; sdesmalen-arm wrote: I don't think 'IgnoredAttributes' is correct. These diagnostics probably deserve to be in their own group. https://github.com/llvm/llvm-project/pull/79842 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov updated https://github.com/llvm/llvm-project/pull/79842 >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH 1/2] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e..37fea5746936c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b4..e668a45c69e5f 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Dinar Temirbulatov (dtemirbulatov) Changes …or size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- Full diff: https://github.com/llvm/llvm-project/pull/79842.diff 3 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+24) - (modified) clang/lib/Sema/SemaChecking.cpp (+42) - (modified) clang/test/Sema/aarch64-sme-func-attrs.c (+66-2) ``diff diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e24..37fea5746936c7a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42b..e668a45c69e5f91 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); + ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD); + if (FD->hasAttr() && + CallerFnType != ArmStreaming) { +if (AnyScalableArgs) + Diag(Loc, diag::warn_sme_locally_streaming_has_vl_args); +if (FD->getReturnType()->isSizelessVectorType()) + Diag(Loc, diag::warn_sme_locally_streaming_returns_vl); + } + // If the caller is a non-streaming function and the callee has a + // streaming attribute. If it passed any VL-bas
[clang] [Clang][AArch64] Warn when calling streaming/non-streaming about vect… (PR #79842)
https://github.com/dtemirbulatov created https://github.com/llvm/llvm-project/pull/79842 …or size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. >From af323998a63a72f569d543cf5167d5d28e784682 Mon Sep 17 00:00:00 2001 From: Dinar Temirbulatov Date: Mon, 29 Jan 2024 14:43:13 + Subject: [PATCH] [Clang][AArch64] Warn when calling streaming/non-streaming about vector size might be different. The compiler doesn't know in advance if the streaming and non-streaming vector-lengths are different, so it should be safe to give a warning diagnostic to warn the user about possible undefined behaviour. If the user knows the vector lengths are equal, they can disable the warning separately. --- .../clang/Basic/DiagnosticSemaKinds.td| 24 +++ clang/lib/Sema/SemaChecking.cpp | 42 clang/test/Sema/aarch64-sme-func-attrs.c | 68 ++- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 24d32cb87c89e2..37fea5746936c7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3717,6 +3717,30 @@ def err_sme_definition_using_za_in_non_sme_target : Error< "function using ZA state requires 'sme'">; def err_sme_definition_using_zt0_in_non_sme2_target : Error< "function using ZT0 state requires 'sme2'">; +def warn_sme_streaming_caller_pass_args_to_non_streaming : Warning< + "streaming caller passes a VL-dependent argument to non-streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_callee_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_pass_args_to_streaming : Warning< + "non-streaming caller passes a VL-dependent argument to streaming callee, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_non_streaming_caller_returns_to_streaming : Warning< + "non-streaming callee returns a VL-dependent value to streaming caller, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_has_vl_args : Warning< + "non-streaming callee receives a VL-dependent argument and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; +def warn_sme_locally_streaming_returns_vl : Warning< + "non-streaming callee returns a VL-dependent value and the callee has an arm_locally_streaming attribute, " + "the streaming and non-streaming vector lengths may be different">, + InGroup; def err_conflicting_attributes_arm_state : Error< "conflicting attributes for state '%0'">; def err_unknown_arm_state : Error< diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 502b24bcdf8b42..e668a45c69e5f9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -7480,6 +7480,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, // For variadic functions, we may have more args than parameters. // For some K&R functions, we may have less args than parameters. const auto N = std::min(Proto->getNumParams(), Args.size()); +bool AnyScalableArgs = false; for (unsigned ArgIdx = 0; ArgIdx < N; ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. if (const Expr *Arg = Args[ArgIdx]) { @@ -7493,6 +7494,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, checkAIXMemberAlignment((Arg->getExprLoc()), Arg); QualType ParamTy = Proto->getParamType(ArgIdx); +if (ParamTy->isSizelessVectorType()) + AnyScalableArgs = true; QualType ArgTy = Arg->getType(); CheckArgAlignment(Arg->getExprLoc(), FDecl, std::to_string(ArgIdx + 1), ArgTy, ParamTy); @@ -7513,6 +7516,45 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } +auto *CallerFD = dyn_cast(CurContext); +if (FD && CallerFD && Context.getTargetInfo().hasFeature("sme") && +!FD->getBuiltinID()) { + // If the callee has an AArch64 SME __arm_locally_streaming attribute + // warn if this function returns VL-based value or pass any such argument, + // the streaming and non-streaming vector lengths may be different. + ArmStreamingType CalleeFnType = getArmStreamingFnType(FD); +