Skip to content

[6.0][ScanDependency] Handle -Xcc options that affects module generation #74106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/ClangImporter/ClangImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class ClangImporter final : public ClangModuleLoader {
createClangInvocation(ClangImporter *importer,
const ClangImporterOptions &importerOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
std::vector<std::string> &CC1Args);
const std::vector<std::string> &CC1Args);

ClangImporter(const ClangImporter &) = delete;
ClangImporter(ClangImporter &&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
ClangImporter *importer, const ClangImporterOptions &importerOpts,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
std::vector<std::string> &CC1Args) {
const std::vector<std::string> &CC1Args) {
std::vector<const char *> invocationArgs;
invocationArgs.reserve(CC1Args.size());
llvm::for_each(CC1Args, [&](const std::string &Arg) {
Expand Down
21 changes: 11 additions & 10 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,16 +1906,11 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
// 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.
// 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();
inheritedParentContextClangArgs =
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
genericSubInvocation.getFrontendOptions()
.DependencyScanningSubInvocation = true;
} else if (LoaderOpts.strictImplicitModuleContext ||
Expand All @@ -1929,9 +1924,15 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
inheritedParentContextClangArgs = clangImporterOpts.ExtraArgs;
}
subClangImporterOpts.ExtraArgs = inheritedParentContextClangArgs;
for (auto arg : subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
// 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.
if (!clangImporterOpts.ClangImporterDirectCC1Scan) {
for (auto arg : subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");
GenericArgs.push_back(ArgSaver.save(arg));
}
}

subClangImporterOpts.EnableClangSPI = clangImporterOpts.EnableClangSPI;
Expand Down
47 changes: 47 additions & 0 deletions test/CAS/Xcc_objc_direct.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: %t/test.swift -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas -Xcc -fobjc-disable-direct-methods-for-testing \
// RUN: -file-compilation-dir %t \
// RUN: -I %t/include -module-load-mode prefer-serialized

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shims.cmd
// RUN: %swift_frontend_plain @%t/shims.cmd

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
// RUN: %swift_frontend_plain @%t/B.cmd

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
// RUN: %swift_frontend_plain @%t/A.cmd

// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid

// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd

// RUN: %target-swift-frontend \
// RUN: -typecheck -cache-compile-job -cas-path %t/cas \
// RUN: -swift-version 5 -disable-implicit-swift-modules \
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
// RUN: %t/test.swift @%t/MyApp.cmd

//--- test.swift
private import A

//--- include/A.swiftinterface
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name A -O -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-stdlib -user-module-version 1.0
import B
public func a() {}

//--- include/module.modulemap
module B {
header "B.h"
export *
}

//--- include/B.h
void b(void);