diff options
Diffstat (limited to 'lib/Analysis/BugReporterVisitors.cpp')
-rw-r--r-- | lib/Analysis/BugReporterVisitors.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/lib/Analysis/BugReporterVisitors.cpp b/lib/Analysis/BugReporterVisitors.cpp index 8b3502805d..b76ffb18a6 100644 --- a/lib/Analysis/BugReporterVisitors.cpp +++ b/lib/Analysis/BugReporterVisitors.cpp @@ -28,7 +28,7 @@ const Stmt *clang::bugreporter::GetDerefExpr(const ExplodedNode *N) { // Pattern match for a few useful cases (do something smarter later): // a[0], p->f, *p const Stmt *S = N->getLocationAs<PostStmt>()->getStmt(); - + if (const UnaryOperator *U = dyn_cast<UnaryOperator>(S)) { if (U->getOpcode() == UnaryOperator::Deref) return U->getSubExpr()->IgnoreParenCasts(); @@ -41,8 +41,8 @@ const Stmt *clang::bugreporter::GetDerefExpr(const ExplodedNode *N) { // to reason about them. return AE->getBase(); } - - return NULL; + + return NULL; } const Stmt* @@ -91,19 +91,19 @@ class VISIBILITY_HIDDEN FindLastStoreBRVisitor : public BugReporterVisitor { public: FindLastStoreBRVisitor(SVal v, const MemRegion *r) : R(r), V(v), satisfied(false), StoreSite(0) {} - + PathDiagnosticPiece* VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext& BRC) { - + if (satisfied) return NULL; - - if (!StoreSite) { + + if (!StoreSite) { const ExplodedNode *Node = N, *Last = NULL; - + for ( ; Node ; Last = Node, Node = Node->getFirstPred()) { - + if (const VarRegion *VR = dyn_cast<VarRegion>(R)) { if (const PostStmt *P = Node->getLocationAs<PostStmt>()) if (const DeclStmt *DS = P->getStmtAs<DeclStmt>()) @@ -112,35 +112,35 @@ public: break; } } - + if (Node->getState()->getSVal(R) != V) break; } - + if (!Node || !Last) { satisfied = true; return NULL; } - + StoreSite = Last; } - + if (StoreSite != N) return NULL; - + satisfied = true; std::string sbuf; llvm::raw_string_ostream os(sbuf); - + if (const PostStmt *PS = N->getLocationAs<PostStmt>()) { if (const DeclStmt *DS = PS->getStmtAs<DeclStmt>()) { - + if (const VarRegion *VR = dyn_cast<VarRegion>(R)) { os << "Variable '" << VR->getDecl()->getNameAsString() << "' "; } else return NULL; - + if (isa<loc::ConcreteInt>(V)) { bool b = false; ASTContext &C = BRC.getASTContext(); @@ -152,7 +152,7 @@ public: } } } - + if (!b) os << "initialized to a null pointer value"; } @@ -165,13 +165,13 @@ public: if (VD->getInit()) os << "initialized to a garbage value"; else - os << "declared without an initial value"; - } + os << "declared without an initial value"; + } } } } - - if (os.str().empty()) { + + if (os.str().empty()) { if (isa<loc::ConcreteInt>(V)) { bool b = false; ASTContext &C = BRC.getASTContext(); @@ -183,7 +183,7 @@ public: } } } - + if (!b) os << "Null pointer value stored to "; } @@ -196,18 +196,18 @@ public: } else return NULL; - + if (const VarRegion *VR = dyn_cast<VarRegion>(R)) { os << '\'' << VR->getDecl()->getNameAsString() << '\''; } else return NULL; } - + // FIXME: Refactor this into BugReporterContext. - const Stmt *S = 0; + const Stmt *S = 0; ProgramPoint P = N->getLocation(); - + if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { CFGBlock *BSrc = BE->getSrc(); S = BSrc->getTerminatorCondition(); @@ -215,10 +215,10 @@ public: else if (PostStmt *PS = dyn_cast<PostStmt>(&P)) { S = PS->getStmt(); } - + if (!S) return NULL; - + // Construct a new PathDiagnosticPiece. PathDiagnosticLocation L(S, BRC.getSourceManager()); return new PathDiagnosticEventPiece(L, os.str()); @@ -238,42 +238,42 @@ class VISIBILITY_HIDDEN TrackConstraintBRVisitor : public BugReporterVisitor { public: TrackConstraintBRVisitor(SVal constraint, bool assumption) : Constraint(constraint), Assumption(assumption), isSatisfied(false) {} - + PathDiagnosticPiece* VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext& BRC) { if (isSatisfied) return NULL; - + // Check if in the previous state it was feasible for this constraint // to *not* be true. if (PrevN->getState()->assume(Constraint, !Assumption)) { - + isSatisfied = true; - + // As a sanity check, make sure that the negation of the constraint // was infeasible in the current state. If it is feasible, we somehow // missed the transition point. if (N->getState()->assume(Constraint, !Assumption)) return NULL; - + // We found the transition point for the constraint. We now need to - // pretty-print the constraint. (work-in-progress) + // pretty-print the constraint. (work-in-progress) std::string sbuf; llvm::raw_string_ostream os(sbuf); - + if (isa<Loc>(Constraint)) { os << "Assuming pointer value is "; os << (Assumption ? "non-null" : "null"); } - + if (os.str().empty()) return NULL; - + // FIXME: Refactor this into BugReporterContext. - const Stmt *S = 0; + const Stmt *S = 0; ProgramPoint P = N->getLocation(); - + if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { CFGBlock *BSrc = BE->getSrc(); S = BSrc->getTerminatorCondition(); @@ -281,65 +281,65 @@ public: else if (PostStmt *PS = dyn_cast<PostStmt>(&P)) { S = PS->getStmt(); } - + if (!S) return NULL; - + // Construct a new PathDiagnosticPiece. PathDiagnosticLocation L(S, BRC.getSourceManager()); return new PathDiagnosticEventPiece(L, os.str()); } - + return NULL; - } + } }; } // end anonymous namespace static void registerTrackConstraint(BugReporterContext& BRC, SVal Constraint, bool Assumption) { - BRC.addVisitor(new TrackConstraintBRVisitor(Constraint, Assumption)); + BRC.addVisitor(new TrackConstraintBRVisitor(Constraint, Assumption)); } void clang::bugreporter::registerTrackNullOrUndefValue(BugReporterContext& BRC, const void *data, const ExplodedNode* N) { - + const Stmt *S = static_cast<const Stmt*>(data); - + if (!S) return; - + GRStateManager &StateMgr = BRC.getStateManager(); - const GRState *state = N->getState(); - - if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S)) { - if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { + const GRState *state = N->getState(); + + if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S)) { + if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { const VarRegion *R = StateMgr.getRegionManager().getVarRegion(VD, N->getLocationContext()); - + // What did we load? SVal V = state->getSVal(S); - - if (isa<loc::ConcreteInt>(V) || isa<nonloc::ConcreteInt>(V) + + if (isa<loc::ConcreteInt>(V) || isa<nonloc::ConcreteInt>(V) || V.isUndef()) { registerFindLastStore(BRC, R, V); } } } - + SVal V = state->getSValAsScalarOrLoc(S); - + // Uncomment this to find cases where we aren't properly getting the // base value that was dereferenced. // assert(!V.isUnknownOrUndef()); - + // Is it a symbolic value? if (loc::MemRegionVal *L = dyn_cast<loc::MemRegionVal>(&V)) { const SubRegion *R = cast<SubRegion>(L->getRegion()); while (R && !isa<SymbolicRegion>(R)) { R = dyn_cast<SubRegion>(R->getSuperRegion()); } - + if (R) { assert(isa<SymbolicRegion>(R)); registerTrackConstraint(BRC, loc::MemRegionVal(R), false); |