Skip to content

Commit 661d59f

Browse files
authored
Merge pull request #1350 from artemcm/OnlySourceForWMOSupplements-Again
In WMO, make sure the dummy "primary" compilation input is a Swift source file
2 parents e992cd7 + 7bef081 commit 661d59f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,10 @@ extension Driver {
585585
// To match the legacy driver behavior, make sure we add the first input file
586586
// to the output file map if compiling without primary inputs (WMO), even
587587
// if there aren't any corresponding outputs.
588-
entries[inputFiles[0].fileHandle] = [:]
588+
guard let firstSourceInputHandle = inputFiles.first(where:{ $0.type == .swift })?.fileHandle else {
589+
fatalError("Formulating swift-frontend invocation without any input .swift files")
590+
}
591+
entries[firstSourceInputHandle] = [:]
589592
}
590593

591594
for flaggedPair in flaggedInputOutputPairs {

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,11 @@ extension Driver {
329329
emitModuleTrace: Bool
330330
) throws -> Job? {
331331
guard case .singleCompile = compilerMode,
332-
inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation })
332+
inputFiles.contains(where: { $0.type.isPartOfSwiftCompilation })
333333
else { return nil }
334334

335-
if parsedOptions.hasArgument(.embedBitcode) {
335+
if parsedOptions.hasArgument(.embedBitcode),
336+
inputFiles.allSatisfy({ $0.type.isPartOfSwiftCompilation }) {
336337
let compile = try compileJob(primaryInputs: [],
337338
outputType: .llvmBitcode,
338339
addJobOutputs: addJobOutputs,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,27 @@ final class SwiftDriverTests: XCTestCase {
28242824

28252825
}
28262826

2827+
func testWMOWithNonSourceInput() throws {
2828+
var driver1 = try Driver(args: [
2829+
"swiftc", "-whole-module-optimization", "danger.o", "foo.swift", "bar.swift", "wibble.swift", "-module-name", "Test",
2830+
"-driver-filelist-threshold=0"
2831+
])
2832+
let plannedJobs = try driver1.planBuild().removingAutolinkExtractJobs()
2833+
XCTAssertEqual(plannedJobs.count, 2)
2834+
let compileJob = plannedJobs[0]
2835+
XCTAssertEqual(compileJob.kind, .compile)
2836+
XCTAssert(compileJob.commandLine.contains(.flag("-supplementary-output-file-map")))
2837+
let argIdx = try XCTUnwrap(compileJob.commandLine.firstIndex(where: { $0 == .flag("-supplementary-output-file-map") }))
2838+
let supplOutputs = compileJob.commandLine[argIdx+1]
2839+
guard case let .path(path) = supplOutputs,
2840+
case let .fileList(_, fileList) = path,
2841+
case let .outputFileMap(outFileMap) = fileList else {
2842+
throw StringError("Unexpected argument for output file map")
2843+
}
2844+
let firstKey: String = try VirtualPath.lookup(XCTUnwrap(outFileMap.entries.keys.first)).description
2845+
XCTAssertEqual(firstKey, "foo.swift")
2846+
}
2847+
28272848
func testDashDashPassingDownInput() throws {
28282849
do {
28292850
var driver = try Driver(args: ["swiftc", "-module-name=ThisModule", "-wmo", "-num-threads", "4", "-emit-module", "-o", "test.swiftmodule", "--", "main.swift", "multi-threaded.swift"])

0 commit comments

Comments
 (0)