diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-01-26 01:28:19 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-01-26 01:28:19 +0000 |
commit | dede2fd56d053a114a65ba72583981ce7aab27da (patch) | |
tree | 62f34acd9fc7791600a0e5568de96b14080b144d | |
parent | aeca2cc3a6f486abff3fdfb4e82903cd3ca4267e (diff) |
[analyzer] bugreporter::getDerefExpr now takes a Stmt, not an ExplodedNode.
This allows it to be used in places where the interesting statement
doesn't match up with the current node. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173546 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h | 2 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp | 4 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 24 |
3 files changed, 13 insertions, 17 deletions
diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h index dcd078f5b3..86f9af352c 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h @@ -275,7 +275,7 @@ namespace bugreporter { bool trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, BugReport &R, bool IsArg = false); -const Stmt *GetDerefExpr(const ExplodedNode *N); +const Expr *getDerefExpr(const Stmt *S); const Stmt *GetDenomExpr(const ExplodedNode *N); const Stmt *GetRetValExpr(const ExplodedNode *N); bool isDeclRefExprToReference(const Expr *E); diff --git a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp index df2fd71f1c..c77e2e3e4c 100644 --- a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -157,7 +157,7 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S, buf.empty() ? BT_null->getDescription() : buf.str(), N); - bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N), *report); + bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S), *report); for (SmallVectorImpl<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end(); I!=E; ++I) @@ -176,7 +176,7 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S, BugReport *report = new BugReport(*BT_undef, BT_undef->getDescription(), N); - bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N), + bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S), *report); C.emitReport(report); } diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 33c0ba8865..7cd1319af2 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -38,37 +38,33 @@ bool bugreporter::isDeclRefExprToReference(const Expr *E) { return false; } -const Stmt *bugreporter::GetDerefExpr(const ExplodedNode *N) { +const Expr *bugreporter::getDerefExpr(const Stmt *S) { // Pattern match for a few useful cases (do something smarter later): // a[0], p->f, *p - const PostStmt *Loc = N->getLocationAs<PostStmt>(); - if (!Loc) + const Expr *E = dyn_cast<Expr>(S); + if (!E) return 0; - - const Expr *S = dyn_cast<Expr>(Loc->getStmt()); - if (!S) - return 0; - S = S->IgnoreParenCasts(); + E = E->IgnoreParenCasts(); while (true) { - if (const BinaryOperator *B = dyn_cast<BinaryOperator>(S)) { + if (const BinaryOperator *B = dyn_cast<BinaryOperator>(E)) { assert(B->isAssignmentOp()); - S = B->getLHS()->IgnoreParenCasts(); + E = B->getLHS()->IgnoreParenCasts(); continue; } - else if (const UnaryOperator *U = dyn_cast<UnaryOperator>(S)) { + else if (const UnaryOperator *U = dyn_cast<UnaryOperator>(E)) { if (U->getOpcode() == UO_Deref) return U->getSubExpr()->IgnoreParenCasts(); } - else if (const MemberExpr *ME = dyn_cast<MemberExpr>(S)) { + else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) { return ME->getBase()->IgnoreParenCasts(); } } - else if (const ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(S)) { + else if (const ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) { return IvarRef->getBase()->IgnoreParenCasts(); } - else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(S)) { + else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(E)) { return AE->getBase(); } break; |