Skip to content

Commit 02658f7

Browse files
- Mark CheckSMEFunctionDefAttributes as static
- Move CheckSMEFunctionDefAttributes call to ActOnStartOfLambdaDefinition
1 parent bbc80c2 commit 02658f7

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

clang/include/clang/Sema/SemaARM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ 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);
82+
83+
static void CheckSMEFunctionDefAttributes(const FunctionDecl *FD, Sema &S);
8384
};
8485

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

clang/lib/Sema/SemaARM.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,22 +1331,22 @@ void SemaARM::handleInterruptAttr(Decl *D, const ParsedAttr &AL) {
13311331
// Check if the function definition uses any AArch64 SME features without
13321332
// having the '+sme' feature enabled and warn user if sme locally streaming
13331333
// function returns or uses arguments with VL-based types.
1334-
void SemaARM::CheckSMEFunctionDefAttributes(const FunctionDecl *FD) {
1334+
void SemaARM::CheckSMEFunctionDefAttributes(const FunctionDecl *FD, Sema &S) {
13351335
const auto *Attr = FD->getAttr<ArmNewAttr>();
13361336
bool UsesSM = FD->hasAttr<ArmLocallyStreamingAttr>();
13371337
bool UsesZA = Attr && Attr->isNewZA();
13381338
bool UsesZT0 = Attr && Attr->isNewZT0();
13391339

13401340
if (FD->hasAttr<ArmLocallyStreamingAttr>()) {
13411341
if (FD->getReturnType()->isSizelessVectorType())
1342-
Diag(FD->getLocation(),
1343-
diag::warn_sme_locally_streaming_has_vl_args_returns)
1342+
S.Diag(FD->getLocation(),
1343+
diag::warn_sme_locally_streaming_has_vl_args_returns)
13441344
<< /*IsArg=*/false;
13451345
if (llvm::any_of(FD->parameters(), [](ParmVarDecl *P) {
13461346
return P->getOriginalType()->isSizelessVectorType();
13471347
}))
1348-
Diag(FD->getLocation(),
1349-
diag::warn_sme_locally_streaming_has_vl_args_returns)
1348+
S.Diag(FD->getLocation(),
1349+
diag::warn_sme_locally_streaming_has_vl_args_returns)
13501350
<< /*IsArg=*/true;
13511351
}
13521352
if (const auto *FPT = FD->getType()->getAs<FunctionProtoType>()) {
@@ -1358,25 +1358,25 @@ void SemaARM::CheckSMEFunctionDefAttributes(const FunctionDecl *FD) {
13581358
FunctionType::ARM_None;
13591359
}
13601360

1361-
ASTContext &Context = getASTContext();
1361+
ASTContext &Context = S.getASTContext();
13621362
if (UsesSM || UsesZA) {
13631363
llvm::StringMap<bool> FeatureMap;
13641364
Context.getFunctionFeatureMap(FeatureMap, FD);
13651365
if (!FeatureMap.contains("sme")) {
13661366
if (UsesSM)
1367-
Diag(FD->getLocation(),
1368-
diag::err_sme_definition_using_sm_in_non_sme_target);
1367+
S.Diag(FD->getLocation(),
1368+
diag::err_sme_definition_using_sm_in_non_sme_target);
13691369
else
1370-
Diag(FD->getLocation(),
1371-
diag::err_sme_definition_using_za_in_non_sme_target);
1370+
S.Diag(FD->getLocation(),
1371+
diag::err_sme_definition_using_za_in_non_sme_target);
13721372
}
13731373
}
13741374
if (UsesZT0) {
13751375
llvm::StringMap<bool> FeatureMap;
13761376
Context.getFunctionFeatureMap(FeatureMap, FD);
13771377
if (!FeatureMap.contains("sme2")) {
1378-
Diag(FD->getLocation(),
1379-
diag::err_sme_definition_using_zt0_in_non_sme2_target);
1378+
S.Diag(FD->getLocation(),
1379+
diag::err_sme_definition_using_zt0_in_non_sme2_target);
13801380
}
13811381
}
13821382
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12288,7 +12288,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
1228812288
}
1228912289

1229012290
if (DeclIsDefn && Context.getTargetInfo().getTriple().isAArch64())
12291-
ARM().CheckSMEFunctionDefAttributes(NewFD);
12291+
SemaARM::CheckSMEFunctionDefAttributes(NewFD, *this);
1229212292

1229312293
return Redeclaration;
1229412294
}

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "clang/Sema/ParsedTemplate.h"
4242
#include "clang/Sema/Scope.h"
4343
#include "clang/Sema/ScopeInfo.h"
44-
#include "clang/Sema/SemaARM.h"
4544
#include "clang/Sema/SemaCUDA.h"
4645
#include "clang/Sema/SemaInternal.h"
4746
#include "clang/Sema/SemaObjC.h"
@@ -1855,9 +1854,6 @@ bool Sema::CheckConstexprFunctionDefinition(const FunctionDecl *NewFD,
18551854
}
18561855
}
18571856

1858-
if (Context.getTargetInfo().getTriple().isAArch64())
1859-
ARM().CheckSMEFunctionDefAttributes(NewFD);
1860-
18611857
// - each of its parameter types shall be a literal type; (removed in C++23)
18621858
if (!getLangOpts().CPlusPlus23 &&
18631859
!CheckConstexprParameterTypes(*this, NewFD, Kind))

clang/lib/Sema/SemaLambda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/Sema/Lookup.h"
2222
#include "clang/Sema/Scope.h"
2323
#include "clang/Sema/ScopeInfo.h"
24+
#include "clang/Sema/SemaARM.h"
2425
#include "clang/Sema/SemaCUDA.h"
2526
#include "clang/Sema/SemaInternal.h"
2627
#include "clang/Sema/SemaOpenMP.h"
@@ -1454,6 +1455,9 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
14541455
// Attributes on the lambda apply to the method.
14551456
ProcessDeclAttributes(CurScope, Method, ParamInfo);
14561457

1458+
if (Context.getTargetInfo().getTriple().isAArch64())
1459+
SemaARM::CheckSMEFunctionDefAttributes(Method, *this);
1460+
14571461
// CUDA lambdas get implicit host and device attributes.
14581462
if (getLangOpts().CUDA)
14591463
CUDA().SetLambdaAttrs(Method);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int streaming_decl_ret_int() __arm_streaming;
5050
int x = streaming_decl_ret_int(); // expected-error {{call to a streaming function requires 'sme'}}
5151

5252
void sme_attrs_lambdas() {
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'}}
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'}}
5656
}

0 commit comments

Comments
 (0)