@@ -366,12 +366,14 @@ enum TypeAttrLocation {
366366 TAL_DeclName
367367};
368368
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);
372373
373374static bool handleFunctionTypeAttr (TypeProcessingState &state, ParsedAttr &attr,
374- QualType &type);
375+ QualType &type,
376+ Sema::CUDAFunctionTarget CFT);
375377
376378static bool handleMSPointerTypeQualifierAttr (TypeProcessingState &state,
377379 ParsedAttr &attr, QualType &type);
@@ -617,7 +619,8 @@ static void distributeFunctionTypeAttr(TypeProcessingState &state,
617619// / distributed, false if no location was found.
618620static bool distributeFunctionTypeAttrToInnermost (
619621 TypeProcessingState &state, ParsedAttr &attr,
620- ParsedAttributesView &attrList, QualType &declSpecType) {
622+ ParsedAttributesView &attrList, QualType &declSpecType,
623+ Sema::CUDAFunctionTarget CFT) {
621624 Declarator &declarator = state.getDeclarator ();
622625
623626 // Put it on the innermost function chunk, if there is one.
@@ -629,19 +632,20 @@ static bool distributeFunctionTypeAttrToInnermost(
629632 return true ;
630633 }
631634
632- return handleFunctionTypeAttr (state, attr, declSpecType);
635+ return handleFunctionTypeAttr (state, attr, declSpecType, CFT );
633636}
634637
635638// / A function type attribute was written in the decl spec. Try to
636639// / 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) {
640644 state.saveDeclSpecAttrs ();
641645
642646 // Try to distribute to the innermost.
643647 if (distributeFunctionTypeAttrToInnermost (
644- state, attr, state.getCurrentAttributes (), declSpecType))
648+ state, attr, state.getCurrentAttributes (), declSpecType, CFT ))
645649 return ;
646650
647651 // If that failed, diagnose the bad attribute when the declarator is
@@ -653,14 +657,14 @@ static void distributeFunctionTypeAttrFromDeclSpec(TypeProcessingState &state,
653657// / Try to apply it somewhere.
654658// / `Attrs` is the attribute list containing the declaration (either of the
655659// / 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 ) {
659663 Declarator &declarator = state.getDeclarator ();
660664
661665 // Try to distribute to the innermost.
662666 if (distributeFunctionTypeAttrToInnermost (
663- state, attr, declarator.getAttributes (), declSpecType))
667+ state, attr, declarator.getAttributes (), declSpecType, CFT ))
664668 return ;
665669
666670 // If that failed, diagnose the bad attribute when the declarator is
@@ -682,7 +686,8 @@ static void distributeFunctionTypeAttrFromDeclarator(TypeProcessingState &state,
682686// / `Attrs` is the attribute list containing the declaration (either of the
683687// / declarator or the declaration).
684688static void distributeTypeAttrsFromDeclarator (TypeProcessingState &state,
685- QualType &declSpecType) {
689+ QualType &declSpecType,
690+ Sema::CUDAFunctionTarget CFT) {
686691 // The called functions in this loop actually remove things from the current
687692 // list, so iterating over the existing list isn't possible. Instead, make a
688693 // non-owning copy and iterate over that.
@@ -699,7 +704,7 @@ static void distributeTypeAttrsFromDeclarator(TypeProcessingState &state,
699704 break ;
700705
701706 FUNCTION_TYPE_ATTRS_CASELIST:
702- distributeFunctionTypeAttrFromDeclarator (state, attr, declSpecType);
707+ distributeFunctionTypeAttrFromDeclarator (state, attr, declSpecType, CFT );
703708 break ;
704709
705710 MS_TYPE_ATTRS_CASELIST:
@@ -3544,7 +3549,8 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
35443549 // Note: We don't need to distribute declaration attributes (i.e.
35453550 // D.getDeclarationAttributes()) because those are always C++11 attributes,
35463551 // and those don't get distributed.
3547- distributeTypeAttrsFromDeclarator (state, T);
3552+ distributeTypeAttrsFromDeclarator (
3553+ state, T, SemaRef.IdentifyCUDATarget (D.getAttributes ()));
35483554
35493555 // Find the deduced type in this type. Look in the trailing return type if we
35503556 // have one, otherwise in the DeclSpec type.
@@ -4055,7 +4061,8 @@ static CallingConv getCCForDeclaratorChunk(
40554061 // function type. We'll diagnose the failure to apply them in
40564062 // handleFunctionTypeAttr.
40574063 CallingConv CC;
4058- if (!S.CheckCallingConvAttr (AL, CC) &&
4064+ if (!S.CheckCallingConvAttr (AL, CC, /* FunctionDecl=*/ nullptr ,
4065+ S.IdentifyCUDATarget (D.getAttributes ())) &&
40594066 (!FTI.isVariadic || supportsVariadicCall (CC))) {
40604067 return CC;
40614068 }
@@ -5727,7 +5734,8 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
57275734 }
57285735
57295736 // 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 ()));
57315739
57325740 if (DeclType.Kind != DeclaratorChunk::Paren) {
57335741 if (ExpectNoDerefChunk && !IsNoDerefableChunk (DeclType))
@@ -7801,7 +7809,8 @@ static bool checkMutualExclusion(TypeProcessingState &state,
78017809// / Process an individual function attribute. Returns true to
78027810// / indicate that the attribute was handled, false if it wasn't.
78037811static bool handleFunctionTypeAttr (TypeProcessingState &state, ParsedAttr &attr,
7804- QualType &type) {
7812+ QualType &type,
7813+ Sema::CUDAFunctionTarget CFT) {
78057814 Sema &S = state.getSema ();
78067815
78077816 FunctionTypeUnwrapper unwrapped (S, type);
@@ -8032,7 +8041,7 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
80328041
80338042 // Otherwise, a calling convention.
80348043 CallingConv CC;
8035- if (S.CheckCallingConvAttr (attr, CC))
8044+ if (S.CheckCallingConvAttr (attr, CC, /* FunctionDecl= */ nullptr , CFT ))
80368045 return true ;
80378046
80388047 const FunctionType *fn = unwrapped.get ();
@@ -8584,7 +8593,8 @@ static void HandleLifetimeBoundAttr(TypeProcessingState &State,
85848593
85858594static void processTypeAttrs (TypeProcessingState &state, QualType &type,
85868595 TypeAttrLocation TAL,
8587- const ParsedAttributesView &attrs) {
8596+ const ParsedAttributesView &attrs,
8597+ Sema::CUDAFunctionTarget CFT) {
85888598
85898599 state.setParsedNoDeref (false );
85908600 if (attrs.empty ())
@@ -8826,7 +8836,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
88268836 // appertain to and hence should not use the "distribution" logic below.
88278837 if (attr.isStandardAttributeSyntax () ||
88288838 attr.isRegularKeywordAttribute ()) {
8829- if (!handleFunctionTypeAttr (state, attr, type)) {
8839+ if (!handleFunctionTypeAttr (state, attr, type, CFT )) {
88308840 diagnoseBadTypeAttribute (state.getSema (), attr, type);
88318841 attr.setInvalid ();
88328842 }
@@ -8836,10 +8846,10 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
88368846 // Never process function type attributes as part of the
88378847 // declaration-specifiers.
88388848 if (TAL == TAL_DeclSpec)
8839- distributeFunctionTypeAttrFromDeclSpec (state, attr, type);
8849+ distributeFunctionTypeAttrFromDeclSpec (state, attr, type, CFT );
88408850
88418851 // Otherwise, handle the possible delays.
8842- else if (!handleFunctionTypeAttr (state, attr, type))
8852+ else if (!handleFunctionTypeAttr (state, attr, type, CFT ))
88438853 distributeFunctionTypeAttr (state, attr, type);
88448854 break ;
88458855 case ParsedAttr::AT_AcquireHandle: {
0 commit comments