clang  8.0.0svn
Macros | Typedefs | Functions | Variables
BugReporter.cpp File Reference
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "clang/Analysis/ProgramPoint.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <memory>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "BugReporter"
 

Typedefs

using LocationContextMap = llvm::DenseMap< const PathPieces *, const LocationContext * >
 A map from PathDiagnosticPiece to the LocationContext of the inlined function call it represents. More...
 
using StackDiagPair = std::pair< PathDiagnosticCallPiece *, const ExplodedNode * >
 
using StackDiagVector = SmallVector< StackDiagPair, 6 >
 
using InterestingExprs = llvm::DenseSet< const Expr * >
 
using OptimizedCallsSet = llvm::DenseSet< const PathDiagnosticCallPiece * >
 
using VisitorsDiagnosticsTy = llvm::DenseMap< const ExplodedNode *, std::vector< std::shared_ptr< PathDiagnosticPiece > >>
 

Functions

 STATISTIC (MaxBugClassSize, "The maximum number of bug reports in the same equivalence class")
 
 STATISTIC (MaxValidBugClassSize, "The maximum number of bug reports in the same equivalence class " "where at least one report is valid (not suppressed)")
 
static const StmtGetPreviousStmt (const ExplodedNode *N)
 
static const StmtGetCurrentOrPreviousStmt (const ExplodedNode *N)
 
static PathDiagnosticEventPiece * eventsDescribeSameCondition (PathDiagnosticEventPiece *X, PathDiagnosticEventPiece *Y)
 
static void removeRedundantMsgs (PathPieces &path)
 An optimization pass over PathPieces that removes redundant diagnostics generated by both ConditionBRVisitor and TrackConstraintBRVisitor. More...
 
static bool removeUnneededCalls (PathPieces &pieces, BugReport *R, LocationContextMap &LCM, bool IsInteresting=false)
 Recursively scan through a path and prune out calls and macros pieces that aren't needed. More...
 
static bool hasImplicitBody (const Decl *D)
 Returns true if the given decl has been implicitly given a body, either by the analyzer or by the compiler proper. More...
 
static void adjustCallLocations (PathPieces &Pieces, PathDiagnosticLocation *LastCallLocation=nullptr)
 Recursively scan through a path and make sure that all call pieces have valid locations. More...
 
static void removeEdgesToDefaultInitializers (PathPieces &Pieces)
 Remove edges in and out of C++ default initializer expressions. More...
 
static void removePiecesWithInvalidLocations (PathPieces &Pieces)
 Remove all pieces with invalid locations as these cannot be serialized. More...
 
static const StmtgetEnclosingParent (const Stmt *S, const ParentMap &PM)
 
static PathDiagnosticLocation getEnclosingStmtLocation (const Stmt *S, SourceManager &SMgr, const ParentMap &P, const LocationContext *LC, bool allowNestedContexts)
 
static void updateStackPiecesWithMessage (PathDiagnosticPiece &P, StackDiagVector &CallStack)
 
static void CompactPathDiagnostic (PathPieces &path, const SourceManager &SM)
 CompactPathDiagnostic - This function postprocesses a PathDiagnostic object and collapses PathDiagosticPieces that are expanded by macros. More...
 
std::shared_ptr< PathDiagnosticControlFlowPiece > generateDiagForSwitchOP (const ExplodedNode *N, const CFGBlock *Dst, const SourceManager &SM, const LocationContext *LC, PathDiagnosticBuilder &PDB, PathDiagnosticLocation &Start)
 
std::shared_ptr< PathDiagnosticControlFlowPiece > generateDiagForGotoOP (const Stmt *S, PathDiagnosticBuilder &PDB, PathDiagnosticLocation &Start)
 
std::shared_ptr< PathDiagnosticControlFlowPiece > generateDiagForBinaryOP (const ExplodedNode *N, const Stmt *T, const CFGBlock *Src, const CFGBlock *Dst, const SourceManager &SM, PathDiagnosticBuilder &PDB, const LocationContext *LC)
 
void generateMinimalDiagForBlockEdge (const ExplodedNode *N, BlockEdge BE, const SourceManager &SM, PathDiagnosticBuilder &PDB, PathDiagnostic &PD)
 
static void reversePropagateIntererstingSymbols (BugReport &R, InterestingExprs &IE, const ProgramState *State, const Expr *Ex, const LocationContext *LCtx)
 
static void reversePropagateInterestingSymbols (BugReport &R, InterestingExprs &IE, const ProgramState *State, const LocationContext *CalleeCtx)
 
static bool isLoop (const Stmt *Term)
 
static bool isJumpToFalseBranch (const BlockEdge *BE)
 
static bool isContainedByStmt (ParentMap &PM, const Stmt *S, const Stmt *SubS)
 
static const StmtgetStmtBeforeCond (ParentMap &PM, const Stmt *Term, const ExplodedNode *N)
 
static bool isInLoopBody (ParentMap &PM, const Stmt *S, const Stmt *Term)
 
static void addEdgeToPath (PathPieces &path, PathDiagnosticLocation &PrevLoc, PathDiagnosticLocation NewLoc)
 Adds a sanitized control-flow diagnostic edge to a path. More...
 
static const StmtgetTerminatorCondition (const CFGBlock *B)
 A customized wrapper for CFGBlock::getTerminatorCondition() which returns the element for ObjCForCollectionStmts. More...
 
static std::unique_ptr< FilesToLineNumsMap > findExecutedLines (SourceManager &SM, const ExplodedNode *N)
 
static void generatePathDiagnosticsForNode (const ExplodedNode *N, PathDiagnostic &PD, PathDiagnosticLocation &PrevLoc, PathDiagnosticBuilder &PDB, LocationContextMap &LCM, StackDiagVector &CallStack, InterestingExprs &IE, bool AddPathEdges)
 Generate diagnostics for the node N, and write it into PD. More...
 
static std::unique_ptr< PathDiagnostic > generateEmptyDiagnosticForReport (BugReport *R, SourceManager &SM)
 
static const StmtgetStmtParent (const Stmt *S, const ParentMap &PM)
 
static bool isConditionForTerminator (const Stmt *S, const Stmt *Cond)
 
static bool isIncrementOrInitInForLoop (const Stmt *S, const Stmt *FL)
 
static void addContextEdges (PathPieces &pieces, SourceManager &SM, const ParentMap &PM, const LocationContext *LCtx)
 Adds synthetic edges from top-level statements to their subexpressions. More...
 
static void simplifySimpleBranches (PathPieces &pieces)
 Move edges from a branch condition to a branch target when the condition is simple. More...
 
static Optional< size_tgetLengthOnSingleLine (SourceManager &SM, SourceRange Range)
 Returns the number of bytes in the given (character-based) SourceRange. More...
 
static Optional< size_tgetLengthOnSingleLine (SourceManager &SM, const Stmt *S)
 
static void removeContextCycles (PathPieces &Path, SourceManager &SM)
 Eliminate two-edge cycles created by addContextEdges(). More...
 
static bool lexicalContains (ParentMap &PM, const Stmt *X, const Stmt *Y)
 Return true if X is contained by Y. More...
 
static void removePunyEdges (PathPieces &path, SourceManager &SM, ParentMap &PM)
 
static void removeIdenticalEvents (PathPieces &path)
 
static bool optimizeEdges (PathPieces &path, SourceManager &SM, OptimizedCallsSet &OCS, LocationContextMap &LCM)
 
static void dropFunctionEntryEdge (PathPieces &Path, LocationContextMap &LCM, SourceManager &SM)
 Drop the very first edge in a path, which should be a function entry edge. More...
 
static void updateExecutedLinesWithDiagnosticPieces (PathDiagnostic &PD)
 Populate executes lines with lines containing at least one diagnostics. More...
 
static std::unique_ptr< PathDiagnostic > generatePathDiagnosticForConsumer (PathDiagnosticConsumer::PathGenerationScheme ActiveScheme, PathDiagnosticBuilder &PDB, const ExplodedNode *ErrorNode, const VisitorsDiagnosticsTy &VisitorsDiagnostics)
 This function is responsible for generating diagnostic pieces that are not provided by bug report visitors. More...
 

Variables

static const char StrEnteringLoop [] = "Entering loop body"
 
static const char StrLoopBodyZero [] = "Loop body executed 0 times"
 
static const char StrLoopRangeEmpty []
 
static const char StrLoopCollectionEmpty []
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "BugReporter"

Definition at line 76 of file BugReporter.cpp.

Typedef Documentation

◆ InterestingExprs

Definition at line 829 of file BugReporter.cpp.

◆ LocationContextMap

using LocationContextMap = llvm::DenseMap<const PathPieces *, const LocationContext *>

A map from PathDiagnosticPiece to the LocationContext of the inlined function call it represents.

Definition at line 189 of file BugReporter.cpp.

◆ OptimizedCallsSet

using OptimizedCallsSet = llvm::DenseSet<const PathDiagnosticCallPiece *>

Definition at line 1329 of file BugReporter.cpp.

◆ StackDiagPair

using StackDiagPair = std::pair<PathDiagnosticCallPiece *, const ExplodedNode *>

Definition at line 526 of file BugReporter.cpp.

◆ StackDiagVector

Definition at line 527 of file BugReporter.cpp.

◆ VisitorsDiagnosticsTy

using VisitorsDiagnosticsTy = llvm::DenseMap<const ExplodedNode *, std::vector<std::shared_ptr<PathDiagnosticPiece> >>

Definition at line 1877 of file BugReporter.cpp.

Function Documentation

◆ addContextEdges()

static void addContextEdges ( PathPieces &  pieces,
SourceManager SM,
const ParentMap PM,
const LocationContext LCtx 
)
static

Adds synthetic edges from top-level statements to their subexpressions.

This avoids a "swoosh" effect, where an edge from a top-level statement A points to a sub-expression B.1 that's not at the start of B. In these cases, we'd like to see an edge from A to B, then another one from B to B.1.

Definition at line 1336 of file BugReporter.cpp.

References getEnclosingStmtLocation(), getStmtParent(), and P.

Referenced by optimizeEdges().

◆ addEdgeToPath()

static void addEdgeToPath ( PathPieces &  path,
PathDiagnosticLocation &  PrevLoc,
PathDiagnosticLocation  NewLoc 
)
static

Adds a sanitized control-flow diagnostic edge to a path.

Definition at line 967 of file BugReporter.cpp.

References clang::SourceLocation::isInvalid().

Referenced by generatePathDiagnosticForConsumer(), and generatePathDiagnosticsForNode().

◆ adjustCallLocations()

static void adjustCallLocations ( PathPieces &  Pieces,
PathDiagnosticLocation *  LastCallLocation = nullptr 
)
static

Recursively scan through a path and make sure that all call pieces have valid locations.

Definition at line 256 of file BugReporter.cpp.

References hasImplicitBody(), and clang::if().

Referenced by generatePathDiagnosticForConsumer().

◆ CompactPathDiagnostic()

static void CompactPathDiagnostic ( PathPieces &  path,
const SourceManager SM 
)
static

CompactPathDiagnostic - This function postprocesses a PathDiagnostic object and collapses PathDiagosticPieces that are expanded by macros.

Definition at line 2441 of file BugReporter.cpp.

References clang::AnalyzerOptions::AnalyzeAll, clang::CFGBlock::begin(), clang::ento::BugReporterContext::BugReporterContext(), clang::ento::PathDiagnosticLocation::createSingleLocation(), clang::ento::BugReporter::EmitBasicReport(), clang::ento::BugReporter::emitReport(), End, clang::CFGBlock::end(), findExecutedLines(), generateEmptyDiagnosticForReport(), generatePathDiagnosticForConsumer(), clang::ento::GRBugReporter::generatePathDiagnostics(), clang::ento::BugReporterContext::getAnalyzerOptions(), clang::ProgramPoint::getAs(), clang::SourceRange::getBegin(), clang::Decl::getBody(), clang::SourceRange::getEnd(), clang::CFG::getExit(), clang::SourceManager::getExpansionLineNumber(), clang::SourceManager::getExpansionLoc(), clang::SourceManager::getFileID(), clang::ento::BugReporterContext::getGraph(), clang::ento::BugReporterContext::getSourceManager(), clang::Stmt::getSourceRange(), clang::ento::PathDiagnosticLocation::getStmt(), clang::CFGBlock::hasNoReturnElement(), clang::AnalysisDeclContext::isBodyAutosynthesized(), clang::AnalysisDeclContext::isBodyAutosynthesizedFromModelFile(), clang::SourceLocation::isFileID(), clang::SourceLocation::isMacroID(), clang::SourceLocation::isValid(), Line, P, clang::ento::BugReporter::Register(), clang::AnalyzerOptions::shouldCrosscheckWithZ3(), clang::AnalyzerOptions::shouldReportIssuesInMainSourceFile(), clang::CFGBlock::succs(), and updateExecutedLinesWithDiagnosticPieces().

Referenced by generatePathDiagnosticForConsumer(), and updateStackPiecesWithMessage().

◆ dropFunctionEntryEdge()

static void dropFunctionEntryEdge ( PathPieces &  Path,
LocationContextMap LCM,
SourceManager SM 
)
static

Drop the very first edge in a path, which should be a function entry edge.

If the first edge is not a function entry edge (say, because the first statement had an invalid source location), this function does nothing.

Definition at line 1861 of file BugReporter.cpp.

References clang::ento::PathDiagnosticLocation::createBegin().

Referenced by generatePathDiagnosticForConsumer().

◆ eventsDescribeSameCondition()

static PathDiagnosticEventPiece* eventsDescribeSameCondition ( PathDiagnosticEventPiece *  X,
PathDiagnosticEventPiece *  Y 
)
static

Definition at line 113 of file BugReporter.cpp.

References X.

Referenced by removeRedundantMsgs().

◆ findExecutedLines()

static std::unique_ptr<FilesToLineNumsMap> findExecutedLines ( SourceManager SM,
const ExplodedNode *  N 
)
static

◆ generateDiagForBinaryOP()

std::shared_ptr<PathDiagnosticControlFlowPiece> generateDiagForBinaryOP ( const ExplodedNode *  N,
const Stmt T,
const CFGBlock Src,
const CFGBlock Dst,
const SourceManager SM,
PathDiagnosticBuilder &  PDB,
const LocationContext LC 
)

◆ generateDiagForGotoOP()

std::shared_ptr<PathDiagnosticControlFlowPiece> generateDiagForGotoOP ( const Stmt S,
PathDiagnosticBuilder &  PDB,
PathDiagnosticLocation &  Start 
)

Definition at line 614 of file BugReporter.cpp.

References End.

Referenced by generateMinimalDiagForBlockEdge().

◆ generateDiagForSwitchOP()

std::shared_ptr<PathDiagnosticControlFlowPiece> generateDiagForSwitchOP ( const ExplodedNode *  N,
const CFGBlock Dst,
const SourceManager SM,
const LocationContext LC,
PathDiagnosticBuilder &  PDB,
PathDiagnosticLocation &  Start 
)

◆ generateEmptyDiagnosticForReport()

static std::unique_ptr<PathDiagnostic> generateEmptyDiagnosticForReport ( BugReport *  R,
SourceManager SM 
)
static

Definition at line 1248 of file BugReporter.cpp.

References findExecutedLines().

Referenced by CompactPathDiagnostic(), and generatePathDiagnosticForConsumer().

◆ generateMinimalDiagForBlockEdge()

void generateMinimalDiagForBlockEdge ( const ExplodedNode *  N,
BlockEdge  BE,
const SourceManager SM,
PathDiagnosticBuilder &  PDB,
PathDiagnostic &  PD 
)

◆ generatePathDiagnosticForConsumer()

static std::unique_ptr<PathDiagnostic> generatePathDiagnosticForConsumer ( PathDiagnosticConsumer::PathGenerationScheme  ActiveScheme,
PathDiagnosticBuilder &  PDB,
const ExplodedNode *  ErrorNode,
const VisitorsDiagnosticsTy VisitorsDiagnostics 
)
static

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, and are therefore constructed separately for each consumer.

There are two path diagnostics generation modes: with adding edges (used for plists) and without (used for HTML and text). When edges are added (ActiveScheme is Extensive), the path is modified to insert artificially generated edges. Otherwise, more detailed diagnostics is emitted for block edges, explaining the transitions in words.

Definition at line 1907 of file BugReporter.cpp.

References addEdgeToPath(), adjustCallLocations(), CompactPathDiagnostic(), clang::ento::PathDiagnosticLocation::createBegin(), dropFunctionEntryEdge(), clang::ento::PathDiagnosticConsumer::Extensive, generateEmptyDiagnosticForReport(), generatePathDiagnosticsForNode(), clang::LocationContext::getDecl(), clang::ento::PathDiagnosticConsumer::None, optimizeEdges(), P, removeEdgesToDefaultInitializers(), removePiecesWithInvalidLocations(), removeRedundantMsgs(), removeUnneededCalls(), clang::AnalyzerOptions::shouldPrunePaths(), SM, and updateStackPiecesWithMessage().

Referenced by CompactPathDiagnostic().

◆ generatePathDiagnosticsForNode()

static void generatePathDiagnosticsForNode ( const ExplodedNode *  N,
PathDiagnostic &  PD,
PathDiagnosticLocation &  PrevLoc,
PathDiagnosticBuilder &  PDB,
LocationContextMap LCM,
StackDiagVector CallStack,
InterestingExprs IE,
bool  AddPathEdges 
)
static

◆ GetCurrentOrPreviousStmt()

static const Stmt* GetCurrentOrPreviousStmt ( const ExplodedNode *  N)
inlinestatic

Definition at line 101 of file BugReporter.cpp.

Referenced by clang::ento::BugReport::Profile().

◆ getEnclosingParent()

static const Stmt* getEnclosingParent ( const Stmt S,
const ParentMap PM 
)
static

Definition at line 426 of file BugReporter.cpp.

◆ getEnclosingStmtLocation()

static PathDiagnosticLocation getEnclosingStmtLocation ( const Stmt S,
SourceManager SMgr,
const ParentMap P,
const LocationContext LC,
bool  allowNestedContexts 
)
static

Definition at line 449 of file BugReporter.cpp.

Referenced by addContextEdges().

◆ getLengthOnSingleLine() [1/2]

static Optional<size_t> getLengthOnSingleLine ( SourceManager SM,
SourceRange  Range 
)
static

Returns the number of bytes in the given (character-based) SourceRange.

If the locations in the range are not on the same line, returns None.

Note that this does not do a precise user-visible character or column count.

Definition at line 1488 of file BugReporter.cpp.

References clang::SourceRange::getBegin(), clang::SourceManager::getBuffer(), clang::SourceRange::getEnd(), clang::SourceManager::getExpansionLoc(), clang::SourceManager::getExpansionRange(), clang::SourceManager::getFileID(), and clang::SourceManager::getFileOffset().

Referenced by getLengthOnSingleLine(), optimizeEdges(), removeContextCycles(), and removePunyEdges().

◆ getLengthOnSingleLine() [2/2]

static Optional<size_t> getLengthOnSingleLine ( SourceManager SM,
const Stmt S 
)
static
See also
getLengthOnSingleLine(SourceManager, SourceRange)

Definition at line 1518 of file BugReporter.cpp.

References getLengthOnSingleLine(), and clang::Stmt::getSourceRange().

◆ GetPreviousStmt()

static const Stmt* GetPreviousStmt ( const ExplodedNode *  N)
static

Definition at line 92 of file BugReporter.cpp.

Referenced by clang::ento::BugReport::getStmt().

◆ getStmtBeforeCond()

static const Stmt* getStmtBeforeCond ( ParentMap PM,
const Stmt Term,
const ExplodedNode *  N 
)
static

Definition at line 919 of file BugReporter.cpp.

References isContainedByStmt().

Referenced by generatePathDiagnosticsForNode().

◆ getStmtParent()

static const Stmt* getStmtParent ( const Stmt S,
const ParentMap PM 
)
static

Definition at line 1258 of file BugReporter.cpp.

References clang::ParentMap::getParentIgnoreParens().

Referenced by addContextEdges(), and optimizeEdges().

◆ getTerminatorCondition()

static const Stmt* getTerminatorCondition ( const CFGBlock B)
static

A customized wrapper for CFGBlock::getTerminatorCondition() which returns the element for ObjCForCollectionStmts.

Definition at line 994 of file BugReporter.cpp.

References clang::CFGBlock::getTerminatorCondition().

Referenced by generatePathDiagnosticsForNode(), clang::CFGBlock::getTerminator(), and clang::CFGBlock::getTerminatorCondition().

◆ hasImplicitBody()

static bool hasImplicitBody ( const Decl D)
static

Returns true if the given decl has been implicitly given a body, either by the analyzer or by the compiler proper.

Definition at line 248 of file BugReporter.cpp.

References clang::Decl::hasBody(), and clang::Decl::isImplicit().

Referenced by adjustCallLocations().

◆ isConditionForTerminator()

static bool isConditionForTerminator ( const Stmt S,
const Stmt Cond 
)
static

Definition at line 1279 of file BugReporter.cpp.

References clang::Stmt::getStmtClass().

Referenced by optimizeEdges(), removePunyEdges(), and simplifySimpleBranches().

◆ isContainedByStmt()

static bool isContainedByStmt ( ParentMap PM,
const Stmt S,
const Stmt SubS 
)
static

Definition at line 910 of file BugReporter.cpp.

References clang::ParentMap::getParent().

Referenced by getStmtBeforeCond(), and isInLoopBody().

◆ isIncrementOrInitInForLoop()

static bool isIncrementOrInitInForLoop ( const Stmt S,
const Stmt FL 
)
static

Definition at line 1320 of file BugReporter.cpp.

Referenced by optimizeEdges().

◆ isInLoopBody()

static bool isInLoopBody ( ParentMap PM,
const Stmt S,
const Stmt Term 
)
static

Definition at line 933 of file BugReporter.cpp.

References clang::Stmt::getStmtClass(), and isContainedByStmt().

Referenced by generatePathDiagnosticsForNode().

◆ isJumpToFalseBranch()

static bool isJumpToFalseBranch ( const BlockEdge BE)
static

◆ isLoop()

static bool isLoop ( const Stmt Term)
static

Definition at line 891 of file BugReporter.cpp.

References clang::Stmt::getStmtClass().

Referenced by generatePathDiagnosticsForNode().

◆ lexicalContains()

static bool lexicalContains ( ParentMap PM,
const Stmt X,
const Stmt Y 
)
static

Return true if X is contained by Y.

Definition at line 1594 of file BugReporter.cpp.

References clang::ParentMap::getParent().

Referenced by optimizeEdges().

◆ optimizeEdges()

static bool optimizeEdges ( PathPieces &  path,
SourceManager SM,
OptimizedCallsSet OCS,
LocationContextMap LCM 
)
static

◆ removeContextCycles()

static void removeContextCycles ( PathPieces &  Path,
SourceManager SM 
)
static

Eliminate two-edge cycles created by addContextEdges().

Once all the context edges are in place, there are plenty of cases where there's a single edge from a top-level statement to a subexpression, followed by a single path note, and then a reverse edge to get back out to the top level. If the statement is simple enough, the subexpression edges just add noise and make it harder to understand what's going on.

This function only removes edges in pairs, because removing only one edge might leave other edges dangling.

This will not remove edges in more complicated situations:

  • if there is more than one "hop" leading to or from a subexpression.
  • if there is an inlined call between the edges instead of a single event.
  • if the whole statement is large enough that having subexpression arrows might be helpful.

Definition at line 1539 of file BugReporter.cpp.

References getLengthOnSingleLine().

Referenced by optimizeEdges().

◆ removeEdgesToDefaultInitializers()

static void removeEdgesToDefaultInitializers ( PathPieces &  Pieces)
static

Remove edges in and out of C++ default initializer expressions.

These are for fields that have in-class initializers, as opposed to being initialized explicitly in a constructor or braced list.

Definition at line 289 of file BugReporter.cpp.

References End.

Referenced by generatePathDiagnosticForConsumer().

◆ removeIdenticalEvents()

static void removeIdenticalEvents ( PathPieces &  path)
static

Definition at line 1657 of file BugReporter.cpp.

Referenced by optimizeEdges().

◆ removePiecesWithInvalidLocations()

static void removePiecesWithInvalidLocations ( PathPieces &  Pieces)
static

Remove all pieces with invalid locations as these cannot be serialized.

We might have pieces with invalid locations as a result of inlining Body Farm generated functions.

Definition at line 323 of file BugReporter.cpp.

References clang::ento::BugReporterContext::BugReporterContext(), and clang::LocationContext::getParentMap().

Referenced by generatePathDiagnosticForConsumer().

◆ removePunyEdges()

static void removePunyEdges ( PathPieces &  path,
SourceManager SM,
ParentMap PM 
)
static

◆ removeRedundantMsgs()

static void removeRedundantMsgs ( PathPieces &  path)
static

An optimization pass over PathPieces that removes redundant diagnostics generated by both ConditionBRVisitor and TrackConstraintBRVisitor.

Both BugReporterVisitors use different methods to generate diagnostics, with one capable of emitting diagnostics in some cases but not in others. This can lead to redundant diagnostic pieces at the same point in a path.

Definition at line 139 of file BugReporter.cpp.

References clang::ento::PathDiagnosticPiece::Call, clang::ento::PathDiagnosticPiece::ControlFlow, clang::ento::PathDiagnosticPiece::Event, eventsDescribeSameCondition(), clang::ento::PathDiagnosticPiece::Macro, and clang::ento::PathDiagnosticPiece::Note.

Referenced by generatePathDiagnosticForConsumer().

◆ removeUnneededCalls()

static bool removeUnneededCalls ( PathPieces &  pieces,
BugReport *  R,
LocationContextMap LCM,
bool  IsInteresting = false 
)
static

Recursively scan through a path and prune out calls and macros pieces that aren't needed.

Return true if afterwards the path contains "interesting stuff" which means it shouldn't be pruned from the parent path.

Definition at line 194 of file BugReporter.cpp.

References clang::ento::PathDiagnosticPiece::Call, clang::ento::PathDiagnosticPiece::ControlFlow, clang::ento::PathDiagnosticPiece::Event, clang::ento::PathDiagnosticPiece::Macro, and clang::ento::PathDiagnosticPiece::Note.

Referenced by generatePathDiagnosticForConsumer().

◆ reversePropagateIntererstingSymbols()

static void reversePropagateIntererstingSymbols ( BugReport &  R,
InterestingExprs IE,
const ProgramState *  State,
const Expr Ex,
const LocationContext LCtx 
)
static

◆ reversePropagateInterestingSymbols()

static void reversePropagateInterestingSymbols ( BugReport &  R,
InterestingExprs IE,
const ProgramState *  State,
const LocationContext CalleeCtx 
)
static

◆ simplifySimpleBranches()

static void simplifySimpleBranches ( PathPieces &  pieces)
static

Move edges from a branch condition to a branch target when the condition is simple.

This restructures some of the work of addContextEdges. That function creates edges this may destroy, but they work together to create a more aesthetically set of edges around branches. After the call to addContextEdges, we may have (1) an edge to the branch, (2) an edge from the branch to the branch condition, and (3) an edge from the branch condition to the branch target. We keep (1), but may wish to remove (2) and move the source of (3) to the branch if the branch condition is simple.

Definition at line 1418 of file BugReporter.cpp.

References isConditionForTerminator(), StrEnteringLoop, StrLoopBodyZero, StrLoopCollectionEmpty, and StrLoopRangeEmpty.

Referenced by optimizeEdges().

◆ STATISTIC() [1/2]

STATISTIC ( MaxBugClassSize  ,
"The maximum number of bug reports in the same equivalence class"   
)

◆ STATISTIC() [2/2]

STATISTIC ( MaxValidBugClassSize  ,
"The maximum number of bug reports in the same equivalence class " "where at least one report is valid (not suppressed)"   
)

◆ updateExecutedLinesWithDiagnosticPieces()

static void updateExecutedLinesWithDiagnosticPieces ( PathDiagnostic &  PD)
static

Populate executes lines with lines containing at least one diagnostics.

Definition at line 1880 of file BugReporter.cpp.

References clang::FullSourceLoc::getFileID(), clang::FullSourceLoc::getLineNumber(), clang::FileID::isValid(), and P.

Referenced by CompactPathDiagnostic().

◆ updateStackPiecesWithMessage()

static void updateStackPiecesWithMessage ( PathDiagnosticPiece &  P,
StackDiagVector CallStack 
)
static

Definition at line 529 of file BugReporter.cpp.

References CompactPathDiagnostic(), and SM.

Referenced by generatePathDiagnosticForConsumer().

Variable Documentation

◆ StrEnteringLoop

const char StrEnteringLoop[] = "Entering loop body"
static

Definition at line 1001 of file BugReporter.cpp.

Referenced by generatePathDiagnosticsForNode(), and simplifySimpleBranches().

◆ StrLoopBodyZero

const char StrLoopBodyZero[] = "Loop body executed 0 times"
static

Definition at line 1002 of file BugReporter.cpp.

Referenced by generatePathDiagnosticsForNode(), and simplifySimpleBranches().

◆ StrLoopCollectionEmpty

const char StrLoopCollectionEmpty[]
static
Initial value:
=
"Loop body skipped when collection is empty"

Definition at line 1005 of file BugReporter.cpp.

Referenced by generatePathDiagnosticsForNode(), and simplifySimpleBranches().

◆ StrLoopRangeEmpty

const char StrLoopRangeEmpty[]
static
Initial value:
=
"Loop body skipped when range is empty"

Definition at line 1003 of file BugReporter.cpp.

Referenced by generatePathDiagnosticsForNode(), and simplifySimpleBranches().