forked from OSchip/llvm-project
[analyzer] Push updating-the-executed-lines logic into the BugReporter.
So it can be reused across different consumers. Differential Revision: https://reviews.llvm.org/D51514 llvm-svn: 341617
This commit is contained in:
parent
98bee02297
commit
5f8d361c9c
|
@ -858,13 +858,13 @@ public:
|
|||
meta_iterator meta_end() const { return OtherDesc.end(); }
|
||||
void addMeta(StringRef s) { OtherDesc.push_back(s); }
|
||||
|
||||
using filesmap_iterator = FilesToLineNumsMap::const_iterator;
|
||||
|
||||
filesmap_iterator executedLines_begin() const {
|
||||
return ExecutedLines->begin();
|
||||
const FilesToLineNumsMap &getExecutedLines() const {
|
||||
return *ExecutedLines;
|
||||
}
|
||||
|
||||
filesmap_iterator executedLines_end() const { return ExecutedLines->end(); }
|
||||
FilesToLineNumsMap &getExecutedLines() {
|
||||
return *ExecutedLines;
|
||||
}
|
||||
|
||||
PathDiagnosticLocation getLocation() const {
|
||||
return Loc;
|
||||
|
|
|
@ -1881,6 +1881,21 @@ static void dropFunctionEntryEdge(PathPieces &Path, LocationContextMap &LCM,
|
|||
using VisitorsDiagnosticsTy = llvm::DenseMap<const ExplodedNode *,
|
||||
std::vector<std::shared_ptr<PathDiagnosticPiece>>>;
|
||||
|
||||
/// Populate executes lines with lines containing at least one diagnostics.
|
||||
static void updateExecutedLinesWithDiagnosticPieces(
|
||||
PathDiagnostic &PD) {
|
||||
|
||||
PathPieces path = PD.path.flatten(/*ShouldFlattenMacros=*/true);
|
||||
FilesToLineNumsMap &ExecutedLines = PD.getExecutedLines();
|
||||
|
||||
for (const auto &P : path) {
|
||||
FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
|
||||
FileID FID = Loc.getFileID();
|
||||
unsigned LineNo = Loc.getLineNumber();
|
||||
ExecutedLines[FID.getHashValue()].insert(LineNo);
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is responsible for generating diagnostic pieces that are
|
||||
/// *not* provided by bug report visitors.
|
||||
/// These diagnostics may differ depending on the consumer's settings,
|
||||
|
@ -2985,6 +3000,7 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) {
|
|||
for (const auto &i : Meta)
|
||||
PD->addMeta(i);
|
||||
|
||||
updateExecutedLinesWithDiagnosticPieces(*PD);
|
||||
Consumer->HandlePathDiagnostic(std::move(PD));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,23 +337,8 @@ static void serializeExecutedLines(
|
|||
const PathDiagnostic &D,
|
||||
const PathPieces &path,
|
||||
llvm::raw_string_ostream &os) {
|
||||
// Copy executed lines from path diagnostics.
|
||||
std::map<unsigned, std::set<unsigned>> ExecutedLines;
|
||||
for (auto I = D.executedLines_begin(),
|
||||
E = D.executedLines_end(); I != E; ++I) {
|
||||
std::set<unsigned> &LinesInFile = ExecutedLines[I->first];
|
||||
for (unsigned LineNo : I->second) {
|
||||
LinesInFile.insert(LineNo);
|
||||
}
|
||||
}
|
||||
|
||||
// We need to include all lines for which any kind of diagnostics appears.
|
||||
for (const auto &P : path) {
|
||||
FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
|
||||
FileID FID = Loc.getFileID();
|
||||
unsigned LineNo = Loc.getLineNumber();
|
||||
ExecutedLines[FID.getHashValue()].insert(LineNo);
|
||||
}
|
||||
const FilesToLineNumsMap &ExecutedLines = D.getExecutedLines();
|
||||
|
||||
os << "var relevant_lines = {";
|
||||
for (auto I = ExecutedLines.begin(),
|
||||
|
|
Loading…
Reference in New Issue