Skip to content

Commit e4a3fc8

Browse files
[ScanDependency] Handle -Xcc options that affects module generation
Make sure the `-Xcc` options to the scanner are correctly considered when creating ClangImporterCC1 arguments for constructed swift interface compilation job. Also cached the computed swift explicit module cc1 arguments so it doesn't need to be computed every time for each swift interface job. rdar://128873665
1 parent 531469f commit e4a3fc8

File tree

5 files changed

+60
-12
lines changed

5 files changed

+60
-12
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 2 additions & 2 deletions
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;
@@ -517,7 +517,7 @@ class ClangImporter final : public ClangModuleLoader {
517517
std::string getClangModuleHash() const;
518518

519519
/// Get clang import creation cc1 args for swift explicit module build.
520-
std::vector<std::string> getSwiftExplicitModuleDirectCC1Args() const;
520+
const std::vector<std::string> &getSwiftExplicitModuleDirectCC1Args() const;
521521

522522
/// If we already imported a given decl successfully, return the corresponding
523523
/// Swift decl as an Optional<Decl *>, but if we previously tried and failed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 3 deletions
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) {
@@ -4064,8 +4064,11 @@ std::string ClangImporter::getClangModuleHash() const {
40644064
return Impl.Invocation->getModuleHash(Impl.Instance->getDiagnostics());
40654065
}
40664066

4067-
std::vector<std::string>
4067+
const std::vector<std::string> &
40684068
ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
4069+
if (!Impl.SwiftExplicitModuleCC1Args.empty())
4070+
return Impl.SwiftExplicitModuleCC1Args;
4071+
40694072
llvm::SmallVector<const char*> clangArgs;
40704073
clangArgs.reserve(Impl.ClangArgs.size());
40714074
llvm::for_each(Impl.ClangArgs, [&](const std::string &Arg) {
@@ -4121,7 +4124,8 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
41214124
FSOpts.WorkingDir.clear();
41224125
}
41234126

4124-
return instance.getCC1CommandLine();
4127+
Impl.SwiftExplicitModuleCC1Args = instance.getCC1CommandLine();
4128+
return Impl.SwiftExplicitModuleCC1Args;
41254129
}
41264130

41274131
std::optional<Decl *>

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
536536
/// Clang arguments used to create the Clang invocation.
537537
std::vector<std::string> ClangArgs;
538538

539+
/// Clang arguments used to create the ClangImporter for swift-frontend jobs.
540+
std::vector<std::string> SwiftExplicitModuleCC1Args;
541+
539542
/// Mapping from Clang swift_attr attribute text to the Swift source buffer
540543
/// IDs that contain that attribute text. These are re-used when parsing the
541544
/// Swift attributes on import.

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 2 additions & 7 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 ||

test/CAS/Xcc_objc_direct.swift

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

0 commit comments

Comments
 (0)