File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -519,6 +519,12 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
519519 LLVM_READONLY
520520 SourceFile *getParentSourceFile () const ;
521521
522+ // / Returns the "outermost" source file that contains this context,
523+ // / looking through any source files for generated code, such as
524+ // / macro expansions.
525+ LLVM_READONLY
526+ SourceFile *getOutermostParentSourceFile () const ;
527+
522528 // / Determine whether this declaration context is generic, meaning that it or
523529 // / any of its parents have generic parameters.
524530 bool isGenericContext () const ;
Original file line number Diff line number Diff line change @@ -323,6 +323,18 @@ SourceFile *DeclContext::getParentSourceFile() const {
323323 return fallbackSF;
324324}
325325
326+ SourceFile *DeclContext::getOutermostParentSourceFile () const {
327+ auto sf = getParentSourceFile ();
328+ if (!sf)
329+ return nullptr ;
330+
331+ // Find the originating source file.
332+ while (auto enclosingSF = sf->getEnclosingSourceFile ())
333+ sf = enclosingSF;
334+
335+ return sf;
336+ }
337+
326338DeclContext *DeclContext::getModuleScopeContext () const {
327339 auto DC = const_cast <DeclContext*>(this );
328340
Original file line number Diff line number Diff line change @@ -1919,10 +1919,11 @@ IRGenModule *IRGenerator::getGenModule(DeclContext *ctxt) {
19191919 if (GenModules.size () == 1 || !ctxt) {
19201920 return getPrimaryIGM ();
19211921 }
1922- SourceFile *SF = ctxt->getParentSourceFile ();
1922+ SourceFile *SF = ctxt->getOutermostParentSourceFile ();
19231923 if (!SF) {
19241924 return getPrimaryIGM ();
19251925 }
1926+
19261927 IRGenModule *IGM = GenModules[SF];
19271928 assert (IGM);
19281929 return IGM;
You can’t perform that action at this time.
0 commit comments