@@ -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 )
@@ -58,6 +59,8 @@ public struct Driver {
5859 return " subcommand passed to driver "
5960 case . integratedReplRemoved:
6061 return " Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead. "
62+ case . cannotSpecify_OForMultipleOutputs:
63+ return " cannot specify -o when generating multiple output files "
6164 case . conflictingOptions( let one, let two) :
6265 return " conflicting options ' \( one. spelling) ' and ' \( two. spelling) ' "
6366 case let . unableToDecodeFrontendTargetInfo( outputString, arguments, errorDesc) :
@@ -696,6 +699,8 @@ public struct Driver {
696699 compilerMode: compilerMode,
697700 outputFileMap: self . outputFileMap,
698701 moduleName: moduleOutputInfo. name)
702+
703+ try verifyOutputOptions ( )
699704 }
700705
701706 public mutating func planBuild( ) throws -> [ Job ] {
@@ -781,6 +786,29 @@ extension Driver {
781786 }
782787}
783788
789+ extension Driver {
790+ // Detect mis-use of multi-threading and output file options
791+ private func verifyOutputOptions( ) throws {
792+ if compilerOutputType != . swiftModule,
793+ parsedOptions. hasArgument ( . o) ,
794+ linkerOutputType == nil {
795+ let shouldComplain : Bool
796+ if numThreads > 0 {
797+ // Multi-threading compilation has multiple outputs unless there's only
798+ // one input.
799+ shouldComplain = self . inputFiles. count > 1
800+ } else {
801+ // Single-threaded compilation is a problem if we're compiling more than
802+ // one file.
803+ shouldComplain = self . inputFiles. filter { $0. type. isPartOfSwiftCompilation } . count > 1 && . singleCompile != compilerMode
804+ }
805+ if shouldComplain {
806+ diagnosticEngine. emit ( Error . cannotSpecify_OForMultipleOutputs)
807+ }
808+ }
809+ }
810+ }
811+
784812// MARK: - Response files.
785813extension Driver {
786814 /// Tokenize a single line in a response file.
0 commit comments