Skip to content

Commit 5bf5968

Browse files
committed
Building object files using -c with -lto should respect the output file path (-o) if present
1 parent 9769aad commit 5bf5968

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ extension Driver {
7979
case .object:
8080
return (linkerOutputType == nil)
8181
case .llvmBitcode:
82+
if linkerOutputType == nil {
83+
return true
84+
}
85+
8286
if compilerOutputType != .llvmBitcode {
8387
// The compiler output isn't bitcode, so bitcode isn't top-level (-embed-bitcode).
8488
return false

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ final class SwiftDriverTests: XCTestCase {
313313
XCTAssertEqual(driver6.compilerOutputType, .llvmBitcode)
314314
}
315315

316+
func testLtoOutputPath() throws {
317+
var driver1 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full",
318+
"-c", "-target", "x86_64-apple-macosx10.9"])
319+
XCTAssertEqual(driver1.compilerOutputType, .llvmBitcode)
320+
XCTAssertEqual(driver1.linkerOutputType, nil)
321+
let jobs1 = try driver1.planBuild()
322+
XCTAssertEqual(jobs1.count, 1)
323+
XCTAssertEqual(jobs1[0].outputs.count, 1)
324+
XCTAssertEqual(jobs1[0].outputs[0].file.basename, "foo.bc")
325+
326+
var driver2 = try Driver(args: ["swiftc", "foo.swift", "-lto=llvm-full",
327+
"-c", "-target", "x86_64-apple-macosx10.9",
328+
"-o", "foo.o"])
329+
XCTAssertEqual(driver2.compilerOutputType, .llvmBitcode)
330+
XCTAssertEqual(driver2.linkerOutputType, nil)
331+
let jobs2 = try driver2.planBuild()
332+
XCTAssertEqual(jobs2.count, 1)
333+
XCTAssertEqual(jobs2[0].outputs.count, 1)
334+
XCTAssertEqual(jobs2[0].outputs[0].file.basename, "foo.o")
335+
}
336+
316337
func testPrimaryOutputKindsDiagnostics() throws {
317338
try assertDriverDiagnostics(args: "swift", "-i") {
318339
$1.expect(.error("the flag '-i' is no longer required and has been removed; use 'swift input-filename'"))

0 commit comments

Comments
 (0)