mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SymbolGraph] Fix crasher when retrieving cursor info of method defined in ObjC
In a mixed Objective-C / Swift module, we have a Clang module overlay that’s a Source file, not a serialized AST as is currently assumed. That assumption caused a crash when retrieving the symbol graph as part of a cursor info request to SourceKit, which was invoked on a method defined in the Objective-C part of the module. To fix the crash, recursively use the same logic that already exists to serialize a module to also serialize the clang overlay module since that function alreayd correctly handles the distinction between source files and serialized ASTs. Resolves rdar://76951147
This commit is contained in:
@@ -17,9 +17,7 @@
|
||||
#include "swift/AST/ProtocolConformance.h"
|
||||
#include "swift/AST/USRGeneration.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "swift/ClangImporter/ClangModule.h"
|
||||
#include "swift/Sema/IDETypeChecking.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
|
||||
#include "DeclarationFragmentPrinter.h"
|
||||
#include "FormatVersion.h"
|
||||
@@ -524,38 +522,7 @@ void SymbolGraph::serialize(llvm::json::OStream &OS) {
|
||||
}
|
||||
AttributeRAII Platform("platform", OS);
|
||||
|
||||
auto *MainFile = M.getFiles().front();
|
||||
switch (MainFile->getKind()) {
|
||||
case FileUnitKind::Builtin:
|
||||
llvm_unreachable("Unexpected module kind: Builtin");
|
||||
case FileUnitKind::DWARFModule:
|
||||
llvm_unreachable("Unexpected module kind: DWARFModule");
|
||||
case FileUnitKind::Synthesized:
|
||||
llvm_unreachable("Unexpected module kind: Synthesized");
|
||||
break;
|
||||
case FileUnitKind::Source:
|
||||
symbolgraphgen::serialize(M.getASTContext().LangOpts.Target, OS);
|
||||
break;
|
||||
case FileUnitKind::SerializedAST: {
|
||||
auto SerializedAST = cast<SerializedASTFile>(MainFile);
|
||||
auto Target = llvm::Triple(SerializedAST->getTargetTriple());
|
||||
symbolgraphgen::serialize(Target, OS);
|
||||
break;
|
||||
}
|
||||
case FileUnitKind::ClangModule: {
|
||||
auto ClangModule = cast<ClangModuleUnit>(MainFile);
|
||||
if (const auto *Overlay = ClangModule->getOverlayModule()) {
|
||||
auto &OverlayMainFile =
|
||||
Overlay->getMainFile(FileUnitKind::SerializedAST);
|
||||
auto SerializedAST = cast<SerializedASTFile>(OverlayMainFile);
|
||||
auto Target = llvm::Triple(SerializedAST.getTargetTriple());
|
||||
symbolgraphgen::serialize(Target, OS);
|
||||
} else {
|
||||
symbolgraphgen::serialize(Walker.Options.Target, OS);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
symbolgraphgen::serialize(M, OS, Walker.Options.Target);
|
||||
});
|
||||
|
||||
if (ModuleVersion) {
|
||||
|
||||
Reference in New Issue
Block a user