Skip to content

Commit 411b133

Browse files
authored
Merge pull request #10733 from graydon/rdar-32984579-emit-bc-depends-on-bridging-pch-as-well
[Bridging PCH] Move dependency-on-bridging-PCH to -emit-bc JobAction itself
2 parents fb5bdde + d4ff453 commit 411b133

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

lib/Driver/Driver.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,27 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13401340
OI.SelectedSanitizer);
13411341
}
13421342

1343+
static void
1344+
currentDependsOnPCHIfPresent(JobAction *PCH,
1345+
std::unique_ptr<Action> &Current,
1346+
ActionList &Actions) {
1347+
if (PCH) {
1348+
// FIXME: When we have a PCH job, it's officially owned by the Actions
1349+
// array; but it's also a secondary input to each of the current
1350+
// JobActions, which means that we need to flip the "owns inputs" bit
1351+
// on the JobActions so they don't try to free it. That in turn means
1352+
// we need to transfer ownership of all the JobActions' existing
1353+
// inputs to the Actions array, since the JobActions either own or
1354+
// don't own _all_ of their inputs. Ownership can't vary
1355+
// input-by-input.
1356+
auto *job = cast<JobAction>(Current.get());
1357+
auto inputs = job->getInputs();
1358+
Actions.append(inputs.begin(), inputs.end());
1359+
job->setOwnsInputs(false);
1360+
job->addInput(PCH);
1361+
}
1362+
}
1363+
13431364
void Driver::buildActions(const ToolChain &TC,
13441365
const DerivedArgList &Args,
13451366
const InputFileList &Inputs,
@@ -1404,30 +1425,17 @@ void Driver::buildActions(const ToolChain &TC,
14041425
Current.reset(new CompileJobAction(Current.release(),
14051426
types::TY_LLVM_BC,
14061427
previousBuildState));
1428+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
14071429
AllModuleInputs.push_back(Current.get());
14081430
Current.reset(new BackendJobAction(Current.release(),
14091431
OI.CompilerOutputType, 0));
14101432
} else {
14111433
Current.reset(new CompileJobAction(Current.release(),
14121434
OI.CompilerOutputType,
14131435
previousBuildState));
1436+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
14141437
AllModuleInputs.push_back(Current.get());
14151438
}
1416-
if (PCH) {
1417-
// FIXME: When we have a PCH job, it's officially owned by the Actions
1418-
// array; but it's also a secondary input to each of the current
1419-
// JobActions, which means that we need to flip the "owns inputs" bit
1420-
// on the JobActions so they don't try to free it. That in turn means
1421-
// we need to transfer ownership of all the JobActions' existing
1422-
// inputs to the Actions array, since the JobActions either own or
1423-
// don't own _all_ of their inputs. Ownership can't vary
1424-
// input-by-input.
1425-
auto *job = cast<JobAction>(Current.get());
1426-
auto inputs = job->getInputs();
1427-
Actions.append(inputs.begin(), inputs.end());
1428-
job->setOwnsInputs(false);
1429-
job->addInput(PCH);
1430-
}
14311439
AllLinkerInputs.push_back(Current.release());
14321440
break;
14331441
}

test/Driver/bridging-pch.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
// PERSISTENT-YESPCHACT: 2: input, "{{.*}}bridging-pch.swift", swift
3333
// PERSISTENT-YESPCHACT: 3: compile, {2, 1}, none
3434

35+
// RUN: %swiftc_driver -c -driver-print-actions -embed-bitcode -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch %s 2>&1 | %FileCheck %s -check-prefix=PERSISTENT-YESPCHACTBC
36+
// PERSISTENT-YESPCHACTBC: 0: input, "{{.*}}Inputs/bridging-header.h", objc-header
37+
// PERSISTENT-YESPCHACTBC: 1: generate-pch, {0}, none
38+
// PERSISTENT-YESPCHACTBC: 2: input, "{{.*}}bridging-pch.swift", swift
39+
// PERSISTENT-YESPCHACTBC: 3: compile, {2, 1}, llvm-bc
40+
3541
// RUN: %swiftc_driver -typecheck -disable-bridging-pch -driver-print-actions -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch %s 2>&1 | %FileCheck %s -check-prefix=NOPCHACT
3642

3743
// RUN: %swiftc_driver -typecheck -driver-print-jobs -import-objc-header %S/Inputs/bridging-header.h -pch-output-dir %t/pch -disable-bridging-pch %s 2>&1 | %FileCheck %s -check-prefix=PERSISTENT-DISABLED-YESPCHJOB

0 commit comments

Comments
 (0)