[flang] Fix bug flang-compiler/f18#843, bad recovery from failed opens of source files

Original-commit: flang-compiler/f18@27d9db610f
Reviewed-on: https://github.com/flang-compiler/f18/pull/850
This commit is contained in:
peter klausler 2019-12-03 09:49:44 -08:00
parent 1564d2735c
commit 64ea224ace
3 changed files with 11 additions and 7 deletions

View File

@ -49,6 +49,7 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
messages_.Say(range, "%s"_err_en_US, fileError.str());
return sourceFile;
}
CHECK(sourceFile);
if (sourceFile->bytes() == 0) {
ProvenanceRange range{allSources.AddCompilerInsertion(path)};
messages_.Say(range, "file is empty"_err_en_US);

View File

@ -174,8 +174,11 @@ std::string AllSources::PopSearchPathDirectory() {
const SourceFile *AllSources::Open(std::string path, std::stringstream *error) {
std::unique_ptr<SourceFile> source{std::make_unique<SourceFile>(encoding_)};
source->Open(LocateSourceFile(path, searchPath_), error);
return ownedSourceFiles_.emplace_back(std::move(source)).get();
if (source->Open(LocateSourceFile(path, searchPath_), error)) {
return ownedSourceFiles_.emplace_back(std::move(source)).get();
} else {
return nullptr;
}
}
const SourceFile *AllSources::ReadStandardInput(std::stringstream *error) {

View File

@ -764,16 +764,16 @@ Scope *ModFileReader::Read(const SourceName &name, Scope *ancestor) {
options.searchDirectories = context_.searchDirectories();
auto path{ModFileName(name, ancestorName, context_.moduleFileSuffix())};
const auto *sourceFile{parsing.Prescan(path, options)};
if (!sourceFile) {
return nullptr;
} else if (parsing.messages().AnyFatalError()) {
if (parsing.messages().AnyFatalError()) {
for (auto &msg : parsing.messages().messages()) {
std::string str{msg.ToString()};
Say(name, ancestorName, parser::MessageFixedText{str.c_str(), str.size()},
sourceFile->path());
path);
}
return nullptr;
} else if (!VerifyHeader(sourceFile->content(), sourceFile->bytes())) {
}
CHECK(sourceFile);
if (!VerifyHeader(sourceFile->content(), sourceFile->bytes())) {
Say(name, ancestorName, "File has invalid checksum: %s"_en_US,
sourceFile->path());
return nullptr;