Skip to content

Commit bbc80c2

Browse files
- Move diagnostics to SemaARM.cpp
1 parent 00772b8 commit bbc80c2

File tree

5 files changed

+61
-74
lines changed

5 files changed

+61
-74
lines changed

clang/include/clang/Sema/SemaARM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SemaARM : public SemaBase {
7979
void handleNewAttr(Decl *D, const ParsedAttr &AL);
8080
void handleCmseNSEntryAttr(Decl *D, const ParsedAttr &AL);
8181
void handleInterruptAttr(Decl *D, const ParsedAttr &AL);
82+
void CheckSMEFunctionDefAttributes(const FunctionDecl *FD);
8283
};
8384

8485
SemaARM::ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD);

clang/lib/Sema/SemaARM.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,4 +1328,57 @@ void SemaARM::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
13281328
ARMInterruptAttr(getASTContext(), AL, Kind));
13291329
}
13301330

1331+
// Check if the function definition uses any AArch64 SME features without
1332+
// having the '+sme' feature enabled and warn user if sme locally streaming
1333+
// function returns or uses arguments with VL-based types.
1334+
void SemaARM::CheckSMEFunctionDefAttributes(const FunctionDecl *FD) {
1335+
const auto *Attr = FD->getAttr<ArmNewAttr>();
1336+
bool UsesSM = FD->hasAttr<ArmLocallyStreamingAttr>();
1337+
bool UsesZA = Attr && Attr->isNewZA();
1338+
bool UsesZT0 = Attr && Attr->isNewZT0();
1339+
1340+
if (FD->hasAttr<ArmLocallyStreamingAttr>()) {
1341+
if (FD->getReturnType()->isSizelessVectorType())
1342+
Diag(FD->getLocation(),
1343+
diag::warn_sme_locally_streaming_has_vl_args_returns)
1344+
<< /*IsArg=*/false;
1345+
if (llvm::any_of(FD->parameters(), [](ParmVarDecl *P) {
1346+
return P->getOriginalType()->isSizelessVectorType();
1347+
}))
1348+
Diag(FD->getLocation(),
1349+
diag::warn_sme_locally_streaming_has_vl_args_returns)
1350+
<< /*IsArg=*/true;
1351+
}
1352+
if (const auto *FPT = FD->getType()->getAs<FunctionProtoType>()) {
1353+
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
1354+
UsesSM |= EPI.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
1355+
UsesZA |= FunctionType::getArmZAState(EPI.AArch64SMEAttributes) !=
1356+
FunctionType::ARM_None;
1357+
UsesZT0 |= FunctionType::getArmZT0State(EPI.AArch64SMEAttributes) !=
1358+
FunctionType::ARM_None;
1359+
}
1360+
1361+
ASTContext &Context = getASTContext();
1362+
if (UsesSM || UsesZA) {
1363+
llvm::StringMap<bool> FeatureMap;
1364+
Context.getFunctionFeatureMap(FeatureMap, FD);
1365+
if (!FeatureMap.contains("sme")) {
1366+
if (UsesSM)
1367+
Diag(FD->getLocation(),
1368+
diag::err_sme_definition_using_sm_in_non_sme_target);
1369+
else
1370+
Diag(FD->getLocation(),
1371+
diag::err_sme_definition_using_za_in_non_sme_target);
1372+
}
1373+
}
1374+
if (UsesZT0) {
1375+
llvm::StringMap<bool> FeatureMap;
1376+
Context.getFunctionFeatureMap(FeatureMap, FD);
1377+
if (!FeatureMap.contains("sme2")) {
1378+
Diag(FD->getLocation(),
1379+
diag::err_sme_definition_using_zt0_in_non_sme2_target);
1380+
}
1381+
}
1382+
}
1383+
13311384
} // namespace clang

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "clang/Sema/ParsedTemplate.h"
4646
#include "clang/Sema/Scope.h"
4747
#include "clang/Sema/ScopeInfo.h"
48+
#include "clang/Sema/SemaARM.h"
4849
#include "clang/Sema/SemaCUDA.h"
4950
#include "clang/Sema/SemaHLSL.h"
5051
#include "clang/Sema/SemaInternal.h"
@@ -12286,58 +12287,8 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
1228612287
}
1228712288
}
1228812289

12289-
// Check if the function definition uses any AArch64 SME features without
12290-
// having the '+sme' feature enabled and warn user if sme locally streaming
12291-
// function returns or uses arguments with VL-based types.
12292-
if (DeclIsDefn) {
12293-
const auto *Attr = NewFD->getAttr<ArmNewAttr>();
12294-
bool UsesSM = NewFD->hasAttr<ArmLocallyStreamingAttr>();
12295-
bool UsesZA = Attr && Attr->isNewZA();
12296-
bool UsesZT0 = Attr && Attr->isNewZT0();
12297-
12298-
if (NewFD->hasAttr<ArmLocallyStreamingAttr>()) {
12299-
if (NewFD->getReturnType()->isSizelessVectorType())
12300-
Diag(NewFD->getLocation(),
12301-
diag::warn_sme_locally_streaming_has_vl_args_returns)
12302-
<< /*IsArg=*/false;
12303-
if (llvm::any_of(NewFD->parameters(), [](ParmVarDecl *P) {
12304-
return P->getOriginalType()->isSizelessVectorType();
12305-
}))
12306-
Diag(NewFD->getLocation(),
12307-
diag::warn_sme_locally_streaming_has_vl_args_returns)
12308-
<< /*IsArg=*/true;
12309-
}
12310-
if (const auto *FPT = NewFD->getType()->getAs<FunctionProtoType>()) {
12311-
FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
12312-
UsesSM |=
12313-
EPI.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
12314-
UsesZA |= FunctionType::getArmZAState(EPI.AArch64SMEAttributes) !=
12315-
FunctionType::ARM_None;
12316-
UsesZT0 |= FunctionType::getArmZT0State(EPI.AArch64SMEAttributes) !=
12317-
FunctionType::ARM_None;
12318-
}
12319-
12320-
if (UsesSM || UsesZA) {
12321-
llvm::StringMap<bool> FeatureMap;
12322-
Context.getFunctionFeatureMap(FeatureMap, NewFD);
12323-
if (!FeatureMap.contains("sme")) {
12324-
if (UsesSM)
12325-
Diag(NewFD->getLocation(),
12326-
diag::err_sme_definition_using_sm_in_non_sme_target);
12327-
else
12328-
Diag(NewFD->getLocation(),
12329-
diag::err_sme_definition_using_za_in_non_sme_target);
12330-
}
12331-
}
12332-
if (UsesZT0) {
12333-
llvm::StringMap<bool> FeatureMap;
12334-
Context.getFunctionFeatureMap(FeatureMap, NewFD);
12335-
if (!FeatureMap.contains("sme2")) {
12336-
Diag(NewFD->getLocation(),
12337-
diag::err_sme_definition_using_zt0_in_non_sme2_target);
12338-
}
12339-
}
12340-
}
12290+
if (DeclIsDefn && Context.getTargetInfo().getTriple().isAArch64())
12291+
ARM().CheckSMEFunctionDefAttributes(NewFD);
1234112292

1234212293
return Redeclaration;
1234312294
}

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "clang/Sema/ParsedTemplate.h"
4242
#include "clang/Sema/Scope.h"
4343
#include "clang/Sema/ScopeInfo.h"
44+
#include "clang/Sema/SemaARM.h"
4445
#include "clang/Sema/SemaCUDA.h"
4546
#include "clang/Sema/SemaInternal.h"
4647
#include "clang/Sema/SemaObjC.h"
@@ -1854,27 +1855,8 @@ bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD,
18541855
}
18551856
}
18561857

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-
}
1858+
if (Context.getTargetInfo().getTriple().isAArch64())
1859+
ARM().CheckSMEFunctionDefAttributes(NewFD);
18781860

18791861
// - each of its parameter types shall be a literal type; (removed in C++23)
18801862
if (!getLangOpts().CPlusPlus23 &&

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void streaming_compatible_def2(void (*streaming_fn_ptr)(void) __arm_streaming,
4949
int streaming_decl_ret_int() __arm_streaming;
5050
int x = streaming_decl_ret_int(); // expected-error {{call to a streaming function requires 'sme'}}
5151

52-
void sme_attrs_method_decls() {
52+
void sme_attrs_lambdas() {
5353
[&] __arm_locally_streaming () { return; }(); // expected-error {{function executed in streaming-SVE mode requires 'sme'}}
5454
[&] __arm_new("za") () { return; }(); // expected-error {{function using ZA state requires 'sme'}}
5555
[&] __arm_new("zt0") () { return; }(); // expected-error {{function using ZT0 state requires 'sme2'}}

0 commit comments

Comments
 (0)