[Frontend] Recover missing input file by dummy input buffer.

Also, continue trying opening files even if any of primary files are
missing so that the caller can know all files failed to open.

rdar://problem/33757793
This commit is contained in:
Rintaro Ishizaki
2020-11-06 16:16:15 -08:00
parent bbd1ed4dbe
commit 055dc66d3b
3 changed files with 34 additions and 2 deletions

View File

@@ -599,17 +599,19 @@ bool CompilerInstance::setUpInputs() {
const auto &Inputs =
Invocation.getFrontendOptions().InputsAndOutputs.getAllInputs();
bool hasFailed = false;
for (const InputFile &input : Inputs) {
bool failed = false;
Optional<unsigned> bufferID = getRecordedBufferID(input, failed);
if (failed)
return true;
hasFailed |= failed;
if (!bufferID.hasValue() || !input.isPrimary())
continue;
recordPrimaryInputBuffer(*bufferID);
}
if (hasFailed)
return true;
// Set the primary file to the code-completion point if one exists.
if (codeCompletionBufferID.hasValue() &&
@@ -631,6 +633,15 @@ Optional<unsigned> CompilerInstance::getRecordedBufferID(const InputFile &input,
}
auto buffers = getInputBuffersIfPresent(input);
// For non-primary '.swift' files, recover by dummy buffer so that the primary
// files are diagnosed. Also, IDE functionalities want to proceed even with
// missing files.
if (!buffers.hasValue() && input.getType() == file_types::TY_Swift &&
!input.isPrimary()) {
buffers = ModuleBuffers(llvm::MemoryBuffer::getMemBuffer(
"// missing file\n", input.getFileName()));
}
if (!buffers.hasValue()) {
failed = true;
return None;