Skip to content

Commit 48237b8

Browse files
Merge pull request #74012 from cachemeifyoucan/eng/PR-128873665
[ScanDependency] Handle `-Xcc` options that affects module generation
2 parents 0341899 + 42732c0 commit 48237b8

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class ClangImporter final : public ClangModuleLoader {
194194
createClangInvocation(ClangImporter *importer,
195195
const ClangImporterOptions &importerOpts,
196196
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
197-
std::vector<std::string> &CC1Args);
197+
const std::vector<std::string> &CC1Args);
198198

199199
ClangImporter(const ClangImporter &) = delete;
200200
ClangImporter(ClangImporter &&) = delete;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
12161216
std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
12171217
ClangImporter *importer, const ClangImporterOptions &importerOpts,
12181218
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1219-
std::vector<std::string> &CC1Args) {
1219+
const std::vector<std::string> &CC1Args) {
12201220
std::vector<const char *> invocationArgs;
12211221
invocationArgs.reserve(CC1Args.size());
12221222
llvm::for_each(CC1Args, [&](const std::string &Arg) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,16 +1908,11 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
19081908
// explicit Swift module build tasks will not rely on them and they may be
19091909
// source-target-context-specific and hinder module sharing across
19101910
// compilation source targets.
1911-
// If using DirectCC1Scan, the command-line reduction is handled inside
1912-
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
1913-
// anything here as the ExtraArgs from the invocation are clang driver
1914-
// options, not cc1 options.
19151911
// Clang module dependecies of this Swift dependency will be distinguished
19161912
// by their context hash for different variants, so would still cause a
19171913
// difference in the Swift compile commands, when different.
1918-
if (!clangImporterOpts.ClangImporterDirectCC1Scan)
1919-
inheritedParentContextClangArgs =
1920-
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
1914+
inheritedParentContextClangArgs =
1915+
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
19211916
genericSubInvocation.getFrontendOptions()
19221917
.DependencyScanningSubInvocation = true;
19231918
} else if (LoaderOpts.strictImplicitModuleContext ||
@@ -1931,9 +1926,15 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
19311926
inheritedParentContextClangArgs = clangImporterOpts.ExtraArgs;
19321927
}
19331928
subClangImporterOpts.ExtraArgs = inheritedParentContextClangArgs;
1934-
for (auto arg : subClangImporterOpts.ExtraArgs) {
1935-
GenericArgs.push_back("-Xcc");
1936-
GenericArgs.push_back(ArgSaver.save(arg));
1929+
// If using DirectCC1Scan, the command-line reduction is handled inside
1930+
// `getSwiftExplicitModuleDirectCC1Args()`, there is no need to inherit
1931+
// anything here as the ExtraArgs from the invocation are clang driver
1932+
// options, not cc1 options.
1933+
if (!clangImporterOpts.ClangImporterDirectCC1Scan) {
1934+
for (auto arg : subClangImporterOpts.ExtraArgs) {
1935+
GenericArgs.push_back("-Xcc");
1936+
GenericArgs.push_back(ArgSaver.save(arg));
1937+
}
19371938
}
19381939

19391940
subClangImporterOpts.EnableClangSPI = clangImporterOpts.EnableClangSPI;

test/CAS/Xcc_objc_direct.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \
5+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
6+
// 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 \
7+
// RUN: -file-compilation-dir %t \
8+
// RUN: -I %t/include -module-load-mode prefer-serialized
9+
10+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shims.cmd
11+
// RUN: %swift_frontend_plain @%t/shims.cmd
12+
13+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd
14+
// RUN: %swift_frontend_plain @%t/B.cmd
15+
16+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
17+
// RUN: %swift_frontend_plain @%t/A.cmd
18+
19+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
20+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
21+
22+
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/MyApp.cmd
23+
24+
// RUN: %target-swift-frontend \
25+
// RUN: -typecheck -cache-compile-job -cas-path %t/cas \
26+
// RUN: -swift-version 5 -disable-implicit-swift-modules \
27+
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
28+
// RUN: -module-name Test -explicit-swift-module-map-file @%t/map.casid \
29+
// RUN: %t/test.swift @%t/MyApp.cmd
30+
31+
//--- test.swift
32+
private import A
33+
34+
//--- include/A.swiftinterface
35+
// swift-interface-format-version: 1.0
36+
// 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
37+
import B
38+
public func a() {}
39+
40+
//--- include/module.modulemap
41+
module B {
42+
header "B.h"
43+
export *
44+
}
45+
46+
//--- include/B.h
47+
void b(void);

0 commit comments

Comments
 (0)