Skip to content

Commit 8b9b1b0

Browse files
committed
Only specify -dwarf-version if the frontend supports it.
The `-dwarf-version` frontend option is still relatively new and in some build configurations, a newer driver may be used with an older frontend that does not understand the argument.
1 parent 0afa340 commit 8b9b1b0

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ extension Driver {
197197
try commandLine.appendLast(in: .g, from: &parsedOptions)
198198
if debugInfo.level != nil {
199199
commandLine.appendFlag("-debug-info-format=\(debugInfo.format)")
200-
commandLine.appendFlag("-dwarf-version=\(debugInfo.dwarfVersion)")
200+
if isFrontendArgSupported(.dwarfVersion) {
201+
commandLine.appendFlag("-dwarf-version=\(debugInfo.dwarfVersion)")
202+
}
201203
}
202204
try commandLine.appendLast(.importUnderlyingModule, from: &parsedOptions)
203205
try commandLine.appendLast(.moduleCachePath, from: &parsedOptions)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,29 @@ final class SwiftDriverTests: XCTestCase {
582582
$1.expect(.error("invalid value '6' in '-dwarf-version="))
583583
}
584584

585-
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
586-
let jobs = try driver.planBuild()
587-
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
588-
}
589-
590585
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-file-compilation-dir", ".") { driver in
591586
let jobs = try driver.planBuild()
592587
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
593588
XCTAssertTrue(jobs[0].commandLine.contains(.flag(".")))
594589
}
595590

591+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-file-compilation-dir", ".") { driver in
592+
let jobs = try driver.planBuild()
593+
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
594+
}
595+
}
596+
597+
func testDwarfVersionSetting() throws {
598+
let driver = try Driver(args: ["swiftc", "foo.swift"])
599+
guard driver.isFrontendArgSupported(.dwarfVersion) else {
600+
throw XCTSkip("Skipping: compiler does not support '-dwarf-version'")
601+
}
602+
603+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
604+
let jobs = try driver.planBuild()
605+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
606+
}
607+
596608
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "x86_64-apple-macosx10.10") { driver in
597609
let jobs = try driver.planBuild()
598610
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=2")))
@@ -625,11 +637,6 @@ final class SwiftDriverTests: XCTestCase {
625637
let jobs = try driver.planBuild()
626638
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
627639
}
628-
629-
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-file-compilation-dir", ".") { driver in
630-
let jobs = try driver.planBuild()
631-
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
632-
}
633640
}
634641

635642
func testCoverageSettings() throws {

0 commit comments

Comments
 (0)