@@ -599,10 +599,14 @@ bool CompilerInstance::setUpInputs() {
599599
600600 const auto &Inputs =
601601 Invocation.getFrontendOptions ().InputsAndOutputs .getAllInputs ();
602+ const bool shouldRecover = Invocation.getFrontendOptions ()
603+ .InputsAndOutputs .shouldRecoverMissingInputs ();
604+
602605 bool hasFailed = false ;
603606 for (const InputFile &input : Inputs) {
604607 bool failed = false ;
605- Optional<unsigned > bufferID = getRecordedBufferID (input, failed);
608+ Optional<unsigned > bufferID =
609+ getRecordedBufferID (input, shouldRecover, failed);
606610 hasFailed |= failed;
607611
608612 if (!bufferID.hasValue () || !input.isPrimary ())
@@ -623,8 +627,9 @@ bool CompilerInstance::setUpInputs() {
623627 return false ;
624628}
625629
626- Optional<unsigned > CompilerInstance::getRecordedBufferID (const InputFile &input,
627- bool &failed) {
630+ Optional<unsigned >
631+ CompilerInstance::getRecordedBufferID (const InputFile &input,
632+ const bool shouldRecover, bool &failed) {
628633 if (!input.getBuffer ()) {
629634 if (Optional<unsigned > existingBufferID =
630635 SourceMgr.getIDForBufferIdentifier (input.getFileName ())) {
@@ -633,11 +638,9 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
633638 }
634639 auto buffers = getInputBuffersIfPresent (input);
635640
636- // For non-primary '.swift' files, recover by dummy buffer so that the primary
637- // files are diagnosed. Also, IDE functionalities want to proceed even with
638- // missing files.
639- if (!buffers.hasValue () && input.getType () == file_types::TY_Swift &&
640- !input.isPrimary ()) {
641+ // Recover by dummy buffer if requested.
642+ if (!buffers.hasValue () && shouldRecover &&
643+ input.getType () == file_types::TY_Swift && !input.isPrimary ()) {
641644 buffers = ModuleBuffers (llvm::MemoryBuffer::getMemBuffer (
642645 " // missing file\n " , input.getFileName ()));
643646 }
0 commit comments