@@ -24,6 +24,7 @@ public struct Driver {
2424 case relativeFrontendPath( String )
2525 case subcommandPassedToDriver
2626 case integratedReplRemoved
27+ case cannotSpecify_OForMultipleOutputs
2728 case conflictingOptions( Option , Option )
2829 case unableToLoadOutputFileMap( String )
2930 case unableToDecodeFrontendTargetInfo( String ? , [ String ] , String )
@@ -57,6 +58,8 @@ public struct Driver {
5758 return " subcommand passed to driver "
5859 case . integratedReplRemoved:
5960 return " Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead. "
61+ case . cannotSpecify_OForMultipleOutputs:
62+ return " cannot specify -o when generating multiple output files "
6063 case . conflictingOptions( let one, let two) :
6164 return " conflicting options ' \( one. spelling) ' and ' \( two. spelling) ' "
6265 case let . unableToDecodeFrontendTargetInfo( outputString, arguments, errorDesc) :
@@ -693,6 +696,8 @@ public struct Driver {
693696 compilerMode: compilerMode,
694697 outputFileMap: self . outputFileMap,
695698 moduleName: moduleOutputInfo. name)
699+
700+ try verifyOutputOptions ( )
696701 }
697702
698703 public mutating func planBuild( ) throws -> [ Job ] {
@@ -778,6 +783,29 @@ extension Driver {
778783 }
779784}
780785
786+ extension Driver {
787+ // Detect mis-use of multi-threading and output file options
788+ private func verifyOutputOptions( ) throws {
789+ if compilerOutputType != . swiftModule,
790+ parsedOptions. hasArgument ( . o) ,
791+ linkerOutputType == nil {
792+ let shouldComplain : Bool
793+ if numThreads > 0 {
794+ // Multi-threading compilation has multiple outputs unless there's only
795+ // one input.
796+ shouldComplain = self . inputFiles. count > 1
797+ } else {
798+ // Single-threaded compilation is a problem if we're compiling more than
799+ // one file.
800+ shouldComplain = self . inputFiles. filter { $0. type. isPartOfSwiftCompilation } . count > 1 && . singleCompile != compilerMode
801+ }
802+ if shouldComplain {
803+ diagnosticEngine. emit ( Error . cannotSpecify_OForMultipleOutputs)
804+ }
805+ }
806+ }
807+ }
808+
781809// MARK: - Response files.
782810extension Driver {
783811 /// Tokenize a single line in a response file.
0 commit comments