diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -406,11 +406,12 @@ ProfiledBinary *Binary = nullptr; while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().startswith(" 0x")) { StringRef FrameStr = TraceIt.getCurrentLine().ltrim(); - // We might get an empty line at the beginning or comments, skip it uint64_t FrameAddr = 0; if (FrameStr.getAsInteger(16, FrameAddr)) { + // We might parse a non-perf sample line like empty line and comments, + // skip it TraceIt.advance(); - break; + return false; } TraceIt.advance(); if (!Binary) { @@ -437,8 +438,6 @@ CallStack.emplace_back(FrameAddr); } - if (CallStack.empty()) - return false; // Skip other unrelated line, find the next valid LBR line while (!TraceIt.isAtEoF() && !TraceIt.getCurrentLine().startswith(" 0x")) { TraceIt.advance(); @@ -451,7 +450,8 @@ // of such case - when sample landed in prolog/epilog, somehow stack // walking will be broken in an unexpected way that higher frames will be // missing. - return !Binary->addressInPrologEpilog(CallStack.front()); + return !CallStack.empty() && + !Binary->addressInPrologEpilog(CallStack.front()); } void PerfReader::parseHybridSample(TraceStream &TraceIt) {