@@ -359,12 +359,14 @@ enum TypeAttrLocation {
359
359
TAL_DeclName
360
360
};
361
361
362
- static void processTypeAttrs(TypeProcessingState &state, QualType &type,
363
- TypeAttrLocation TAL,
364
- const ParsedAttributesView &attrs);
362
+ static void
363
+ processTypeAttrs(TypeProcessingState &state, QualType &type,
364
+ TypeAttrLocation TAL, const ParsedAttributesView &attrs,
365
+ Sema::CUDAFunctionTarget CFT = Sema::CFT_HostDevice);
365
366
366
367
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
367
- QualType &type);
368
+ QualType &type,
369
+ Sema::CUDAFunctionTarget CFT);
368
370
369
371
static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &state,
370
372
ParsedAttr &attr, QualType &type);
@@ -610,7 +612,8 @@ static void distributeFunctionTypeAttr(TypeProcessingState &state,
610
612
/// distributed, false if no location was found.
611
613
static bool distributeFunctionTypeAttrToInnermost(
612
614
TypeProcessingState &state, ParsedAttr &attr,
613
- ParsedAttributesView &attrList, QualType &declSpecType) {
615
+ ParsedAttributesView &attrList, QualType &declSpecType,
616
+ Sema::CUDAFunctionTarget CFT) {
614
617
Declarator &declarator = state.getDeclarator();
615
618
616
619
// Put it on the innermost function chunk, if there is one.
@@ -622,19 +625,20 @@ static bool distributeFunctionTypeAttrToInnermost(
622
625
return true;
623
626
}
624
627
625
- return handleFunctionTypeAttr(state, attr, declSpecType);
628
+ return handleFunctionTypeAttr(state, attr, declSpecType, CFT );
626
629
}
627
630
628
631
/// A function type attribute was written in the decl spec. Try to
629
632
/// apply it somewhere.
630
- static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
631
- ParsedAttr &attr,
632
- QualType &declSpecType) {
633
+ static void
634
+ distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
635
+ ParsedAttr &attr, QualType &declSpecType,
636
+ Sema::CUDAFunctionTarget CFT) {
633
637
state.saveDeclSpecAttrs();
634
638
635
639
// Try to distribute to the innermost.
636
640
if (distributeFunctionTypeAttrToInnermost(
637
- state, attr, state.getCurrentAttributes(), declSpecType))
641
+ state, attr, state.getCurrentAttributes(), declSpecType, CFT ))
638
642
return;
639
643
640
644
// If that failed, diagnose the bad attribute when the declarator is
@@ -646,14 +650,14 @@ static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
646
650
/// Try to apply it somewhere.
647
651
/// `Attrs` is the attribute list containing the declaration (either of the
648
652
/// declarator or the declaration).
649
- static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
650
- ParsedAttr &attr,
651
- QualType &declSpecType ) {
653
+ static void distributeFunctionTypeAttrFromDeclarator(
654
+ TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType ,
655
+ Sema::CUDAFunctionTarget CFT ) {
652
656
Declarator &declarator = state.getDeclarator();
653
657
654
658
// Try to distribute to the innermost.
655
659
if (distributeFunctionTypeAttrToInnermost(
656
- state, attr, declarator.getAttributes(), declSpecType))
660
+ state, attr, declarator.getAttributes(), declSpecType, CFT ))
657
661
return;
658
662
659
663
// If that failed, diagnose the bad attribute when the declarator is
@@ -675,7 +679,8 @@ static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
675
679
/// `Attrs` is the attribute list containing the declaration (either of the
676
680
/// declarator or the declaration).
677
681
static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
678
- QualType &declSpecType) {
682
+ QualType &declSpecType,
683
+ Sema::CUDAFunctionTarget CFT) {
679
684
// The called functions in this loop actually remove things from the current
680
685
// list, so iterating over the existing list isn't possible. Instead, make a
681
686
// non-owning copy and iterate over that.
@@ -692,7 +697,7 @@ static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
692
697
break;
693
698
694
699
FUNCTION_TYPE_ATTRS_CASELIST:
695
- distributeFunctionTypeAttrFromDeclarator(state, attr, declSpecType);
700
+ distributeFunctionTypeAttrFromDeclarator(state, attr, declSpecType, CFT );
696
701
break;
697
702
698
703
MS_TYPE_ATTRS_CASELIST:
@@ -3510,7 +3515,8 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
3510
3515
// Note: We don't need to distribute declaration attributes (i.e.
3511
3516
// D.getDeclarationAttributes()) because those are always C++11 attributes,
3512
3517
// and those don't get distributed.
3513
- distributeTypeAttrsFromDeclarator(state, T);
3518
+ distributeTypeAttrsFromDeclarator(
3519
+ state, T, SemaRef.IdentifyCUDATarget(D.getAttributes()));
3514
3520
3515
3521
// Find the deduced type in this type. Look in the trailing return type if we
3516
3522
// have one, otherwise in the DeclSpec type.
@@ -4021,7 +4027,8 @@ static CallingConv getCCForDeclaratorChunk(
4021
4027
// function type. We'll diagnose the failure to apply them in
4022
4028
// handleFunctionTypeAttr.
4023
4029
CallingConv CC;
4024
- if (!S.CheckCallingConvAttr(AL, CC) &&
4030
+ if (!S.CheckCallingConvAttr(AL, CC, /*FunctionDecl=*/nullptr,
4031
+ S.IdentifyCUDATarget(D.getAttributes())) &&
4025
4032
(!FTI.isVariadic || supportsVariadicCall(CC))) {
4026
4033
return CC;
4027
4034
}
@@ -5665,7 +5672,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
5665
5672
}
5666
5673
5667
5674
// See if there are any attributes on this declarator chunk.
5668
- processTypeAttrs(state, T, TAL_DeclChunk, DeclType.getAttrs());
5675
+ processTypeAttrs(state, T, TAL_DeclChunk, DeclType.getAttrs(),
5676
+ S.IdentifyCUDATarget(D.getAttributes()));
5669
5677
5670
5678
if (DeclType.Kind != DeclaratorChunk::Paren) {
5671
5679
if (ExpectNoDerefChunk && !IsNoDerefableChunk(DeclType))
@@ -7709,7 +7717,8 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) {
7709
7717
/// Process an individual function attribute. Returns true to
7710
7718
/// indicate that the attribute was handled, false if it wasn't.
7711
7719
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
7712
- QualType &type) {
7720
+ QualType &type,
7721
+ Sema::CUDAFunctionTarget CFT) {
7713
7722
Sema &S = state.getSema();
7714
7723
7715
7724
FunctionTypeUnwrapper unwrapped(S, type);
@@ -7891,7 +7900,7 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
7891
7900
7892
7901
// Otherwise, a calling convention.
7893
7902
CallingConv CC;
7894
- if (S.CheckCallingConvAttr(attr, CC))
7903
+ if (S.CheckCallingConvAttr(attr, CC, /*FunctionDecl=*/nullptr, CFT ))
7895
7904
return true;
7896
7905
7897
7906
const FunctionType *fn = unwrapped.get();
@@ -8369,7 +8378,8 @@ static void HandleLifetimeBoundAttr(TypeProcessingState &State,
8369
8378
8370
8379
static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8371
8380
TypeAttrLocation TAL,
8372
- const ParsedAttributesView &attrs) {
8381
+ const ParsedAttributesView &attrs,
8382
+ Sema::CUDAFunctionTarget CFT) {
8373
8383
8374
8384
state.setParsedNoDeref(false);
8375
8385
if (attrs.empty())
@@ -8603,7 +8613,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8603
8613
// Attributes with standard syntax have strict rules for what they
8604
8614
// appertain to and hence should not use the "distribution" logic below.
8605
8615
if (attr.isStandardAttributeSyntax()) {
8606
- if (!handleFunctionTypeAttr(state, attr, type)) {
8616
+ if (!handleFunctionTypeAttr(state, attr, type, CFT )) {
8607
8617
diagnoseBadTypeAttribute(state.getSema(), attr, type);
8608
8618
attr.setInvalid();
8609
8619
}
@@ -8613,10 +8623,10 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8613
8623
// Never process function type attributes as part of the
8614
8624
// declaration-specifiers.
8615
8625
if (TAL == TAL_DeclSpec)
8616
- distributeFunctionTypeAttrFromDeclSpec(state, attr, type);
8626
+ distributeFunctionTypeAttrFromDeclSpec(state, attr, type, CFT );
8617
8627
8618
8628
// Otherwise, handle the possible delays.
8619
- else if (!handleFunctionTypeAttr(state, attr, type))
8629
+ else if (!handleFunctionTypeAttr(state, attr, type, CFT ))
8620
8630
distributeFunctionTypeAttr(state, attr, type);
8621
8631
break;
8622
8632
case ParsedAttr::AT_AcquireHandle: {
0 commit comments