@@ -684,11 +684,13 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) {
684684 }
685685 }
686686
687- // FIXME: This should be getSemanticAttrs if we want to walk macro
688- // expansions. We've just already typechecked and this list is mutable so...
689- for (auto *customAttr : D->getAttrs ().getAttributes <CustomAttr, true >()) {
690- if (!shouldWalkMacroArgumentsAndExpansion ().second &&
691- D->getModuleContext ()->isInGeneratedBuffer (customAttr->getLocation ()))
687+ ModuleDecl *MD = D->getModuleContext ();
688+ for (auto *customAttr :
689+ D->getSemanticAttrs ().getAttributes <CustomAttr, true >()) {
690+ SourceFile *SF =
691+ MD->getSourceFileContainingLocation (customAttr->getLocation ());
692+ ASTNode expansion = SF ? SF->getMacroExpansion () : nullptr ;
693+ if (!shouldWalkMacroArgumentsAndExpansion ().second && expansion)
692694 continue ;
693695
694696 if (auto *Repr = customAttr->getTypeRepr ()) {
@@ -700,10 +702,12 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) {
700702 if (auto macroDecl = D->getResolvedMacro (mutableAttr)) {
701703 Type macroRefType = macroDecl->getDeclaredInterfaceType ();
702704 if (!passReference (
703- macroDecl, macroRefType, DeclNameLoc (Repr->getStartLoc ()),
704- ReferenceMetaData (SemaReferenceKind::DeclRef, None,
705- /* isImplicit=*/ false ,
706- std::make_pair (customAttr, D))))
705+ macroDecl, macroRefType, DeclNameLoc (Repr->getStartLoc ()),
706+ ReferenceMetaData (
707+ SemaReferenceKind::DeclRef, None,
708+ /* isImplicit=*/ false ,
709+ std::make_pair (customAttr,
710+ expansion ? expansion.get <Decl *>() : D))))
707711 return false ;
708712 } else if (!Repr->walk (*this )) {
709713 return false ;
@@ -865,9 +869,23 @@ bool SemaAnnotator::passCallArgNames(Expr *Fn, ArgumentList *ArgList) {
865869}
866870
867871bool SemaAnnotator::shouldIgnore (Decl *D) {
872+ if (!D->isImplicit ())
873+ return false ;
874+
868875 // TODO: There should really be a separate field controlling whether
869876 // constructors are visited or not
870- return D->isImplicit () && !isa<ConstructorDecl>(D);
877+ if (isa<ConstructorDecl>(D))
878+ return false ;
879+
880+ // Walk into missing decls to visit their attributes if they were generated
881+ // by a member attribute expansion. Note that we would have already skipped
882+ // this decl if we were ignoring expansions, so no need to check that.
883+ if (auto *missing = dyn_cast<MissingDecl>(D)) {
884+ if (D->isInGeneratedBuffer ())
885+ return false ;
886+ }
887+
888+ return true ;
871889}
872890
873891bool SourceEntityWalker::walk (SourceFile &SrcFile) {
0 commit comments