[analyzer] bugreporter::getDerefExpr now takes a Stmt, not an ExplodedNode.
authorJordan Rose <jordan_rose@apple.com>
Sat, 26 Jan 2013 01:28:19 +0000 (01:28 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 26 Jan 2013 01:28:19 +0000 (01:28 +0000)
This allows it to be used in places where the interesting statement
doesn't match up with the current node. No functionality change.

llvm-svn: 173546

clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

index dcd078f..86f9af3 100644 (file)
@@ -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);
index df2fd71..c77e2e3 100644 (file)
@@ -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);
     }
index 33c0ba8..7cd1319 100644 (file)
@@ -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;