Skip to content

Commit 4a6bc77

Browse files
committed
[cxx-interop] Do not try to print empty namespaces in module interfaces
Clang sometimes generates implicit empty namespaces with no source location. We should not crash while trying to print them. ``` Assertion failed: (LHS.isValid() && RHS.isValid() && "Passed invalid source location!"), function isBeforeInTranslationUnit, file SourceManager.cpp ``` rdar://118534222
1 parent d6871ed commit 4a6bc77

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,14 @@ void swift::ide::printModuleInterface(
665665
// An imported namespace decl will contain members from all redecls, so
666666
// make sure we add all the redecls.
667667
for (auto redecl : namespaceDecl->redecls()) {
668+
if (redecl->decls_empty())
669+
continue;
668670
// Namespace redecls may exist across mutliple modules. We want to
669671
// add the decl "D" to every module that has a redecl. But we only
670672
// want to add "D" once to prevent duplicate printing.
671673
clang::SourceLocation loc = redecl->getLocation();
674+
assert(loc.isValid() &&
675+
"expected a valid SourceLocation for a non-empty namespace");
672676
auto *owningModule = Importer.getClangOwningModule(redecl);
673677
auto found = ClangDecls.find(owningModule);
674678
if (found != ClangDecls.end() &&

0 commit comments

Comments
 (0)