Skip to content

Commit 26873f8

Browse files
authored
Merge pull request #7944 from graydon/rdar-30879533-bridging-pch-serialize-diagnostics
[Bridging PCH] Serialize diagnostics in -emit-pch step.
2 parents b7c6627 + fae468f commit 26873f8

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ Job *Driver::buildJobsForAction(Compilation &C, const JobAction *JA,
20202020
}
20212021
}
20222022

2023-
if (isa<CompileJobAction>(JA)) {
2023+
if (isa<CompileJobAction>(JA) || isa<GeneratePCHJobAction>(JA)) {
20242024
// Choose the serialized diagnostics output path.
20252025
if (C.getArgs().hasArg(options::OPT_serialize_diagnostics)) {
20262026
addAuxiliaryOutput(C, *Output, types::TY_SerializedDiagnostics, OI,

lib/Driver/ToolChains.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ static void addCommonFrontendArgs(const ToolChain &TC,
167167

168168
if (llvm::sys::Process::StandardErrHasColors())
169169
arguments.push_back("-color-diagnostics");
170+
171+
const std::string &SerializedDiagnosticsPath =
172+
output.getAdditionalOutputForType(types::TY_SerializedDiagnostics);
173+
if (!SerializedDiagnosticsPath.empty()) {
174+
arguments.push_back("-serialize-diagnostics-path");
175+
arguments.push_back(SerializedDiagnosticsPath.c_str());
176+
}
170177
}
171178

172179

@@ -361,13 +368,6 @@ ToolChain::constructInvocation(const CompileJobAction &job,
361368
Arguments.push_back(ObjCHeaderOutputPath.c_str());
362369
}
363370

364-
const std::string &SerializedDiagnosticsPath =
365-
context.Output.getAdditionalOutputForType(types::TY_SerializedDiagnostics);
366-
if (!SerializedDiagnosticsPath.empty()) {
367-
Arguments.push_back("-serialize-diagnostics-path");
368-
Arguments.push_back(SerializedDiagnosticsPath.c_str());
369-
}
370-
371371
const std::string &DependenciesPath =
372372
context.Output.getAdditionalOutputForType(types::TY_Dependencies);
373373
if (!DependenciesPath.empty()) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: rm -f %t.*
2+
3+
// Check that when a driver is run with -serialize-diagnostics, it picks a .dia location and passes it to the frontend.
4+
// RUN: %target-swiftc_driver -typecheck %s -enable-bridging-pch -serialize-diagnostics -import-objc-header %S/Inputs/bad-bridging-header.h -driver-print-jobs 2>&1 | %FileCheck -check-prefix=CHECK-ARG %s
5+
// CHECK-ARG: -serialize-diagnostics-path
6+
7+
// Check that when a frontend is run in -emit-pch mode with -serialize-diagnostics-path, the diagnostics -- both textual and serialized -- reflect the error.
8+
// RUN: not %target-swift-frontend -emit-pch %S/Inputs/bad-bridging-header.h -o %t.pch -serialize-diagnostics -serialize-diagnostics-path %t.dia 2>&1 | %FileCheck -check-prefix=CHECK-DIAG %s
9+
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
10+
// RUN: %FileCheck -check-prefix=CHECK-DIAG -input-file=%t.deserialized_diagnostics.txt %s
11+
// CHECK-DIAG: bad-bridging-header.h:1:10: error: 'this-header-does-not-exist.h' file not found
12+
// CHECK-DIAG: failed to emit precompiled header

0 commit comments

Comments
 (0)