Skip to content

Commit ae727e1

Browse files
authored
Merge pull request swiftlang#39509 from artemcm/FixExplicitPCMWarnings
Fix `'linker' input unused` warnings in Explicit Module Builds
2 parents f8e5f28 + aa31794 commit ae727e1

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,17 @@ ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
958958

959959
std::vector<std::string>
960960
ClangImporter::getClangArguments(ASTContext &ctx) {
961-
if (ctx.ClangImporterOpts.ExtraArgsOnly) {
962-
return ctx.ClangImporterOpts.ExtraArgs;
963-
}
964961
std::vector<std::string> invocationArgStrs;
965962
// Clang expects this to be like an actual command line. So we need to pass in
966963
// "clang" for argv[0]
967964
invocationArgStrs.push_back(ctx.ClangImporterOpts.clangPath);
965+
if (ctx.ClangImporterOpts.ExtraArgsOnly) {
966+
invocationArgStrs.insert(invocationArgStrs.end(),
967+
ctx.ClangImporterOpts.ExtraArgs.begin(),
968+
ctx.ClangImporterOpts.ExtraArgs.end());
969+
return invocationArgStrs;
970+
}
971+
968972
switch (ctx.ClangImporterOpts.Mode) {
969973
case ClangImporterOptions::Modes::Normal:
970974
case ClangImporterOptions::Modes::PrecompiledModule:

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ void ClangImporter::recordModuleDependencies(
242242
// from the depending Swift modules.
243243
if (arg == "-target") {
244244
It += 2;
245+
} else if (arg == "clang" ||
246+
arg.endswith(llvm::sys::path::get_separator().str() + "clang")) {
247+
// Remove the initial path to clang executable argument, to avoid
248+
// treating it as an executable input to compilation. It is not needed
249+
// because the consumer of this command-line will invoke the emit-PCM
250+
// action via swift-frontend.
251+
It += 1;
245252
} else if (arg.startswith("-fapinotes-swift-version=")) {
246253
// Remove the apinotes version because we should use the language version
247254
// specified in the interface file.

test/ScanDependencies/module_deps.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ import SubE
126126
// CHECK: "commandLine": [
127127
// CHECK-NEXT: "-frontend"
128128
// CHECK-NEXT: "-only-use-extra-clang-opts"
129-
// CHECK-NEXT: "-Xcc"
130-
// CHECK-NEXT: "BUILD_DIR/bin/clang"
129+
// CHECK-NOT: "BUILD_DIR/bin/clang"
131130
// CHECK: "-fsystem-module",
132131
// CHECK-NEXT: "-emit-pcm",
133132
// CHECK-NEXT: "-module-name",

test/ScanDependencies/module_deps_cache_reuse.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ import SubE
109109

110110
// CHECK: "commandLine": [
111111
// CHECK-NEXT: "-frontend"
112-
// CHECK-NEXT: "-only-use-extra-clang-opts"
113-
// CHECK-NEXT: "-Xcc"
114-
// CHECK-NEXT: "BUILD_DIR/bin/clang"
112+
// CHECK-NEXT: "-only-use-extra-clang-opts
113+
// CHECK-NOT: "BUILD_DIR/bin/clang"
115114
// CHECK-NEXT: "-Xcc"
116115
// CHECK-NEXT: "-fsyntax-only",
117116
// CHECK: "-fsystem-module",

0 commit comments

Comments
 (0)