Index: lib/Index/IndexSymbol.cpp =================================================================== --- lib/Index/IndexSymbol.cpp +++ lib/Index/IndexSymbol.cpp @@ -319,8 +319,10 @@ Info.Lang = SymbolLanguage::CXX; auto getExternalSymAttr = [](const Decl *D) -> ExternalSourceSymbolAttr* { - if (auto *attr = D->getAttr()) - return attr; + for (auto *Redecl: D->redecls()) { + if (auto *attr = Redecl->getAttr()) + return attr; + } if (auto *dcd = dyn_cast(D->getDeclContext())) { if (auto *attr = dcd->getAttr()) return attr; Index: lib/Index/USRGeneration.cpp =================================================================== --- lib/Index/USRGeneration.cpp +++ lib/Index/USRGeneration.cpp @@ -49,8 +49,10 @@ static StringRef GetExternalSourceContainer(const NamedDecl *D) { if (!D) return StringRef(); - if (auto *attr = D->getAttr()) { - return attr->getDefinedIn(); + for (auto *Redecl: D->redecls()) { + if (auto *attr = Redecl->getAttr()) { + return attr->getDefinedIn(); + } } return StringRef(); } Index: test/Index/Core/external-source-symbol-attr.m =================================================================== --- test/Index/Core/external-source-symbol-attr.m +++ test/Index/Core/external-source-symbol-attr.m @@ -4,6 +4,10 @@ #define GEN_DECL(mod_name) __attribute__((external_source_symbol(language="Swift", defined_in=mod_name, generated_declaration))) #define PUSH_GEN_DECL(mod_name) push(GEN_DECL(mod_name), apply_to=any(enum, objc_interface, objc_category, objc_protocol)) +// Forward declarations should not affect module namespacing below +@class I1; +@class I2; + // This should not be indexed. GEN_DECL("some_module") @interface I1