Skip to content

Commit

Permalink
[BOLT] Abort processing if the profile has no valid data
Browse files Browse the repository at this point in the history
Summary:
It's possible to pass a profile in invalid format to BOLT, and we
silently ignore it. This could cause a regression as such scenario can
go undetected. We should abort processing if no valid data was seen in
the profile and issue a warning if it was partially invalid.

(cherry picked from FBD14941211)
  • Loading branch information
maksfb committed Apr 15, 2019
1 parent 8f98268 commit 27dcec9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions bolt/src/DataReader.cpp
Expand Up @@ -253,14 +253,20 @@ void FuncMemData::update(const Location &Offset, const Location &Addr) {

ErrorOr<std::unique_ptr<DataReader>>
DataReader::readPerfData(StringRef Path, raw_ostream &Diag) {
ErrorOr<std::unique_ptr<MemoryBuffer>> MB =
MemoryBuffer::getFileOrSTDIN(Path);
if (std::error_code EC = MB.getError()) {
Diag << "Cannot open " << Path << ": " << EC.message() << "\n";
auto MB = MemoryBuffer::getFileOrSTDIN(Path);
if (auto EC = MB.getError()) {
Diag << "cannot open " << Path << ": " << EC.message() << "\n";
return EC;
}
auto DR = make_unique<DataReader>(std::move(MB.get()), Diag);
DR->parse();
if (auto EC = DR->parse()) {
return EC;
}
if (!DR->ParsingBuf.empty()) {
Diag << "WARNING: invalid profile data detected at line " << DR->Line
<< ". Possibly corrupted profile.\n";
}

DR->buildLTONameMaps();
return std::move(DR);
}
Expand Down Expand Up @@ -599,6 +605,12 @@ std::error_code DataReader::parse() {
if (!FlagOrErr)
return FlagOrErr.getError();
NoLBRMode = *FlagOrErr;

if (!hasBranchData() && !hasMemData()) {
Diag << "ERROR: no valid profile data found\n";
return make_error_code(llvm::errc::io_error);
}

if (NoLBRMode)
return parseInNoLBRMode();

Expand Down

0 comments on commit 27dcec9

Please sign in to comment.