@@ -599,17 +599,23 @@ bool CompilerInstance::setUpInputs() {
599
599
600
600
const auto &Inputs =
601
601
Invocation.getFrontendOptions ().InputsAndOutputs .getAllInputs ();
602
+ const bool shouldRecover = Invocation.getFrontendOptions ()
603
+ .InputsAndOutputs .shouldRecoverMissingInputs ();
604
+
605
+ bool hasFailed = false ;
602
606
for (const InputFile &input : Inputs) {
603
607
bool failed = false ;
604
- Optional<unsigned > bufferID = getRecordedBufferID (input, failed);
605
- if ( failed)
606
- return true ;
608
+ Optional<unsigned > bufferID =
609
+ getRecordedBufferID (input, shouldRecover, failed);
610
+ hasFailed |= failed ;
607
611
608
612
if (!bufferID.hasValue () || !input.isPrimary ())
609
613
continue ;
610
614
611
615
recordPrimaryInputBuffer (*bufferID);
612
616
}
617
+ if (hasFailed)
618
+ return true ;
613
619
614
620
// Set the primary file to the code-completion point if one exists.
615
621
if (codeCompletionBufferID.hasValue () &&
@@ -621,8 +627,9 @@ bool CompilerInstance::setUpInputs() {
621
627
return false ;
622
628
}
623
629
624
- Optional<unsigned > CompilerInstance::getRecordedBufferID (const InputFile &input,
625
- bool &failed) {
630
+ Optional<unsigned >
631
+ CompilerInstance::getRecordedBufferID (const InputFile &input,
632
+ const bool shouldRecover, bool &failed) {
626
633
if (!input.getBuffer ()) {
627
634
if (Optional<unsigned > existingBufferID =
628
635
SourceMgr.getIDForBufferIdentifier (input.getFileName ())) {
@@ -631,6 +638,13 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
631
638
}
632
639
auto buffers = getInputBuffersIfPresent (input);
633
640
641
+ // Recover by dummy buffer if requested.
642
+ if (!buffers.hasValue () && shouldRecover &&
643
+ input.getType () == file_types::TY_Swift && !input.isPrimary ()) {
644
+ buffers = ModuleBuffers (llvm::MemoryBuffer::getMemBuffer (
645
+ " // missing file\n " , input.getFileName ()));
646
+ }
647
+
634
648
if (!buffers.hasValue ()) {
635
649
failed = true ;
636
650
return None;
0 commit comments