[cfe-commits] r163260 - /cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp

Anna Zaks ganna at apple.com
Wed Sep 5 15:31:49 PDT 2012


Author: zaks
Date: Wed Sep  5 17:31:49 2012
New Revision: 163260

URL: http://llvm.org/viewvc/llvm-project?rev=163260&view=rev
Log:
[analyzer] Remove unneeded code.

This region is set as interesting as part of trackNullOrUndefValue call,
no need to mark it as interesting twice.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp?rev=163260&r1=163259&r2=163260&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp Wed Sep  5 17:31:49 2012
@@ -39,7 +39,7 @@
                      CheckerContext &C) const;
   void checkBind(SVal L, SVal V, const Stmt *S, CheckerContext &C) const;
 
-  static const MemRegion *AddDerefSource(raw_ostream &os,
+  static void AddDerefSource(raw_ostream &os,
                              SmallVectorImpl<SourceRange> &Ranges,
                              const Expr *Ex, const ProgramState *state,
                              const LocationContext *LCtx,
@@ -47,7 +47,7 @@
 };
 } // end anonymous namespace
 
-const MemRegion *
+void
 DereferenceChecker::AddDerefSource(raw_ostream &os,
                                    SmallVectorImpl<SourceRange> &Ranges,
                                    const Expr *Ex,
@@ -55,7 +55,6 @@
                                    const LocationContext *LCtx,
                                    bool loadedFrom) {
   Ex = Ex->IgnoreParenLValueCasts();
-  const MemRegion *sourceR = 0;
   switch (Ex->getStmtClass()) {
     default:
       break;
@@ -65,7 +64,6 @@
         os << " (" << (loadedFrom ? "loaded from" : "from")
            << " variable '" <<  VD->getName() << "')";
         Ranges.push_back(DR->getSourceRange());
-        sourceR = state->getLValue(VD, LCtx).getAsRegion();
       }
       break;
     }
@@ -78,7 +76,6 @@
       break;
     }
   }
-  return sourceR;
 }
 
 void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S,
@@ -101,8 +98,6 @@
   if (const Expr *expr = dyn_cast<Expr>(S))
     S = expr->IgnoreParenLValueCasts();
 
-  const MemRegion *sourceR = 0;
-
   if (IsBind) {
     if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(S)) {
       if (BO->isAssignmentOp())
@@ -120,8 +115,8 @@
     llvm::raw_svector_ostream os(buf);
     os << "Array access";
     const ArraySubscriptExpr *AE = cast<ArraySubscriptExpr>(S);
-    sourceR = AddDerefSource(os, Ranges, AE->getBase()->IgnoreParenCasts(),
-                             State.getPtr(), N->getLocationContext());
+    AddDerefSource(os, Ranges, AE->getBase()->IgnoreParenCasts(),
+                   State.getPtr(), N->getLocationContext());
     os << " results in a null pointer dereference";
     break;
   }
@@ -129,8 +124,8 @@
     llvm::raw_svector_ostream os(buf);
     os << "Dereference of null pointer";
     const UnaryOperator *U = cast<UnaryOperator>(S);
-    sourceR = AddDerefSource(os, Ranges, U->getSubExpr()->IgnoreParens(),
-                             State.getPtr(), N->getLocationContext(), true);
+    AddDerefSource(os, Ranges, U->getSubExpr()->IgnoreParens(),
+                   State.getPtr(), N->getLocationContext(), true);
     break;
   }
   case Stmt::MemberExprClass: {
@@ -139,8 +134,8 @@
       llvm::raw_svector_ostream os(buf);
       os << "Access to field '" << M->getMemberNameInfo()
          << "' results in a dereference of a null pointer";
-      sourceR = AddDerefSource(os, Ranges, M->getBase()->IgnoreParenCasts(),
-                               State.getPtr(), N->getLocationContext(), true);
+      AddDerefSource(os, Ranges, M->getBase()->IgnoreParenCasts(),
+                     State.getPtr(), N->getLocationContext(), true);
     }
     break;
   }
@@ -172,11 +167,6 @@
        I = Ranges.begin(), E = Ranges.end(); I!=E; ++I)
     report->addRange(*I);
 
-  if (sourceR) {
-    report->markInteresting(sourceR);
-    report->markInteresting(State->getRawSVal(loc::MemRegionVal(sourceR)));
-  }
-
   C.EmitReport(report);
 }
 





More information about the cfe-commits mailing list