@@ -366,12 +366,14 @@ enum TypeAttrLocation {
366
366
TAL_DeclName
367
367
};
368
368
369
- static void processTypeAttrs(TypeProcessingState &state, QualType &type,
370
- TypeAttrLocation TAL,
371
- const ParsedAttributesView &attrs);
369
+ static void
370
+ processTypeAttrs(TypeProcessingState &state, QualType &type,
371
+ TypeAttrLocation TAL, const ParsedAttributesView &attrs,
372
+ Sema::CUDAFunctionTarget CFT = Sema::CFT_HostDevice);
372
373
373
374
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
374
- QualType &type);
375
+ QualType &type,
376
+ Sema::CUDAFunctionTarget CFT);
375
377
376
378
static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &state,
377
379
ParsedAttr &attr, QualType &type);
@@ -617,7 +619,8 @@ static void distributeFunctionTypeAttr(TypeProcessingState &state,
617
619
/// distributed, false if no location was found.
618
620
static bool distributeFunctionTypeAttrToInnermost(
619
621
TypeProcessingState &state, ParsedAttr &attr,
620
- ParsedAttributesView &attrList, QualType &declSpecType) {
622
+ ParsedAttributesView &attrList, QualType &declSpecType,
623
+ Sema::CUDAFunctionTarget CFT) {
621
624
Declarator &declarator = state.getDeclarator();
622
625
623
626
// Put it on the innermost function chunk, if there is one.
@@ -629,19 +632,20 @@ static bool distributeFunctionTypeAttrToInnermost(
629
632
return true;
630
633
}
631
634
632
- return handleFunctionTypeAttr(state, attr, declSpecType);
635
+ return handleFunctionTypeAttr(state, attr, declSpecType, CFT );
633
636
}
634
637
635
638
/// A function type attribute was written in the decl spec. Try to
636
639
/// apply it somewhere.
637
- static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
638
- ParsedAttr &attr,
639
- QualType &declSpecType) {
640
+ static void
641
+ distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
642
+ ParsedAttr &attr, QualType &declSpecType,
643
+ Sema::CUDAFunctionTarget CFT) {
640
644
state.saveDeclSpecAttrs();
641
645
642
646
// Try to distribute to the innermost.
643
647
if (distributeFunctionTypeAttrToInnermost(
644
- state, attr, state.getCurrentAttributes(), declSpecType))
648
+ state, attr, state.getCurrentAttributes(), declSpecType, CFT ))
645
649
return;
646
650
647
651
// If that failed, diagnose the bad attribute when the declarator is
@@ -653,14 +657,14 @@ static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
653
657
/// Try to apply it somewhere.
654
658
/// `Attrs` is the attribute list containing the declaration (either of the
655
659
/// declarator or the declaration).
656
- static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
657
- ParsedAttr &attr,
658
- QualType &declSpecType ) {
660
+ static void distributeFunctionTypeAttrFromDeclarator(
661
+ TypeProcessingState &state, ParsedAttr &attr, QualType &declSpecType ,
662
+ Sema::CUDAFunctionTarget CFT ) {
659
663
Declarator &declarator = state.getDeclarator();
660
664
661
665
// Try to distribute to the innermost.
662
666
if (distributeFunctionTypeAttrToInnermost(
663
- state, attr, declarator.getAttributes(), declSpecType))
667
+ state, attr, declarator.getAttributes(), declSpecType, CFT ))
664
668
return;
665
669
666
670
// If that failed, diagnose the bad attribute when the declarator is
@@ -682,7 +686,8 @@ static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
682
686
/// `Attrs` is the attribute list containing the declaration (either of the
683
687
/// declarator or the declaration).
684
688
static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
685
- QualType &declSpecType) {
689
+ QualType &declSpecType,
690
+ Sema::CUDAFunctionTarget CFT) {
686
691
// The called functions in this loop actually remove things from the current
687
692
// list, so iterating over the existing list isn't possible. Instead, make a
688
693
// non-owning copy and iterate over that.
@@ -699,7 +704,7 @@ static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
699
704
break;
700
705
701
706
FUNCTION_TYPE_ATTRS_CASELIST:
702
- distributeFunctionTypeAttrFromDeclarator(state, attr, declSpecType);
707
+ distributeFunctionTypeAttrFromDeclarator(state, attr, declSpecType, CFT );
703
708
break;
704
709
705
710
MS_TYPE_ATTRS_CASELIST:
@@ -3544,7 +3549,8 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
3544
3549
// Note: We don't need to distribute declaration attributes (i.e.
3545
3550
// D.getDeclarationAttributes()) because those are always C++11 attributes,
3546
3551
// and those don't get distributed.
3547
- distributeTypeAttrsFromDeclarator(state, T);
3552
+ distributeTypeAttrsFromDeclarator(
3553
+ state, T, SemaRef.IdentifyCUDATarget(D.getAttributes()));
3548
3554
3549
3555
// Find the deduced type in this type. Look in the trailing return type if we
3550
3556
// have one, otherwise in the DeclSpec type.
@@ -4055,7 +4061,8 @@ static CallingConv getCCForDeclaratorChunk(
4055
4061
// function type. We'll diagnose the failure to apply them in
4056
4062
// handleFunctionTypeAttr.
4057
4063
CallingConv CC;
4058
- if (!S.CheckCallingConvAttr(AL, CC) &&
4064
+ if (!S.CheckCallingConvAttr(AL, CC, /*FunctionDecl=*/nullptr,
4065
+ S.IdentifyCUDATarget(D.getAttributes())) &&
4059
4066
(!FTI.isVariadic || supportsVariadicCall(CC))) {
4060
4067
return CC;
4061
4068
}
@@ -5727,7 +5734,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
5727
5734
}
5728
5735
5729
5736
// See if there are any attributes on this declarator chunk.
5730
- processTypeAttrs(state, T, TAL_DeclChunk, DeclType.getAttrs());
5737
+ processTypeAttrs(state, T, TAL_DeclChunk, DeclType.getAttrs(),
5738
+ S.IdentifyCUDATarget(D.getAttributes()));
5731
5739
5732
5740
if (DeclType.Kind != DeclaratorChunk::Paren) {
5733
5741
if (ExpectNoDerefChunk && !IsNoDerefableChunk(DeclType))
@@ -7801,7 +7809,8 @@ static bool checkMutualExclusion(TypeProcessingState &state,
7801
7809
/// Process an individual function attribute. Returns true to
7802
7810
/// indicate that the attribute was handled, false if it wasn't.
7803
7811
static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
7804
- QualType &type) {
7812
+ QualType &type,
7813
+ Sema::CUDAFunctionTarget CFT) {
7805
7814
Sema &S = state.getSema();
7806
7815
7807
7816
FunctionTypeUnwrapper unwrapped(S, type);
@@ -8032,7 +8041,7 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
8032
8041
8033
8042
// Otherwise, a calling convention.
8034
8043
CallingConv CC;
8035
- if (S.CheckCallingConvAttr(attr, CC))
8044
+ if (S.CheckCallingConvAttr(attr, CC, /*FunctionDecl=*/nullptr, CFT ))
8036
8045
return true;
8037
8046
8038
8047
const FunctionType *fn = unwrapped.get();
@@ -8584,7 +8593,8 @@ static void HandleLifetimeBoundAttr(TypeProcessingState &State,
8584
8593
8585
8594
static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8586
8595
TypeAttrLocation TAL,
8587
- const ParsedAttributesView &attrs) {
8596
+ const ParsedAttributesView &attrs,
8597
+ Sema::CUDAFunctionTarget CFT) {
8588
8598
8589
8599
state.setParsedNoDeref(false);
8590
8600
if (attrs.empty())
@@ -8826,7 +8836,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8826
8836
// appertain to and hence should not use the "distribution" logic below.
8827
8837
if (attr.isStandardAttributeSyntax() ||
8828
8838
attr.isRegularKeywordAttribute()) {
8829
- if (!handleFunctionTypeAttr(state, attr, type)) {
8839
+ if (!handleFunctionTypeAttr(state, attr, type, CFT )) {
8830
8840
diagnoseBadTypeAttribute(state.getSema(), attr, type);
8831
8841
attr.setInvalid();
8832
8842
}
@@ -8836,10 +8846,10 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
8836
8846
// Never process function type attributes as part of the
8837
8847
// declaration-specifiers.
8838
8848
if (TAL == TAL_DeclSpec)
8839
- distributeFunctionTypeAttrFromDeclSpec(state, attr, type);
8849
+ distributeFunctionTypeAttrFromDeclSpec(state, attr, type, CFT );
8840
8850
8841
8851
// Otherwise, handle the possible delays.
8842
- else if (!handleFunctionTypeAttr(state, attr, type))
8852
+ else if (!handleFunctionTypeAttr(state, attr, type, CFT ))
8843
8853
distributeFunctionTypeAttr(state, attr, type);
8844
8854
break;
8845
8855
case ParsedAttr::AT_AcquireHandle: {
0 commit comments