-
Notifications
You must be signed in to change notification settings - Fork 341
Don't create a Module SwiftASTContext when the stdlib is missing #1391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1556,13 +1556,21 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) { | |
return dsym; | ||
} | ||
|
||
/// Detect whether a Swift module was "imported" by DWARFImporter. | ||
/// All this *really* means is that it couldn't be loaded through any | ||
/// other mechanism. | ||
static bool IsDWARFImported(swift::ModuleDecl &module) { | ||
return std::any_of(module.getFiles().begin(), module.getFiles().end(), | ||
[](swift::FileUnit *file_unit) { | ||
return (file_unit->getKind() == | ||
swift::FileUnitKind::DWARFModule); | ||
}); | ||
} | ||
|
||
lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | ||
Module &module, | ||
Target *target, | ||
bool fallback) { | ||
std::vector<std::string> module_search_paths; | ||
std::vector<std::pair<std::string, bool>> framework_search_paths; | ||
|
||
if (!SwiftASTContextSupportsLanguage(language)) | ||
return lldb::TypeSystemSP(); | ||
|
||
|
@@ -1576,16 +1584,33 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | |
module.GetDescription(ss, eDescriptionLevelBrief); | ||
ss << '"' << ')'; | ||
} | ||
std::vector<std::string> module_search_paths; | ||
std::vector<std::pair<std::string, bool>> framework_search_paths; | ||
|
||
LOG_PRINTF(LIBLLDB_LOG_TYPES, "(Module)"); | ||
|
||
auto logError = [&](const char *message) { | ||
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Failed to create module context - %s", | ||
message); | ||
}; | ||
|
||
ArchSpec arch = module.GetArchitecture(); | ||
if (!arch.IsValid()) { | ||
logError("invalid module architecture"); | ||
return TypeSystemSP(); | ||
} | ||
|
||
ObjectFile *objfile = module.GetObjectFile(); | ||
if (!objfile) | ||
return {}; | ||
if (!objfile) { | ||
logError("no object file for module"); | ||
return TypeSystemSP(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want similar changes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked through the other override and started re-arranging it, but decided to leave those changes out of this patch as they're entirely cosmetic. (I didn't find any missing checks.) |
||
|
||
ArchSpec object_arch = objfile->GetArchitecture(); | ||
if (!object_arch.IsValid()) | ||
return {}; | ||
if (!object_arch.IsValid()) { | ||
logError("invalid objfile architecture"); | ||
return TypeSystemSP(); | ||
} | ||
|
||
lldb::CompUnitSP main_compile_unit_sp = module.GetCompileUnitAtIndex(0); | ||
|
||
|
@@ -1641,9 +1666,6 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | |
swift_ast_sp->GetLanguageOptions().EnableAccessControl = false; | ||
swift_ast_sp->GetLanguageOptions().EnableTargetOSChecking = false; | ||
|
||
if (!arch.IsValid()) | ||
return TypeSystemSP(); | ||
|
||
swift_ast_sp->SetTriple(triple, &module); | ||
|
||
bool set_triple = false; | ||
|
@@ -1654,7 +1676,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | |
std::string target_triple; | ||
|
||
if (sym_file) { | ||
bool got_serialized_options; | ||
bool got_serialized_options = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ouch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is not so bad, I don't believe got_serialized_options is actually used, this is just some future-proofing. I can leave it out if you prefer. |
||
llvm::SmallString<0> error; | ||
llvm::raw_svector_ostream errs(error); | ||
if (DeserializeAllCompilerFlags(*swift_ast_sp, module, m_description, errs, | ||
|
@@ -1784,6 +1806,20 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | |
swift_ast_sp->LogConfiguration(); | ||
} | ||
} | ||
|
||
if (swift_ast_sp->HasFatalErrors()) { | ||
logError(swift_ast_sp->GetFatalErrors().AsCString()); | ||
return {}; | ||
} | ||
|
||
const bool can_create = true; | ||
swift::ModuleDecl *stdlib = | ||
swift_ast_sp->m_ast_context_ap->getStdlibModule(can_create); | ||
if (!stdlib || IsDWARFImported(*stdlib)) { | ||
logError("couldn't load the Swift stdlib"); | ||
return {}; | ||
} | ||
|
||
return swift_ast_sp; | ||
} | ||
|
||
|
@@ -1840,17 +1876,6 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) { | |
return ModuleSP(); | ||
} | ||
|
||
/// Detect whether a Swift module was "imported" by DWARFImporter. | ||
/// All this *really* means is that it couldn't be loaded through any | ||
/// other mechanism. | ||
static bool IsDWARFImported(swift::ModuleDecl &module) { | ||
return std::any_of(module.getFiles().begin(), module.getFiles().end(), | ||
[](swift::FileUnit *file_unit) { | ||
return (file_unit->getKind() == | ||
swift::FileUnitKind::DWARFModule); | ||
}); | ||
} | ||
|
||
lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language, | ||
Target &target, | ||
const char *extra_options) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually write the default return value as
return {}
, since the concrete type doesn't matter that much to the reader.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really just stylistic preference :-)