@@ -1118,9 +1118,14 @@ static void printASTValidationError(
11181118}
11191119
11201120void SwiftASTContext::DiagnoseWarnings (Process &process, Module &module ) const {
1121- if (HasDiagnostics ())
1122- process.PrintWarningCantLoadSwiftModule (module ,
1123- GetAllDiagnostics ().AsCString ());
1121+ if (!HasDiagnostics ())
1122+ return ;
1123+ auto debugger_id = process.GetTarget ().GetDebugger ().GetID ();
1124+ std::string msg;
1125+ llvm::raw_string_ostream (msg) << " Cannot load Swift type information for "
1126+ << module .GetFileSpec ().GetPath ();
1127+ Debugger::ReportWarning (msg, debugger_id, &m_swift_import_warning);
1128+ StreamAllDiagnostics (debugger_id);
11241129}
11251130
11261131// / Locate the swift-plugin-server for a plugin library,
@@ -1503,8 +1508,8 @@ bool ShouldUnique(StringRef arg) {
15031508} // namespace
15041509
15051510// static
1506- void SwiftASTContext::AddExtraClangArgs (const std::vector<std::string>& source,
1507- std::vector<std::string>& dest) {
1511+ void SwiftASTContext::AddExtraClangArgs (const std::vector<std::string> & source,
1512+ std::vector<std::string> & dest) {
15081513 llvm::StringSet<> unique_flags;
15091514 for (auto &arg : dest)
15101515 unique_flags.insert (arg);
@@ -1648,6 +1653,41 @@ void SwiftASTContext::RemapClangImporterOptions(
16481653 }
16491654}
16501655
1656+ void SwiftASTContext::FilterClangImporterOptions (
1657+ std::vector<std::string> &extra_args, SwiftASTContext *ctx) {
1658+ std::string ivfs_arg;
1659+ // Copy back a filtered version of ExtraArgs.
1660+ std::vector<std::string> orig_args (std::move (extra_args));
1661+ for (auto &arg : orig_args) {
1662+ // The VFS options turn into fatal errors when the referenced file
1663+ // is not found. Since the Xcode build system tends to create a
1664+ // lot of VFS overlays by default, stat them and emit a warning if
1665+ // the yaml file couldn't be found.
1666+ if (StringRef (arg).startswith (" -ivfs" )) {
1667+ // Stash the argument.
1668+ ivfs_arg = arg;
1669+ continue ;
1670+ }
1671+ if (!ivfs_arg.empty ()) {
1672+ auto clear_ivfs_arg = llvm::make_scope_exit ([&] { ivfs_arg.clear (); });
1673+ if (!FileSystem::Instance ().Exists (arg)) {
1674+ if (ctx) {
1675+ std::string error;
1676+ llvm::raw_string_ostream (error)
1677+ << " Ignoring missing VFS file: " << arg
1678+ << " \n This is the likely root cause for any subsequent compiler "
1679+ " errors." ;
1680+ ctx->AddDiagnostic (eDiagnosticSeverityWarning, error);
1681+ }
1682+ continue ;
1683+ }
1684+ // Keep it.
1685+ extra_args.push_back (ivfs_arg);
1686+ }
1687+ extra_args.push_back (std::move (arg));
1688+ }
1689+ }
1690+
16511691// / Retrieve the .dSYM bundle for \p module.
16521692static llvm::Optional<StringRef> GetDSYMBundle (Module &module ) {
16531693 auto sym_file = module .GetSymbolFile ();
@@ -1904,6 +1944,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
19041944
19051945 // Apply source path remappings found in the module's dSYM.
19061946 swift_ast_sp->RemapClangImporterOptions (module .GetSourceMappingList ());
1947+ swift_ast_sp->FilterClangImporterOptions (
1948+ swift_ast_sp->GetClangImporterOptions ().ExtraArgs , swift_ast_sp.get ());
19071949
19081950 // Add Swift interfaces in the .dSYM at the end of the search paths.
19091951 // .swiftmodules win over .swiftinterfaces, when they are loaded
@@ -2396,6 +2438,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
23962438
23972439 // Apply source path remappings found in the target settings.
23982440 swift_ast_sp->RemapClangImporterOptions (target.GetSourcePathMap ());
2441+ swift_ast_sp->FilterClangImporterOptions (
2442+ swift_ast_sp->GetClangImporterOptions ().ExtraArgs , swift_ast_sp.get ());
23992443
24002444 // This needs to happen once all the import paths are set, or
24012445 // otherwise no modules will be found.
@@ -2483,6 +2527,35 @@ Status SwiftASTContext::GetAllDiagnostics() const {
24832527 return error;
24842528}
24852529
2530+ void SwiftASTContext::StreamAllDiagnostics (
2531+ llvm::Optional<lldb::user_id_t > debugger_id) const {
2532+ Status error = m_fatal_errors;
2533+ if (!error.Success ()) {
2534+ Debugger::ReportWarning (error.AsCString (), debugger_id,
2535+ &m_swift_diags_streamed);
2536+ return ;
2537+ }
2538+
2539+ // Retrieve the error message from the DiagnosticConsumer.
2540+ DiagnosticManager diagnostic_manager;
2541+ PrintDiagnostics (diagnostic_manager);
2542+ for (auto &diag : diagnostic_manager.Diagnostics ())
2543+ if (diag) {
2544+ std::string msg = diag->GetMessage ().str ();
2545+ switch (diag->GetSeverity ()) {
2546+ case eDiagnosticSeverityError:
2547+ Debugger::ReportError (msg, debugger_id, &m_swift_diags_streamed);
2548+ break ;
2549+ case eDiagnosticSeverityWarning:
2550+ case eDiagnosticSeverityRemark:
2551+ Debugger::ReportWarning (msg, debugger_id, &m_swift_warning_streamed);
2552+ break ;
2553+ }
2554+ }
2555+ static_cast <StoringDiagnosticConsumer *>(m_diagnostic_consumer_ap.get ())
2556+ ->Clear ();
2557+ }
2558+
24862559void SwiftASTContext::LogFatalErrors () const {
24872560 // Avoid spamming the health log with redundant copies of the fatal error.
24882561 if (m_logged_fatal_error) {
0 commit comments