Skip to content

Commit af1feb8

Browse files
Merge pull request #7106 from adrian-prantl/112939483-5.9
Degrade missing VFS overlays in serialized Swift options to warnings.
2 parents 8250a14 + c4142a2 commit af1feb8

File tree

10 files changed

+134
-41
lines changed

10 files changed

+134
-41
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,6 @@ class Module : public std::enable_shared_from_this<Module>,
844844

845845
#ifdef LLDB_ENABLE_SWIFT
846846
void
847-
ReportWarningCantLoadSwiftModule(std::string details,
848-
llvm::Optional<lldb::user_id_t> debugger_id);
849-
void
850847
ReportWarningToolchainMismatch(CompileUnit &comp_unit,
851848
llvm::Optional<lldb::user_id_t> debugger_id);
852849

@@ -1110,7 +1107,6 @@ class Module : public std::enable_shared_from_this<Module>,
11101107
std::once_flag m_optimization_warning;
11111108
std::once_flag m_language_warning;
11121109
#ifdef LLDB_ENABLE_SWIFT
1113-
std::once_flag m_swift_import_warning;
11141110
std::once_flag m_toolchain_mismatch_warning;
11151111
#endif
11161112

lldb/include/lldb/Target/Process.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,6 @@ class Process : public std::enable_shared_from_this<Process>,
13501350
void PrintWarningOptimization(const SymbolContext &sc);
13511351

13521352
#ifdef LLDB_ENABLE_SWIFT
1353-
/// Prints a async warning message to the user one time per Process
1354-
/// for a Module whose Swift AST sections couldn't be loaded because
1355-
/// they aren't buildable on the current machine.
1356-
///
1357-
/// @param [in] module
1358-
/// The affected Module.
1359-
void PrintWarningCantLoadSwiftModule(Module &module, std::string details);
1360-
13611353
/// Print a user-visible warning about Swift CUs compiled with a
13621354
/// different Swift compiler than the one embedded in LLDB.
13631355
void PrintWarningToolchainMismatch(const SymbolContext &sc);

lldb/source/Core/Module.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,6 @@ void Module::ReportWarningUnsupportedLanguage(
11791179
}
11801180

11811181
#ifdef LLDB_ENABLE_SWIFT
1182-
void Module::ReportWarningCantLoadSwiftModule(
1183-
std::string details, llvm::Optional<lldb::user_id_t> debugger_id) {
1184-
StreamString ss;
1185-
ss << GetFileSpec() << ": "
1186-
<< "Cannot load Swift type information: " << details;
1187-
Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
1188-
&m_swift_import_warning);
1189-
}
1190-
11911182
static llvm::VersionTuple GetAdjustedVersion(llvm::VersionTuple version) {
11921183
return version;
11931184
}

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,14 @@ static void printASTValidationError(
11181118
}
11191119

11201120
void 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+
<< "\nThis 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.
16521692
static 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+
24862559
void SwiftASTContext::LogFatalErrors() const {
24872560
// Avoid spamming the health log with redundant copies of the fatal error.
24882561
if (m_logged_fatal_error) {

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ class SwiftASTContext : public TypeSystemSwift {
262262
static void AddExtraClangArgs(const std::vector<std::string>& source,
263263
std::vector<std::string>& dest);
264264
static std::string GetPluginServer(llvm::StringRef plugin_library_path);
265+
/// Removes nonexisting VFS overlay options.
266+
static void FilterClangImporterOptions(std::vector<std::string> &extra_args,
267+
SwiftASTContext *ctx = nullptr);
265268

266269
/// Add the target's swift-extra-clang-flags to the ClangImporter options.
267270
void AddUserClangArgs(TargetProperties &props);
@@ -859,6 +862,8 @@ class SwiftASTContext : public TypeSystemSwift {
859862
/// Called by the VALID_OR_RETURN macro to log all errors.
860863
void LogFatalErrors() const;
861864
Status GetAllDiagnostics() const;
865+
/// Stream all diagnostics to the Debugger and clear them.
866+
void StreamAllDiagnostics(llvm::Optional<lldb::user_id_t> debugger_id) const;
862867

863868
llvm::TargetOptions *getTargetOptions();
864869

@@ -903,6 +908,9 @@ class SwiftASTContext : public TypeSystemSwift {
903908
std::unique_ptr<swift::irgen::IRGenerator> m_ir_generator_ap;
904909
std::unique_ptr<swift::irgen::IRGenModule> m_ir_gen_module_ap;
905910
llvm::once_flag m_ir_gen_module_once;
911+
mutable std::once_flag m_swift_import_warning;
912+
mutable std::once_flag m_swift_diags_streamed;
913+
mutable std::once_flag m_swift_warning_streamed;
906914
std::unique_ptr<swift::DiagnosticConsumer> m_diagnostic_consumer_ap;
907915
std::unique_ptr<swift::DependencyTracker> m_dependency_tracker;
908916
swift::ModuleDecl *m_scratch_module = nullptr;

lldb/source/Target/Process.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6010,12 +6010,6 @@ void Process::PrintWarningOptimization(const SymbolContext &sc) {
60106010
}
60116011

60126012
#ifdef LLDB_ENABLE_SWIFT
6013-
void Process::PrintWarningCantLoadSwiftModule(Module &module,
6014-
std::string details) {
6015-
module.ReportWarningCantLoadSwiftModule(std::move(details),
6016-
GetTarget().GetDebugger().GetID());
6017-
}
6018-
60196013
void Process::PrintWarningToolchainMismatch(const SymbolContext &sc) {
60206014
if (GetTarget().GetProcessLaunchInfo().IsScriptedProcess())
60216015
// It's very likely that the debugger used to launch the ScriptedProcess

lldb/test/API/lang/swift/clangimporter/missing_vfsoverlay/TestSwiftMissingVFSOverlay.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lldbsuite.test.lldbutil as lldbutil
55
import unittest2
66

7-
87
class TestSwiftMissingVFSOverlay(TestBase):
98
mydir = TestBase.compute_mydir(__file__)
109

@@ -18,11 +17,11 @@ def setUp(self):
1817
@skipUnlessDarwin
1918
@swiftTest
2019
def test(self):
21-
"""Test that a broken Clang command line option is diagnosed
22-
in the expression evaluator"""
20+
"""This used to be a test for a diagnostic, however,
21+
this is no longer an unrecoverable error"""
2322
self.build()
2423
lldbutil.run_to_source_breakpoint(
2524
self, "break here", lldb.SBFileSpec("main.swift"),
2625
extra_images=["Foo"]
2726
)
28-
self.expect("expr y", error=True, substrs=["IRGen", "overlay.yaml"])
27+
self.expect("expr y", substrs=["42"])

lldb/test/Shell/Swift/DeserializationFailure.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ run
1818
expression 1
1919

2020
# The {{ }} avoids accidentally matching the input script!
21-
# CHECK: a.out:{{ }}{{.*}}The serialized module is corrupted.
21+
# CHECK: {{ }}a.out
22+
# CHECK: {{ }}The serialized module is corrupted.

lldb/test/Shell/Swift/MissingVFSOverlay.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ run
1515
expression 1
1616

1717
# The {{ }} avoids accidentally matching the input script!
18-
# CHECK: a.out:{{ }}
19-
# CHECK-SAME: error:
18+
# CHECK: warning:
19+
# CHECK-SAME: a.out
20+
# CHECK: warning:
21+
# CHECK-SAME: Ignoring missing VFS
2022
# CHECK-SAME: overlay.yaml
21-
# CHECK-SAME: not found

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
#include "gtest/gtest.h"
1414

15+
#include "Plugins/TypeSystem/Swift/SwiftASTContext.h"
1516
#include "lldb/Host/FileSystem.h"
1617
#include "lldb/Host/HostInfo.h"
17-
#include "Plugins/TypeSystem/Swift/SwiftASTContext.h"
18+
#include "llvm/Support/FileUtilities.h"
1819

1920
using namespace lldb;
2021
using namespace lldb_private;
@@ -255,3 +256,40 @@ TEST(ClangArgs, DoubleDash) {
255256
// Check that all ignored arguments got removed.
256257
EXPECT_EQ(dest, std::vector<std::string>({"-v"}));
257258
}
259+
260+
TEST_F(TestSwiftASTContext, IVFS) {
261+
const auto *Info = testing::UnitTest::GetInstance()->current_test_info();
262+
llvm::SmallString<128> name;
263+
auto ec = llvm::sys::fs::createTemporaryFile(
264+
llvm::Twine(Info->test_case_name()) + "-" + Info->name(), "overlay.yaml",
265+
name);
266+
ASSERT_FALSE((bool)ec);
267+
llvm::FileRemover remover(name);
268+
269+
std::string valid = name.str().str();
270+
std::string invalid = name.str().drop_back(1).str() +"XXX";
271+
std::vector<std::string> args;
272+
args.push_back("-ivfsoverlay");
273+
args.push_back(valid);
274+
275+
args.push_back("-ivfsoverlay");
276+
args.push_back(invalid);
277+
278+
args.push_back("-ivfsstatcache");
279+
args.push_back(valid);
280+
281+
args.push_back("-ivfsstatcache");
282+
args.push_back(invalid);
283+
284+
std::vector<std::string> expected;
285+
expected.push_back("-ivfsoverlay");
286+
expected.push_back(valid);
287+
288+
expected.push_back("-ivfsstatcache");
289+
expected.push_back(valid);
290+
291+
SwiftASTContext::FilterClangImporterOptions(args);
292+
293+
// Check that all ignored arguments got removed.
294+
EXPECT_EQ(args, expected);
295+
}

0 commit comments

Comments
 (0)