Skip to content

Commit c4142a2

Browse files
committed
Degrade missing VFS overlays in serialized Swift options to warnings.
The VFS options turn into fatal errors when the referenced file is not found. Since the Xcode build system tends to create a lot of VFS overlays by default, stat them emit a warning if the yaml file couldn't be found. rdar://112939483
1 parent 4aed073 commit c4142a2

File tree

5 files changed

+90
-10
lines changed

5 files changed

+90
-10
lines changed

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,8 +1508,8 @@ bool ShouldUnique(StringRef arg) {
15081508
} // namespace
15091509

15101510
// static
1511-
void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string>& source,
1512-
std::vector<std::string>& dest) {
1511+
void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1512+
std::vector<std::string> &dest) {
15131513
llvm::StringSet<> unique_flags;
15141514
for (auto &arg : dest)
15151515
unique_flags.insert(arg);
@@ -1653,6 +1653,41 @@ void SwiftASTContext::RemapClangImporterOptions(
16531653
}
16541654
}
16551655

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+
16561691
/// Retrieve the .dSYM bundle for \p module.
16571692
static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
16581693
auto sym_file = module.GetSymbolFile();
@@ -1909,6 +1944,8 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
19091944

19101945
// Apply source path remappings found in the module's dSYM.
19111946
swift_ast_sp->RemapClangImporterOptions(module.GetSourceMappingList());
1947+
swift_ast_sp->FilterClangImporterOptions(
1948+
swift_ast_sp->GetClangImporterOptions().ExtraArgs, swift_ast_sp.get());
19121949

19131950
// Add Swift interfaces in the .dSYM at the end of the search paths.
19141951
// .swiftmodules win over .swiftinterfaces, when they are loaded
@@ -2401,6 +2438,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
24012438

24022439
// Apply source path remappings found in the target settings.
24032440
swift_ast_sp->RemapClangImporterOptions(target.GetSourcePathMap());
2441+
swift_ast_sp->FilterClangImporterOptions(
2442+
swift_ast_sp->GetClangImporterOptions().ExtraArgs, swift_ast_sp.get());
24042443

24052444
// This needs to happen once all the import paths are set, or
24062445
// otherwise no modules will be found.

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

Lines changed: 3 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);

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/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)