Skip to content

Commit 056d2e3

Browse files
committed
Restore support for the llvm-bc (bitcode) field in the Swift file map.
This is still used by, e.g., Swift LTO. rdar://150188689
1 parent ea8d619 commit 056d2e3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,6 +3067,12 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
30673067
fileMapEntry.indexUnitOutputPath = indexObjectPath.str
30683068
}
30693069
}
3070+
let objectFilePrefix = objectFilePath.basenameWithoutSuffix
3071+
// The path to the bitcode file. This is used, for example, by LTO.
3072+
if compilationMode.compileSources {
3073+
let bitcodeFilePath = objectFileDir.join(objectFilePrefix + ".bc")
3074+
fileMapEntry.llvmBitcode = bitcodeFilePath.str
3075+
}
30703076
return (objectFilePath, fileMapEntry)
30713077
}
30723078

@@ -3782,6 +3788,7 @@ struct SwiftOutputFileMap: Codable {
37823788
struct Entry: Codable {
37833789
var object: String?
37843790
var indexUnitOutputPath: String?
3791+
var llvmBitcode: String?
37853792
var remap: String?
37863793
var diagnostics: String?
37873794
var emitModuleDiagnostics: String?
@@ -3795,6 +3802,7 @@ struct SwiftOutputFileMap: Codable {
37953802
enum CodingKeys: String, CodingKey {
37963803
case object
37973804
case indexUnitOutputPath = "index-unit-output-path"
3805+
case llvmBitcode = "llvm-bc"
37983806
case remap
37993807
case diagnostics
38003808
case emitModuleDiagnostics = "emit-module-diagnostics"

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,11 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
326326
#expect(fileDict["dependencies"]?.stringValue == "\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename).d")
327327
#expect(fileDict["swift-dependencies"]?.stringValue == "\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename).swiftdeps")
328328
#expect(fileDict["swiftmodule"]?.stringValue == "\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename)~partial.swiftmodule")
329+
#expect(fileDict["llvm-bc"]?.stringValue == "\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename).bc")
329330
#expect(fileDict["const-values"]?.stringValue == "\(SRCROOT)/build/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename).swiftconstvalues")
330331
if swiftFeatures.has(.indexUnitOutputPathWithoutWarning) {
331332
#expect(fileDict["index-unit-output-path"]?.stringValue == "/aProject.build/Debug/AppTarget.build/Objects-normal/x86_64/\(filename).o")
332-
#expect(fileDict.count == 7)
333+
#expect(fileDict.count == 8)
333334
} else {
334335
#expect(fileDict.count == 6)
335336
}
@@ -1265,9 +1266,11 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
12651266
} else {
12661267
compileTask.checkCommandLineContains(["-lto=llvm-thin"])
12671268
}
1269+
compileTask.checkOutputs(contain: [.namePattern(.suffix("Bar.bc"))])
12681270
}
12691271
results.checkTask(.matchTarget(target), .matchRuleType("Libtool")) { archiverTask in
12701272
results.checkTaskFollows(archiverTask, .matchTarget(target), .matchRuleType("SwiftDriver Compilation"))
1273+
archiverTask.checkInputs(contain: [.namePattern(.suffix("Bar.bc"))])
12711274
}
12721275
}
12731276
results.checkTarget("CoreFoo") { target in
@@ -1277,9 +1280,11 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
12771280
} else {
12781281
compileTask.checkCommandLineContains(["-lto=llvm-thin"])
12791282
}
1283+
compileTask.checkOutputs(contain: [.namePattern(.suffix("Foo.bc"))])
12801284
}
12811285
results.checkTask(.matchTarget(target), .matchRuleType("Ld")) { linkerTask in
12821286
results.checkTaskFollows(linkerTask, .matchTarget(target), .matchRuleType("SwiftDriver Compilation"))
1287+
linkerTask.checkInputs(contain: [.namePattern(.suffix("Foo.bc"))])
12831288
if ltoSetting == "YES_THIN" {
12841289
linkerTask.checkCommandLineMatches([.anySequence, "-Xlinker", "-cache_path_lto", "-Xlinker", .suffix("/LTOCache"), .anySequence])
12851290
}

0 commit comments

Comments
 (0)