Skip to content

Commit 14c478a

Browse files
committed
Skip default CMO when emitting module separately
Cross-module optimization is incompatible with emitting the module separately. Previously, an assertion caught this condition, but the assertion would not fire in release builds. This changes the logic to simply skip enabling default CMO when emitModuleSeparately is true, rather than asserting or erroring.
1 parent 0764248 commit 14c478a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ extension Driver {
296296
forObject: outputType == .object)
297297
try addRuntimeLibraryFlags(commandLine: &commandLine)
298298

299+
// Enable default cross-module optimization when possible, but only if we're not
300+
// emitting the module separately (CMO is incompatible with separate module emission)
299301
if Driver.canDoCrossModuleOptimization(parsedOptions: &parsedOptions) &&
300302
// For historical reasons, -cross-module-optimization turns on "aggressive" CMO
301303
// which is different from "default" CMO.
302304
!parsedOptions.hasArgument(.CrossModuleOptimization) &&
303-
!parsedOptions.hasArgument(.EnableCMOEverything) {
304-
assert(!emitModuleSeparately, "Cannot emit module separately with cross-module-optimization")
305+
!parsedOptions.hasArgument(.EnableCMOEverything) &&
306+
!emitModuleSeparately {
305307
commandLine.appendFlag("-enable-default-cmo")
306308
}
307309

0 commit comments

Comments
 (0)