[clang] 453c30e - [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.
Sander de Smalen via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 9 05:38:18 PDT 2023
Author: Sander de Smalen
Date: 2023-08-09T12:37:41Z
New Revision: 453c30e9e633f5b1e9bebed950592e3e51645a94
URL: https://github.com/llvm/llvm-project/commit/453c30e9e633f5b1e9bebed950592e3e51645a94
DIFF: https://github.com/llvm/llvm-project/commit/453c30e9e633f5b1e9bebed950592e3e51645a94.diff
LOG: [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.
The caller is required to have ZA state if it wants to share it with a callee.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D157270
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
clang/test/Sema/aarch64-sme-func-attrs.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9017d5ad3711c9..bbd40a16040398 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3629,6 +3629,8 @@ def err_sme_attr_mismatch : Error<
"function declared %0 was previously declared %1, which has
diff erent SME function attributes">;
def err_sme_call_in_non_sme_target : Error<
"call to a streaming function requires 'sme'">;
+def err_sme_za_call_no_za_state : Error<
+ "call to a shared ZA function requires the caller to have ZA state">;
def err_sme_definition_using_sm_in_non_sme_target : Error<
"function executed in streaming-SVE mode requires 'sme'">;
def err_sme_definition_using_za_in_non_sme_target : Error<
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e2bf759307e99b..281f1883d269c2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6811,6 +6811,22 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
Diag(Loc, diag::err_sme_call_in_non_sme_target);
}
}
+
+ // If the callee uses AArch64 SME ZA state but the caller doesn't define
+ // any, then this is an error.
+ if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateZASharedMask) {
+ bool CallerHasZAState = false;
+ if (const auto *CallerFD = dyn_cast<FunctionDecl>(CurContext)) {
+ if (CallerFD->hasAttr<ArmNewZAAttr>())
+ CallerHasZAState = true;
+ else if (const auto *FPT = CallerFD->getType()->getAs<FunctionProtoType>())
+ CallerHasZAState = FPT->getExtProtoInfo().AArch64SMEAttributes &
+ FunctionType::SME_PStateZASharedMask;
+ }
+
+ if (!CallerHasZAState)
+ Diag(Loc, diag::err_sme_za_call_no_za_state);
+ }
}
if (FDecl && FDecl->hasAttr<AllocAlignAttr>()) {
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp b/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
index 52937495484d04..0768bfc3323870 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
@@ -255,7 +255,7 @@ int call() { return 0; }
template <typename T, typename... Other>
__attribute__((always_inline))
-int call(T f, Other... other) {
+int call(T f, Other... other) __arm_shared_za {
return f() + call(other...);
}
@@ -270,7 +270,7 @@ int call(T f, Other... other) {
// CHECK-NEXT: add nsw
// CHECK-NEXT: add nsw
// CHECK-NEXT: ret
-int test_variadic_template() {
+int test_variadic_template() __arm_shared_za {
return call(normal_callee,
streaming_decl,
streaming_compatible_decl,
diff --git a/clang/test/Sema/aarch64-sme-func-attrs.c b/clang/test/Sema/aarch64-sme-func-attrs.c
index 71140a9ebc61eb..73c0934d689e7c 100644
--- a/clang/test/Sema/aarch64-sme-func-attrs.c
+++ b/clang/test/Sema/aarch64-sme-func-attrs.c
@@ -178,7 +178,31 @@ void redecl_preserve_za(void) __arm_shared_za {}
void redecl_nopreserve_za(void) __arm_shared_za;
void redecl_nopreserve_za(void) __arm_shared_za __arm_preserves_za {}
+void non_za_definition(void (*shared_za_fn_ptr)(void) __arm_shared_za) {
+ sme_arm_new_za(); // OK
+ // expected-error at +2 {{call to a shared ZA function requires the caller to have ZA state}}
+ // expected-cpp-error at +1 {{call to a shared ZA function requires the caller to have ZA state}}
+ sme_arm_shared_za();
+ // expected-error at +2 {{call to a shared ZA function requires the caller to have ZA state}}
+ // expected-cpp-error at +1 {{call to a shared ZA function requires the caller to have ZA state}}
+ shared_za_fn_ptr();
+}
+
+void shared_za_definition(void (*shared_za_fn_ptr)(void) __arm_shared_za) __arm_shared_za {
+ sme_arm_shared_za(); // OK
+ shared_za_fn_ptr(); // OK
+}
+
+__arm_new_za void new_za_definition(void (*shared_za_fn_ptr)(void) __arm_shared_za) {
+ sme_arm_shared_za(); // OK
+ shared_za_fn_ptr(); // OK
+}
+
#ifdef __cplusplus
+int shared_za_initializer(void) __arm_shared_za;
+// expected-cpp-error at +1 {{call to a shared ZA function requires the caller to have ZA state}}
+int global = shared_za_initializer();
+
struct S {
virtual void shared_za_memberfn(void) __arm_shared_za;
};
More information about the cfe-commits
mailing list