Skip to content

Commit 00772b8

Browse files
[AArch64][SME] Add diagnostics to CheckConstexprFunctionDefinition
CheckFunctionDeclaration emits diagnostics if any SME attributes are used by a function definition without the required +sme or +sme2 target features. This patch adds similar diagnostics to CheckConstexprFunctionDefinition to ensure this emits the same errors when attributes such as __arm_new("za") are found without +sme/+sme2.
1 parent d8d4c18 commit 00772b8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,28 @@ bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD,
18541854
}
18551855
}
18561856

1857+
if (Context.getTargetInfo().getTriple().isAArch64()) {
1858+
const auto *Attr = NewFD->getAttr<ArmNewAttr>();
1859+
bool LocallyStreaming = NewFD->hasAttr<ArmLocallyStreamingAttr>();
1860+
llvm::StringMap<bool> FeatureMap;
1861+
Context.getFunctionFeatureMap(FeatureMap, NewFD);
1862+
if (!FeatureMap.contains("sme") && LocallyStreaming) {
1863+
Diag(NewFD->getLocation(),
1864+
diag::err_sme_definition_using_sm_in_non_sme_target);
1865+
return false;
1866+
}
1867+
if (Attr && Attr->isNewZA() && !FeatureMap.contains("sme")) {
1868+
Diag(NewFD->getLocation(),
1869+
diag::err_sme_definition_using_za_in_non_sme_target);
1870+
return false;
1871+
}
1872+
if (Attr && Attr->isNewZT0() && !FeatureMap.contains("sme2")) {
1873+
Diag(NewFD->getLocation(),
1874+
diag::err_sme_definition_using_zt0_in_non_sme2_target);
1875+
return false;
1876+
}
1877+
}
1878+
18571879
// - each of its parameter types shall be a literal type; (removed in C++23)
18581880
if (!getLangOpts().CPlusPlus23 &&
18591881
!CheckConstexprParameterTypes(*this, NewFD, Kind))

clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -std=c++23 -fsyntax-only -verify %s
22

33
// This test is testing the diagnostics that Clang emits when compiling without '+sme'.
44

@@ -48,3 +48,9 @@ void streaming_compatible_def2(void (*streaming_fn_ptr)(void) __arm_streaming,
4848
// Also test when call-site is not a function.
4949
int streaming_decl_ret_int() __arm_streaming;
5050
int x = streaming_decl_ret_int(); // expected-error {{call to a streaming function requires 'sme'}}
51+
52+
void sme_attrs_method_decls() {
53+
[&] __arm_locally_streaming () { return; }(); // expected-error {{function executed in streaming-SVE mode requires 'sme'}}
54+
[&] __arm_new("za") () { return; }(); // expected-error {{function using ZA state requires 'sme'}}
55+
[&] __arm_new("zt0") () { return; }(); // expected-error {{function using ZT0 state requires 'sme2'}}
56+
}

0 commit comments

Comments
 (0)