Skip to content

Commit a66a4d0

Browse files
Revert "[lldb] Fix SwiftASTContext creatiion when swift caching is used"
This reverts commit 81b0f13 and 1162e50. The original change can cause lldb to hang forever on certain configurations when swiftmodules are not available. Revert the change for now for further investigation. rdar://135917827
1 parent fc10361 commit a66a4d0

File tree

10 files changed

+22
-139
lines changed

10 files changed

+22
-139
lines changed

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

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "clang/Basic/TargetOptions.h"
5858
#include "clang/Driver/Driver.h"
5959
#include "clang/Frontend/CompilerInstance.h"
60-
#include "clang/Frontend/TextDiagnosticPrinter.h"
6160
#include "clang/Lex/Preprocessor.h"
6261

6362
#include "clang/Lex/PreprocessorOptions.h"
@@ -1575,7 +1574,21 @@ bool ShouldUnique(StringRef arg) {
15751574

15761575
// static
15771576
void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1578-
std::vector<std::string> &dest) {
1577+
std::vector<std::string> &dest,
1578+
bool cc1) {
1579+
// FIXME: Support for cc1 flags isn't complete. The uniquing
1580+
// algortihm below does not work for cc1 flags. Since cc1 flags are
1581+
// not stable it's not feasible to keep a list of all multi-arg
1582+
// flags, for example. It also makes it difficult to correctly
1583+
// identify where workng directories and path remappings should
1584+
// applied. For all these reasons, using cc1 flags for anything but
1585+
// a local build with explicit modules and precise compiler
1586+
// invocations isn't supported yet.
1587+
if (cc1) {
1588+
dest.insert(dest.end(), source.begin(), source.end());
1589+
return;
1590+
}
1591+
15791592
llvm::StringSet<> unique_flags;
15801593
for (auto &arg : dest)
15811594
unique_flags.insert(arg);
@@ -1767,14 +1780,8 @@ void SwiftASTContext::AddExtraClangArgs(
17671780
eSeverityWarning,
17681781
"Mixing and matching of driver and cc1 Clang options detected");
17691782

1770-
// If using direct cc1 flags, compute the arguments and return.
1771-
// Since this is cc1 flags, no driver overwrite can be applied.
1772-
if (importer_options.DirectClangCC1ModuleBuild) {
1773-
AddExtraClangCC1Args(ExtraArgs, importer_options.ExtraArgs);
1774-
return;
1775-
}
1776-
1777-
AddExtraClangArgs(ExtraArgs, importer_options.ExtraArgs);
1783+
AddExtraClangArgs(ExtraArgs, importer_options.ExtraArgs,
1784+
importer_options.DirectClangCC1ModuleBuild);
17781785
applyOverrideOptions(importer_options.ExtraArgs, overrideOpts);
17791786
if (HasNonexistentExplicitModule(importer_options.ExtraArgs))
17801787
RemoveExplicitModules(importer_options.ExtraArgs);
@@ -1786,73 +1793,6 @@ void SwiftASTContext::AddExtraClangArgs(
17861793
});
17871794
}
17881795

1789-
void SwiftASTContext::AddExtraClangCC1Args(
1790-
const std::vector<std::string> &source, std::vector<std::string> &dest) {
1791-
clang::CompilerInvocation invocation;
1792-
llvm::SmallVector<const char *> clangArgs;
1793-
clangArgs.reserve(source.size());
1794-
llvm::for_each(source, [&](const std::string &Arg) {
1795-
// Workaround for the extra driver argument embedded in the swiftmodule by
1796-
// some swift compiler version. It always starts with `--target=` and it is
1797-
// not a valid cc1 option.
1798-
if (!StringRef(Arg).starts_with("--target="))
1799-
clangArgs.push_back(Arg.c_str());
1800-
});
1801-
1802-
std::string diags;
1803-
llvm::raw_string_ostream os(diags);
1804-
auto diagOpts = llvm::makeIntrusiveRefCnt<clang::DiagnosticOptions>();
1805-
clang::DiagnosticsEngine clangDiags(
1806-
new clang::DiagnosticIDs(), diagOpts,
1807-
new clang::TextDiagnosticPrinter(os, diagOpts.get()));
1808-
1809-
if (!clang::CompilerInvocation::CreateFromArgs(invocation, clangArgs,
1810-
clangDiags)) {
1811-
// If cc1 arguments failed to parse, report diagnostics and return
1812-
// immediately.
1813-
AddDiagnostic(eSeverityError, diags);
1814-
// Disable direct-cc1 build as fallback.
1815-
GetClangImporterOptions().DirectClangCC1ModuleBuild = false;
1816-
return;
1817-
}
1818-
1819-
// Clear module cache key and other CAS options to load modules from disk
1820-
// directly.
1821-
invocation.getFrontendOpts().ModuleCacheKeys.clear();
1822-
invocation.getCASOpts() = clang::CASOptions();
1823-
1824-
// Remove non-existing modules in a systematic way.
1825-
bool module_missing = false;
1826-
auto CheckFileExists = [&](const char *file) {
1827-
if (!llvm::sys::fs::exists(file)) {
1828-
std::string m_description;
1829-
HEALTH_LOG_PRINTF("Nonexistent explicit module file %s", file);
1830-
module_missing = true;
1831-
}
1832-
};
1833-
llvm::for_each(invocation.getHeaderSearchOpts().PrebuiltModuleFiles,
1834-
[&](const auto &mod) { CheckFileExists(mod.second.c_str()); });
1835-
llvm::for_each(invocation.getFrontendOpts().ModuleFiles,
1836-
[&](const auto &mod) { CheckFileExists(mod.c_str()); });
1837-
1838-
// If missing, clear all the prebuilt module options and use implicit module
1839-
// build.
1840-
if (module_missing) {
1841-
invocation.getHeaderSearchOpts().PrebuiltModuleFiles.clear();
1842-
invocation.getFrontendOpts().ModuleFiles.clear();
1843-
invocation.getLangOpts().ImplicitModules = true;
1844-
invocation.getHeaderSearchOpts().ImplicitModuleMaps = true;
1845-
}
1846-
1847-
invocation.generateCC1CommandLine(
1848-
[&](const llvm::Twine &arg) { dest.push_back(arg.str()); });
1849-
1850-
// If cc1 arguments are parsed and generated correctly, set explicitly-built
1851-
// module since only explicit module build can use direct cc1 mode.
1852-
m_has_explicit_modules = true;
1853-
return;
1854-
}
1855-
18561796
void SwiftASTContext::AddUserClangArgs(TargetProperties &props) {
18571797
Args args(props.GetSwiftExtraClangFlags());
18581798
std::vector<std::string> user_clang_flags;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,8 @@ class SwiftASTContext : public TypeSystemSwift {
278278
/// apply the working directory to any relative paths.
279279
void AddExtraClangArgs(const std::vector<std::string> &ExtraArgs,
280280
llvm::StringRef overrideOpts = "");
281-
void AddExtraClangCC1Args(const std::vector<std::string>& source,
282-
std::vector<std::string>& dest);
283281
static void AddExtraClangArgs(const std::vector<std::string>& source,
284-
std::vector<std::string>& dest);
282+
std::vector<std::string>& dest, bool cc1);
285283
static std::string GetPluginServer(llvm::StringRef plugin_library_path);
286284
/// Removes nonexisting VFS overlay options.
287285
static void FilterClangImporterOptions(std::vector<std::string> &extra_args,

lldb/test/API/lang/swift/clangimporter/caching/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/lang/swift/clangimporter/caching/TestSwiftClangImporterCaching.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

lldb/test/API/lang/swift/clangimporter/caching/a.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/test/API/lang/swift/clangimporter/caching/b.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

lldb/test/API/lang/swift/clangimporter/caching/main.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

lldb/test/API/lang/swift/clangimporter/caching/module.modulemap

Lines changed: 0 additions & 7 deletions
This file was deleted.

lldb/test/API/lang/swift/clangimporter/explicit_cc1/TestSwiftClangImporterExplicitCC1.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ def test(self):
2626
self.expect("expression obj", DATA_TYPES_DISPLAYED_CORRECTLY,
2727
substrs=["b ="])
2828
self.filecheck('platform shell cat "%s"' % log, __file__)
29-
### -cc1 should be round-tripped so there is no more `-cc1` in the extra args. Look for `-triple` which is a cc1 flag.
30-
# CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- -triple
31-
# CHECK-NOT: -cc1
29+
# CHECK: SwiftASTContextForExpressions(module: "a", cu: "main.swift")::LogConfiguration() -- -cc1

lldb/unittests/Symbol/TestSwiftASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ const std::vector<std::string> uniqued_flags = {
234234
TEST_F(ClangArgs, UniquingCollisionWithExistingFlags) {
235235
const std::vector<std::string> source = duplicated_flags;
236236
std::vector<std::string> dest = uniqued_flags;
237-
SwiftASTContext::AddExtraClangArgs(source, dest);
237+
SwiftASTContext::AddExtraClangArgs(source, dest, false);
238238

239239
EXPECT_EQ(dest, uniqued_flags);
240240
}
241241

242242
TEST_F(ClangArgs, UniquingCollisionWithAddedFlags) {
243243
const std::vector<std::string> source = duplicated_flags;
244244
std::vector<std::string> dest;
245-
SwiftASTContext::AddExtraClangArgs(source, dest);
245+
SwiftASTContext::AddExtraClangArgs(source, dest, false);
246246

247247
EXPECT_EQ(dest, uniqued_flags);
248248
}
@@ -251,7 +251,7 @@ TEST_F(ClangArgs, DoubleDash) {
251251
// -v with all currently ignored arguments following.
252252
const std::vector<std::string> source{"-v", "--", "-Werror", ""};
253253
std::vector<std::string> dest;
254-
SwiftASTContext::AddExtraClangArgs(source, dest);
254+
SwiftASTContext::AddExtraClangArgs(source, dest, false);
255255

256256
// Check that all ignored arguments got removed.
257257
EXPECT_EQ(dest, std::vector<std::string>({"-v"}));

0 commit comments

Comments
 (0)