Skip to content

Commit 376d137

Browse files
[ScanDependencies] Do not inherit driver options in direct-cc1 mode
When direct-cc1 scanning mode is enabled, do not inherit -Xcc options from the commandline as those are driver flags and clang importer already handle the conversion. rdar://125194535 (cherry picked from commit aad00e6)
1 parent 4248455 commit 376d137

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,17 +1873,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18731873
if (LoaderOpts.requestedAction ==
18741874
FrontendOptions::ActionType::ScanDependencies) {
18751875
// For a dependency scanning action, interface build command generation must
1876-
// inherit
1877-
// `-Xcc` flags used for configuration of the building instance's
1876+
// inherit `-Xcc` flags used for configuration of the building instance's
18781877
// `ClangImporter`. However, we can ignore Clang search path flags because
18791878
// explicit Swift module build tasks will not rely on them and they may be
18801879
// source-target-context-specific and hinder module sharing across
18811880
// compilation source targets.
1882-
// Clang module dependecies of this Swift dependency will be distinguished by
1883-
// their context hash for different variants, so would still cause a difference
1884-
// in the Swift compile commands, when different.
1885-
inheritedParentContextClangArgs =
1886-
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
1881+
// If using DirectCC1Scan, the command-line reduction is handled inside
1882+
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
1883+
// anything here as the ExtraArgs from the invocation are clang driver
1884+
// options, not cc1 options.
1885+
// Clang module dependecies of this Swift dependency will be distinguished
1886+
// by their context hash for different variants, so would still cause a
1887+
// difference in the Swift compile commands, when different.
1888+
if (!clangImporterOpts.ClangImporterDirectCC1Scan)
1889+
inheritedParentContextClangArgs =
1890+
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
18871891
genericSubInvocation.getFrontendOptions()
18881892
.DependencyScanningSubInvocation = true;
18891893
} else if (LoaderOpts.strictImplicitModuleContext ||

test/ScanDependencies/direct_cc1_scan.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps2.json -I %t \
1717
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib \
18+
// RUN: -g -file-compilation-dir %t -Xcc -ferror-limit=1 \
1819
// RUN: %t/test.swift -module-name Test -swift-version 5 -experimental-clang-importer-direct-cc1-scan
1920
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps2.json A | %FileCheck %s --check-prefix CHECK-DIRECT-CC1-SCAN
2021
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps2.json Test | %FileCheck %s --check-prefix CHECK-DIRECT-CC1-SCAN
2122

2223
// CHECK-NO-DIRECT-CC1-NOT: -direct-clang-cc1-module-build
2324
// CHECK-DIRECT-CC1-SCAN: -direct-clang-cc1-module-build
25+
// CHECK-DIRECT-CC1-SCAN-NOT: -ffile-compilation-dir
26+
// CHECK-DIRECT-CC1-SCAN-NOT: -ferror-limit=1
2427

2528
//--- A.swift
2629
func a() {}

0 commit comments

Comments
 (0)