Skip to content

Commit

Permalink
Fix bug flang-compiler#843, bad recovery from failed opens of source …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
klausler committed Dec 3, 2019
1 parent 58f036e commit 27d9db6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/parser/parsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions lib/parser/provenance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions lib/semantics/mod-file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 27d9db6

Please sign in to comment.