Skip to content

Commit c5a9738

Browse files
authored
Merge pull request swiftlang#75177 from artemcm/60DepScanNoGlobalLLVMOpts
[6.0 🍒][Dependency Scanning] Avoid configuration (and reset) of LLVM Options by the scanner
2 parents b8c8d73 + 899e785 commit c5a9738

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ llvm::ErrorOr<swiftscan_string_ref_t> getTargetInfo(ArrayRef<const char *> Comma
3535
const char *main_executable_path) {
3636
llvm::sys::SmartScopedLock<true> Lock(TargetInfoMutex);
3737

38-
// We must reset option occurrences because we are handling an unrelated
39-
// command-line to those possibly parsed before using the same tool.
40-
// We must do so because LLVM options parsing is done using a managed
41-
// static `GlobalParser`.
42-
llvm::cl::ResetAllOptionOccurrences();
4338
// Parse arguments.
4439
std::string CommandString;
4540
for (const auto *c : Command) {
@@ -399,8 +394,7 @@ DependencyScanningTool::initCompilerInstanceForScan(
399394
StringRef WorkingDir,
400395
std::shared_ptr<DependencyScanDiagnosticCollector> scannerDiagnosticsCollector) {
401396
// The remainder of this method operates on shared state in the
402-
// scanning service and global LLVM state with:
403-
// llvm::cl::ResetAllOptionOccurrences
397+
// scanning service
404398
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
405399
// FIXME: Instead, target-info and supported-features queries must use
406400
// `DependencyScanningToolStateLock`, but this currently requires further
@@ -426,11 +420,6 @@ DependencyScanningTool::initCompilerInstanceForScan(
426420
if (WorkingDirectory.empty())
427421
llvm::sys::fs::current_path(WorkingDirectory);
428422

429-
// We must reset option occurrences because we are handling an unrelated
430-
// command-line to those possibly parsed before using the same tool.
431-
// We must do so because LLVM options parsing is done using a managed
432-
// static `GlobalParser`.
433-
llvm::cl::ResetAllOptionOccurrences();
434423
// Parse/tokenize arguments.
435424
std::string CommandString;
436425
for (const auto *c : CommandArgs) {

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,6 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
10851085
// those of the current scanner invocation.
10861086
updateCachedInstanceOpts(*pInstance, invocationInstance, entry.arguments);
10871087
} else {
1088-
// We must reset option occurrences because we are handling an unrelated command-line
1089-
// to those parsed before. We must do so because LLVM options parsing is done
1090-
// using a managed static `GlobalParser`.
1091-
llvm::cl::ResetAllOptionOccurrences();
1092-
10931088
// Create a new instance by the arguments and save it in the map.
10941089
auto newService = std::make_unique<SwiftDependencyScanningService>();
10951090
auto newInstance = std::make_unique<CompilerInstance>();

lib/Frontend/Frontend.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,21 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
659659
}
660660

661661
void CompilerInstance::setUpLLVMArguments() {
662-
// Honor -Xllvm.
663-
if (!Invocation.getFrontendOptions().LLVMArgs.empty()) {
664-
llvm::SmallVector<const char *, 4> Args;
665-
Args.push_back("swift (LLVM option parsing)");
666-
for (unsigned i = 0, e = Invocation.getFrontendOptions().LLVMArgs.size();
667-
i != e; ++i)
668-
Args.push_back(Invocation.getFrontendOptions().LLVMArgs[i].c_str());
669-
Args.push_back(nullptr);
670-
llvm::cl::ParseCommandLineOptions(Args.size()-1, Args.data());
662+
// Dependency scanning has no need for LLVM options, and
663+
// must not use `llvm::cl::` utilities operating on global state
664+
// since dependency scanning is multi-threaded.
665+
if (Invocation.getFrontendOptions().RequestedAction !=
666+
FrontendOptions::ActionType::ScanDependencies) {
667+
// Honor -Xllvm.
668+
if (!Invocation.getFrontendOptions().LLVMArgs.empty()) {
669+
llvm::SmallVector<const char *, 4> Args;
670+
Args.push_back("swift (LLVM option parsing)");
671+
for (unsigned i = 0, e = Invocation.getFrontendOptions().LLVMArgs.size();
672+
i != e; ++i)
673+
Args.push_back(Invocation.getFrontendOptions().LLVMArgs[i].c_str());
674+
Args.push_back(nullptr);
675+
llvm::cl::ParseCommandLineOptions(Args.size()-1, Args.data());
676+
}
671677
}
672678
}
673679

0 commit comments

Comments
 (0)