[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
This commit is contained in:
Steven Wu
2024-03-21 14:58:32 -07:00
parent 716a1a9dfc
commit aad00e60cf
2 changed files with 14 additions and 7 deletions

View File

@@ -1873,17 +1873,21 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
if (LoaderOpts.requestedAction ==
FrontendOptions::ActionType::ScanDependencies) {
// For a dependency scanning action, interface build command generation must
// inherit
// `-Xcc` flags used for configuration of the building instance's
// inherit `-Xcc` flags used for configuration of the building instance's
// `ClangImporter`. However, we can ignore Clang search path flags because
// explicit Swift module build tasks will not rely on them and they may be
// source-target-context-specific and hinder module sharing across
// compilation source targets.
// Clang module dependecies of this Swift dependency will be distinguished by
// their context hash for different variants, so would still cause a difference
// in the Swift compile commands, when different.
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
// If using DirectCC1Scan, the command-line reduction is handled inside
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
// anything here as the ExtraArgs from the invocation are clang driver
// options, not cc1 options.
// Clang module dependecies of this Swift dependency will be distinguished
// by their context hash for different variants, so would still cause a
// difference in the Swift compile commands, when different.
if (!clangImporterOpts.ClangImporterDirectCC1Scan)
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
genericSubInvocation.getFrontendOptions()
.DependencyScanningSubInvocation = true;
} else if (LoaderOpts.strictImplicitModuleContext ||