Skip to content

Commit 4fd6d30

Browse files
authored
Merge pull request #10736 from graydon/rdar-32984579-emit-bc-depends-on-bridging-pch-as-well-swift-4.0-branch-06-23-2017
[Bridging PCH] Move dependency-on-bridging-PCH to -emit-bc JobAction …
2 parents 310d5f3 + eeabbdb commit 4fd6d30

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
@@ -1300,6 +1300,27 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
13001300
OI.SelectedSanitizer);
13011301
}
13021302

1303+
static void
1304+
currentDependsOnPCHIfPresent(JobAction *PCH,
1305+
std::unique_ptr<Action> &Current,
1306+
ActionList &Actions) {
1307+
if (PCH) {
1308+
// FIXME: When we have a PCH job, it's officially owned by the Actions
1309+
// array; but it's also a secondary input to each of the current
1310+
// JobActions, which means that we need to flip the "owns inputs" bit
1311+
// on the JobActions so they don't try to free it. That in turn means
1312+
// we need to transfer ownership of all the JobActions' existing
1313+
// inputs to the Actions array, since the JobActions either own or
1314+
// don't own _all_ of their inputs. Ownership can't vary
1315+
// input-by-input.
1316+
auto *job = cast<JobAction>(Current.get());
1317+
auto inputs = job->getInputs();
1318+
Actions.append(inputs.begin(), inputs.end());
1319+
job->setOwnsInputs(false);
1320+
job->addInput(PCH);
1321+
}
1322+
}
1323+
13031324
void Driver::buildActions(const ToolChain &TC,
13041325
const DerivedArgList &Args,
13051326
const InputFileList &Inputs,
@@ -1364,30 +1385,17 @@ void Driver::buildActions(const ToolChain &TC,
13641385
Current.reset(new CompileJobAction(Current.release(),
13651386
types::TY_LLVM_BC,
13661387
previousBuildState));
1388+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
13671389
AllModuleInputs.push_back(Current.get());
13681390
Current.reset(new BackendJobAction(Current.release(),
13691391
OI.CompilerOutputType, 0));
13701392
} else {
13711393
Current.reset(new CompileJobAction(Current.release(),
13721394
OI.CompilerOutputType,
13731395
previousBuildState));
1396+
currentDependsOnPCHIfPresent(PCH, Current, Actions);
13741397
AllModuleInputs.push_back(Current.get());
13751398
}
1376-
if (PCH) {
1377-
// FIXME: When we have a PCH job, it's officially owned by the Actions
1378-
// array; but it's also a secondary input to each of the current
1379-
// JobActions, which means that we need to flip the "owns inputs" bit
1380-
// on the JobActions so they don't try to free it. That in turn means
1381-
// we need to transfer ownership of all the JobActions' existing
1382-
// inputs to the Actions array, since the JobActions either own or
1383-
// don't own _all_ of their inputs. Ownership can't vary
1384-
// input-by-input.
1385-
auto *job = cast<JobAction>(Current.get());
1386-
auto inputs = job->getInputs();
1387-
Actions.append(inputs.begin(), inputs.end());
1388-
job->setOwnsInputs(false);
1389-
job->addInput(PCH);
1390-
}
13911399
AllLinkerInputs.push_back(Current.release());
13921400
break;
13931401
}

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)