diff options
author | Kristof Umann <dkszelethus@gmail.com> | 2019-08-21 22:38:00 +0000 |
---|---|---|
committer | Kristof Umann <dkszelethus@gmail.com> | 2019-08-21 22:38:00 +0000 |
commit | d9a81ccf05925e25df17cf64f7636ae78cd99d3d (patch) | |
tree | fc100a1d4a4643c20a8efc145c4c979218b4b910 /clang/lib/StaticAnalyzer | |
parent | 71dc97b5bfb771b480695659bcd5ba26f5cea083 (diff) | |
download | bcm5719-llvm-d9a81ccf05925e25df17cf64f7636ae78cd99d3d.tar.gz bcm5719-llvm-d9a81ccf05925e25df17cf64f7636ae78cd99d3d.zip |
[analyzer] Mention whether an event is about a condition in a bug report part 2
In D65724, I do a pretty thorough explanation about how I'm solving this
problem, I think that summary nails whats happening here ;)
Differential Revision: https://reviews.llvm.org/D65725
llvm-svn: 369596
Diffstat (limited to 'clang/lib/StaticAnalyzer')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index ccd147081d9..973580ed00a 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -213,6 +213,22 @@ getConcreteIntegerValue(const Expr *CondVarExpr, const ExplodedNode *N) { return None; } +static bool isVarAnInterestingCondition(const Expr *CondVarExpr, + const ExplodedNode *N, + const BugReport *B) { + // Even if this condition is marked as interesting, it isn't *that* + // interesting if it didn't happen in a nested stackframe, the user could just + // follow the arrows. + if (!B->getErrorNode()->getStackFrame()->isParentOf(N->getStackFrame())) + return false; + + if (Optional<SVal> V = getSValForVar(CondVarExpr, N)) + if (Optional<bugreporter::TrackingKind> K = B->getInterestingnessKind(*V)) + return *K == bugreporter::TrackingKind::Condition; + + return false; +} + static bool isInterestingExpr(const Expr *E, const ExplodedNode *N, const BugReport *B) { if (Optional<SVal> V = getSValForVar(E, N)) @@ -2454,6 +2470,10 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitTrueTest( const LocationContext *LCtx = N->getLocationContext(); const SourceManager &SM = BRC.getSourceManager(); + if (isVarAnInterestingCondition(BExpr->getLHS(), N, &R) || + isVarAnInterestingCondition(BExpr->getRHS(), N, &R)) + Out << WillBeUsedForACondition; + // Convert 'field ...' to 'Field ...' if it is a MemberExpr. std::string Message = Out.str(); Message[0] = toupper(Message[0]); @@ -2499,6 +2519,9 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitConditionVariable( const LocationContext *LCtx = N->getLocationContext(); PathDiagnosticLocation Loc(CondVarExpr, BRC.getSourceManager(), LCtx); + if (isVarAnInterestingCondition(CondVarExpr, N, &report)) + Out << WillBeUsedForACondition; + auto event = std::make_shared<PathDiagnosticEventPiece>(Loc, Out.str()); if (isInterestingExpr(CondVarExpr, N, &report)) @@ -2524,6 +2547,9 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitTrueTest( const LocationContext *LCtx = N->getLocationContext(); + if (isVarAnInterestingCondition(DRE, N, &report)) + Out << WillBeUsedForACondition; + // If we know the value create a pop-up note to the 'DRE'. if (!IsAssuming) { PathDiagnosticLocation Loc(DRE, BRC.getSourceManager(), LCtx); @@ -2563,6 +2589,10 @@ PathDiagnosticPieceRef ConditionBRVisitor::VisitTrueTest( if (!Loc.isValid() || !Loc.asLocation().isValid()) return nullptr; + if (isVarAnInterestingCondition(ME, N, &report)) + Out << WillBeUsedForACondition; + + // If we know the value create a pop-up note. if (!IsAssuming) return std::make_shared<PathDiagnosticPopUpPiece>(Loc, Out.str()); |