2010-12-23 02:53:44 +08:00
|
|
|
//=-- ExprEngine.cpp - Path-Sensitive Expression-Level Dataflow ---*- C++ -*-=
|
2008-01-31 10:35:41 +08:00
|
|
|
//
|
2008-01-31 14:49:09 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2008-01-16 07:55:06 +08:00
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-02-15 06:13:12 +08:00
|
|
|
// This file defines a meta-engine for path-sensitive dataflow analysis that
|
|
|
|
// is built on GREngine, but provides the boilerplate to execute transfer
|
|
|
|
// functions and build the ExplodedGraph at the expression level.
|
2008-01-16 07:55:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-12-23 02:52:56 +08:00
|
|
|
|
2012-02-29 05:49:04 +08:00
|
|
|
#define DEBUG_TYPE "ExprEngine"
|
|
|
|
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2010-01-12 01:06:35 +08:00
|
|
|
#include "clang/AST/CharUnits.h"
|
2009-04-26 09:32:48 +08:00
|
|
|
#include "clang/AST/ParentMap.h"
|
2012-03-10 09:34:17 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/StmtObjC.h"
|
2009-06-14 09:54:56 +08:00
|
|
|
#include "clang/Basic/Builtins.h"
|
2009-03-11 10:41:36 +08:00
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
|
2009-08-23 20:08:50 +08:00
|
|
|
#include "llvm/ADT/ImmutableList.h"
|
2012-02-29 05:49:04 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-07-11 06:03:41 +08:00
|
|
|
|
2008-02-27 14:07:00 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include "llvm/Support/GraphWriter.h"
|
|
|
|
#endif
|
|
|
|
|
2008-02-15 06:16:04 +08:00
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2008-02-15 06:16:04 +08:00
|
|
|
using llvm::APSInt;
|
2008-01-24 03:59:44 +08:00
|
|
|
|
2012-02-29 05:49:04 +08:00
|
|
|
STATISTIC(NumRemoveDeadBindings,
|
|
|
|
"The # of times RemoveDeadBindings is called");
|
2012-03-23 05:06:03 +08:00
|
|
|
STATISTIC(NumMaxBlockCountReached,
|
|
|
|
"The # of aborted paths due to reaching the maximum block count in "
|
|
|
|
"a top level function");
|
|
|
|
STATISTIC(NumMaxBlockCountReachedInInlined,
|
|
|
|
"The # of aborted paths due to reaching the maximum block count in "
|
|
|
|
"an inlined function");
|
2012-03-28 04:02:53 +08:00
|
|
|
STATISTIC(NumTimesRetriedWithoutInlining,
|
|
|
|
"The # of times we re-evaluated a call without inlining");
|
|
|
|
|
2008-07-12 02:37:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Engine construction and deletion.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-03-10 05:14:01 +08:00
|
|
|
ExprEngine::ExprEngine(AnalysisManager &mgr, bool gcEnabled,
|
2012-08-31 07:42:02 +08:00
|
|
|
SetOfConstDecls *VisitedCalleesIn,
|
2012-12-08 05:51:47 +08:00
|
|
|
FunctionSummariesTy *FS,
|
|
|
|
InliningModes HowToInlineIn)
|
2009-08-15 11:17:38 +08:00
|
|
|
: AMgr(mgr),
|
2011-10-24 09:32:45 +08:00
|
|
|
AnalysisDeclContexts(mgr.getAnalysisDeclContextManager()),
|
2012-08-31 07:42:02 +08:00
|
|
|
Engine(*this, FS),
|
2010-12-23 02:53:44 +08:00
|
|
|
G(Engine.getGraph()),
|
2010-07-01 15:10:59 +08:00
|
|
|
StateMgr(getContext(), mgr.getStoreManagerCreator(),
|
2010-01-05 08:15:18 +08:00
|
|
|
mgr.getConstraintManagerCreator(), G.getAllocator(),
|
2012-10-02 00:53:40 +08:00
|
|
|
this),
|
2008-04-10 05:41:14 +08:00
|
|
|
SymMgr(StateMgr.getSymbolManager()),
|
2010-12-02 15:49:45 +08:00
|
|
|
svalBuilder(StateMgr.getSValBuilder()),
|
2012-12-07 02:58:26 +08:00
|
|
|
currStmtIdx(0), currBldrCtx(0),
|
2012-09-13 08:21:31 +08:00
|
|
|
ObjCNoRet(mgr.getASTContext()),
|
2012-08-31 07:42:02 +08:00
|
|
|
ObjCGCEnabled(gcEnabled), BR(mgr, *this),
|
2012-12-08 05:51:47 +08:00
|
|
|
VisitedCallees(VisitedCalleesIn),
|
|
|
|
HowToInline(HowToInlineIn)
|
2012-08-31 03:26:43 +08:00
|
|
|
{
|
2012-10-24 07:59:05 +08:00
|
|
|
unsigned TrimInterval = mgr.options.getGraphTrimInterval();
|
|
|
|
if (TrimInterval != 0) {
|
|
|
|
// Enable eager node reclaimation when constructing the ExplodedGraph.
|
|
|
|
G.enableNodeReclamation(TrimInterval);
|
|
|
|
}
|
2009-11-26 05:45:48 +08:00
|
|
|
}
|
2008-04-10 05:41:14 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
ExprEngine::~ExprEngine() {
|
2009-02-05 07:49:09 +08:00
|
|
|
BR.FlushReports();
|
2008-04-10 05:41:14 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) {
|
|
|
|
ProgramStateRef state = StateMgr.getInitialState(InitLoc);
|
2011-12-01 13:29:42 +08:00
|
|
|
const Decl *D = InitLoc->getDecl();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-10 04:36:12 +08:00
|
|
|
// Preconditions.
|
2009-04-10 08:59:50 +08:00
|
|
|
// FIXME: It would be nice if we had a more general mechanism to add
|
|
|
|
// such preconditions. Some day.
|
2009-12-18 03:17:27 +08:00
|
|
|
do {
|
2011-12-01 13:29:42 +08:00
|
|
|
|
2009-12-18 03:17:27 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
// Precondition: the first argument of 'main' is an integer guaranteed
|
|
|
|
// to be > 0.
|
|
|
|
const IdentifierInfo *II = FD->getIdentifier();
|
|
|
|
if (!II || !(II->getName() == "main" && FD->getNumParams() > 0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const ParmVarDecl *PD = FD->getParamDecl(0);
|
|
|
|
QualType T = PD->getType();
|
|
|
|
if (!T->isIntegerType())
|
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2009-12-18 03:17:27 +08:00
|
|
|
const MemRegion *R = state->getRegion(PD, InitLoc);
|
|
|
|
if (!R)
|
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2010-02-09 00:18:51 +08:00
|
|
|
SVal V = state->getSVal(loc::MemRegionVal(R));
|
2010-12-02 05:57:22 +08:00
|
|
|
SVal Constraint_untested = evalBinOp(state, BO_GT, V,
|
2010-12-02 15:49:45 +08:00
|
|
|
svalBuilder.makeZeroVal(T),
|
2009-12-18 03:17:27 +08:00
|
|
|
getContext().IntTy);
|
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<DefinedOrUnknownSVal> Constraint =
|
|
|
|
Constraint_untested.getAs<DefinedOrUnknownSVal>();
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2009-12-18 03:17:27 +08:00
|
|
|
if (!Constraint)
|
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef newState = state->assume(*Constraint, true))
|
2009-12-18 03:17:27 +08:00
|
|
|
state = newState;
|
2009-04-10 08:59:50 +08:00
|
|
|
}
|
2011-12-01 13:29:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
|
|
|
|
// Precondition: 'self' is always non-null upon entry to an Objective-C
|
|
|
|
// method.
|
|
|
|
const ImplicitParamDecl *SelfD = MD->getSelfDecl();
|
|
|
|
const MemRegion *R = state->getRegion(SelfD, InitLoc);
|
|
|
|
SVal V = state->getSVal(loc::MemRegionVal(R));
|
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<Loc> LV = V.getAs<Loc>()) {
|
2011-12-01 13:29:42 +08:00
|
|
|
// Assume that the pointer value in 'self' is non-null.
|
|
|
|
state = state->assume(*LV, true);
|
|
|
|
assert(state && "'self' cannot be null");
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 03:17:27 +08:00
|
|
|
|
2011-12-01 13:29:42 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
if (!MD->isStatic()) {
|
|
|
|
// Precondition: 'this' is always non-null upon entry to the
|
|
|
|
// top-level function. This is our starting assumption for
|
|
|
|
// analyzing an "open" program.
|
|
|
|
const StackFrameContext *SFC = InitLoc->getCurrentStackFrame();
|
|
|
|
if (SFC->getParent() == 0) {
|
2012-06-23 07:55:50 +08:00
|
|
|
loc::MemRegionVal L = svalBuilder.getCXXThis(MD, SFC);
|
2011-12-01 13:29:42 +08:00
|
|
|
SVal V = state->getSVal(L);
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<Loc> LV = V.getAs<Loc>()) {
|
2011-12-01 13:29:42 +08:00
|
|
|
state = state->assume(*LV, true);
|
|
|
|
assert(state && "'this' cannot be null");
|
|
|
|
}
|
2009-12-18 03:17:27 +08:00
|
|
|
}
|
2009-09-10 04:36:12 +08:00
|
|
|
}
|
2011-12-01 13:29:42 +08:00
|
|
|
}
|
|
|
|
|
2009-04-10 08:59:50 +08:00
|
|
|
return state;
|
2008-02-05 05:59:01 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 09:51:15 +08:00
|
|
|
ProgramStateRef
|
|
|
|
ExprEngine::createTemporaryRegionIfNeeded(ProgramStateRef State,
|
|
|
|
const LocationContext *LC,
|
|
|
|
const Expr *Ex,
|
|
|
|
const Expr *Result) {
|
2013-02-22 09:08:00 +08:00
|
|
|
SVal V = State->getSVal(Ex, LC);
|
2013-02-22 09:51:15 +08:00
|
|
|
if (!Result && !V.getAs<NonLoc>())
|
|
|
|
return State;
|
|
|
|
|
|
|
|
ProgramStateManager &StateMgr = State->getStateManager();
|
|
|
|
MemRegionManager &MRMgr = StateMgr.getRegionManager();
|
|
|
|
StoreManager &StoreMgr = StateMgr.getStoreManager();
|
|
|
|
|
|
|
|
// We need to be careful about treating a derived type's value as
|
|
|
|
// bindings for a base type. Start by stripping and recording base casts.
|
|
|
|
SmallVector<const CastExpr *, 4> Casts;
|
|
|
|
const Expr *Inner = Ex->IgnoreParens();
|
|
|
|
while (const CastExpr *CE = dyn_cast<CastExpr>(Inner)) {
|
|
|
|
if (CE->getCastKind() == CK_DerivedToBase ||
|
|
|
|
CE->getCastKind() == CK_UncheckedDerivedToBase)
|
|
|
|
Casts.push_back(CE);
|
|
|
|
else if (CE->getCastKind() != CK_NoOp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Inner = CE->getSubExpr()->IgnoreParens();
|
|
|
|
}
|
2012-10-18 03:35:37 +08:00
|
|
|
|
2013-02-22 09:51:15 +08:00
|
|
|
// Create a temporary object region for the inner expression (which may have
|
|
|
|
// a more derived type) and bind the NonLoc value into it.
|
|
|
|
SVal Reg = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(Inner, LC));
|
|
|
|
State = State->bindLoc(Reg, V);
|
2013-02-22 07:57:17 +08:00
|
|
|
|
2013-02-22 09:51:15 +08:00
|
|
|
// Re-apply the casts (from innermost to outermost) for type sanity.
|
|
|
|
for (SmallVectorImpl<const CastExpr *>::reverse_iterator I = Casts.rbegin(),
|
|
|
|
E = Casts.rend();
|
|
|
|
I != E; ++I) {
|
|
|
|
Reg = StoreMgr.evalDerivedToBase(Reg, *I);
|
2012-10-18 03:35:37 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 09:51:15 +08:00
|
|
|
State = State->BindExpr(Result ? Result : Ex, LC, Reg);
|
2012-10-18 03:35:37 +08:00
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-level transfer function logic (Dispatcher).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-12-02 05:57:22 +08:00
|
|
|
/// evalAssume - Called by ConstraintManager. Used to call checker-specific
|
2010-01-05 08:15:18 +08:00
|
|
|
/// logic for handling assumptions on symbolic values.
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef ExprEngine::processAssume(ProgramStateRef state,
|
2011-08-28 13:54:23 +08:00
|
|
|
SVal cond, bool assumption) {
|
|
|
|
return getCheckerManager().runCheckersForEvalAssume(state, cond, assumption);
|
2010-01-05 08:15:18 +08:00
|
|
|
}
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
bool ExprEngine::wantsRegionChangeUpdate(ProgramStateRef state) {
|
2011-02-24 09:05:30 +08:00
|
|
|
return getCheckerManager().wantsRegionChangeUpdate(state);
|
2010-08-15 04:44:32 +08:00
|
|
|
}
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef
|
|
|
|
ExprEngine::processRegionChanges(ProgramStateRef state,
|
2012-12-20 08:38:25 +08:00
|
|
|
const InvalidatedSymbols *invalidated,
|
2011-08-28 06:51:26 +08:00
|
|
|
ArrayRef<const MemRegion *> Explicits,
|
2012-02-15 05:55:24 +08:00
|
|
|
ArrayRef<const MemRegion *> Regions,
|
2012-07-03 03:27:35 +08:00
|
|
|
const CallEvent *Call) {
|
2011-05-03 03:42:42 +08:00
|
|
|
return getCheckerManager().runCheckersForRegionChanges(state, invalidated,
|
2012-02-15 05:55:24 +08:00
|
|
|
Explicits, Regions, Call);
|
2010-08-15 04:44:32 +08:00
|
|
|
}
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
void ExprEngine::printState(raw_ostream &Out, ProgramStateRef State,
|
2011-08-29 03:11:56 +08:00
|
|
|
const char *NL, const char *Sep) {
|
|
|
|
getCheckerManager().runCheckersForPrintState(Out, State, NL, Sep);
|
|
|
|
}
|
|
|
|
|
2011-01-11 10:34:45 +08:00
|
|
|
void ExprEngine::processEndWorklist(bool hasWorkRemaining) {
|
2011-02-23 15:19:23 +08:00
|
|
|
getCheckerManager().runCheckersForEndAnalysis(G, BR, *this);
|
2010-06-24 06:08:00 +08:00
|
|
|
}
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
void ExprEngine::processCFGElement(const CFGElement E, ExplodedNode *Pred,
|
|
|
|
unsigned StmtIdx, NodeBuilderContext *Ctx) {
|
2012-08-22 14:26:15 +08:00
|
|
|
currStmtIdx = StmtIdx;
|
|
|
|
currBldrCtx = Ctx;
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2010-11-15 16:48:43 +08:00
|
|
|
switch (E.getKind()) {
|
2011-03-01 11:15:10 +08:00
|
|
|
case CFGElement::Statement:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessStmt(const_cast<Stmt*>(E.castAs<CFGStmt>().getStmt()), Pred);
|
2011-03-01 11:15:10 +08:00
|
|
|
return;
|
|
|
|
case CFGElement::Initializer:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessInitializer(E.castAs<CFGInitializer>().getInitializer(), Pred);
|
2011-03-01 11:15:10 +08:00
|
|
|
return;
|
|
|
|
case CFGElement::AutomaticObjectDtor:
|
|
|
|
case CFGElement::BaseDtor:
|
|
|
|
case CFGElement::MemberDtor:
|
|
|
|
case CFGElement::TemporaryDtor:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessImplicitDtor(E.castAs<CFGImplicitDtor>(), Pred);
|
2011-03-01 11:15:10 +08:00
|
|
|
return;
|
2010-11-15 16:48:43 +08:00
|
|
|
}
|
2012-08-22 14:26:15 +08:00
|
|
|
currBldrCtx = 0;
|
2010-11-15 16:48:43 +08:00
|
|
|
}
|
|
|
|
|
2011-11-11 07:26:10 +08:00
|
|
|
static bool shouldRemoveDeadBindings(AnalysisManager &AMgr,
|
|
|
|
const CFGStmt S,
|
|
|
|
const ExplodedNode *Pred,
|
|
|
|
const LocationContext *LC) {
|
|
|
|
|
|
|
|
// Are we never purging state values?
|
2012-08-31 03:26:43 +08:00
|
|
|
if (AMgr.options.AnalysisPurgeOpt == PurgeNone)
|
2011-11-11 07:26:10 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Is this the beginning of a basic block?
|
2013-02-22 06:23:56 +08:00
|
|
|
if (Pred->getLocation().getAs<BlockEntrance>())
|
2011-11-11 07:26:10 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Is this on a non-expression?
|
|
|
|
if (!isa<Expr>(S.getStmt()))
|
|
|
|
return true;
|
2012-02-25 00:49:46 +08:00
|
|
|
|
|
|
|
// Run before processing a call.
|
2012-08-28 08:50:38 +08:00
|
|
|
if (CallEvent::isCallStmt(S.getStmt()))
|
2012-02-25 00:49:46 +08:00
|
|
|
return true;
|
|
|
|
|
2011-11-11 07:26:10 +08:00
|
|
|
// Is this an expression that is consumed by another expression? If so,
|
|
|
|
// postpone cleaning out the state.
|
|
|
|
ParentMap &PM = LC->getAnalysisDeclContext()->getParentMap();
|
|
|
|
return !PM.isConsumedExpr(cast<Expr>(S.getStmt()));
|
|
|
|
}
|
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
void ExprEngine::removeDead(ExplodedNode *Pred, ExplodedNodeSet &Out,
|
|
|
|
const Stmt *ReferenceStmt,
|
2012-11-16 03:11:27 +08:00
|
|
|
const LocationContext *LC,
|
2012-04-21 05:59:08 +08:00
|
|
|
const Stmt *DiagnosticStmt,
|
|
|
|
ProgramPoint::Kind K) {
|
|
|
|
assert((K == ProgramPoint::PreStmtPurgeDeadSymbolsKind ||
|
2012-11-16 03:11:27 +08:00
|
|
|
ReferenceStmt == 0 || isa<ReturnStmt>(ReferenceStmt))
|
2012-11-03 10:54:20 +08:00
|
|
|
&& "PostStmt is not generally supported by the SymbolReaper yet");
|
2012-11-16 03:11:27 +08:00
|
|
|
assert(LC && "Must pass the current (or expiring) LocationContext");
|
|
|
|
|
|
|
|
if (!DiagnosticStmt) {
|
|
|
|
DiagnosticStmt = ReferenceStmt;
|
|
|
|
assert(DiagnosticStmt && "Required for clearing a LocationContext");
|
|
|
|
}
|
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
NumRemoveDeadBindings++;
|
2012-12-07 02:58:26 +08:00
|
|
|
ProgramStateRef CleanedState = Pred->getState();
|
2012-11-16 03:11:27 +08:00
|
|
|
|
|
|
|
// LC is the location context being destroyed, but SymbolReaper wants a
|
|
|
|
// location context that is still live. (If this is the top-level stack
|
|
|
|
// frame, this will be null.)
|
|
|
|
if (!ReferenceStmt) {
|
|
|
|
assert(K == ProgramPoint::PostStmtPurgeDeadSymbolsKind &&
|
|
|
|
"Use PostStmtPurgeDeadSymbolsKind for clearing a LocationContext");
|
|
|
|
LC = LC->getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
const StackFrameContext *SFC = LC ? LC->getCurrentStackFrame() : 0;
|
|
|
|
SymbolReaper SymReaper(SFC, ReferenceStmt, SymMgr, getStoreManager());
|
2012-04-21 05:59:08 +08:00
|
|
|
|
|
|
|
getCheckerManager().runCheckersForLiveSymbols(CleanedState, SymReaper);
|
|
|
|
|
|
|
|
// Create a state in which dead bindings are removed from the environment
|
|
|
|
// and the store. TODO: The function should just return new env and store,
|
|
|
|
// not a new state.
|
|
|
|
CleanedState = StateMgr.removeDeadBindings(CleanedState, SFC, SymReaper);
|
2009-01-22 06:26:05 +08:00
|
|
|
|
2008-04-25 02:31:42 +08:00
|
|
|
// Process any special transfer function for dead symbols.
|
2011-10-25 05:19:43 +08:00
|
|
|
// A tag to track convenience transitions, which can be removed at cleanup.
|
|
|
|
static SimpleProgramPointTag cleanupTag("ExprEngine : Clean Node");
|
2011-08-11 07:14:54 +08:00
|
|
|
if (!SymReaper.hasDeadSymbols()) {
|
|
|
|
// Generate a CleanedNode that has the environment and store cleaned
|
|
|
|
// up. Since no symbols are dead, we can optimize and not clean out
|
|
|
|
// the constraint manager.
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Out, *currBldrCtx);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(DiagnosticStmt, Pred, CleanedState, &cleanupTag, K);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-11 07:14:54 +08:00
|
|
|
} else {
|
|
|
|
// Call checkers with the non-cleaned state so that they could query the
|
|
|
|
// values of the soon to be dead symbols.
|
2011-08-28 13:54:23 +08:00
|
|
|
ExplodedNodeSet CheckedSet;
|
2012-04-21 05:59:08 +08:00
|
|
|
getCheckerManager().runCheckersForDeadSymbols(CheckedSet, Pred, SymReaper,
|
|
|
|
DiagnosticStmt, *this, K);
|
2011-02-24 09:05:30 +08:00
|
|
|
|
2011-08-28 13:54:23 +08:00
|
|
|
// For each node in CheckedSet, generate CleanedNodes that have the
|
|
|
|
// environment, the store, and the constraints cleaned up but have the
|
|
|
|
// user-supplied states as the predecessors.
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(CheckedSet, Out, *currBldrCtx);
|
2011-08-28 13:54:23 +08:00
|
|
|
for (ExplodedNodeSet::const_iterator
|
|
|
|
I = CheckedSet.begin(), E = CheckedSet.end(); I != E; ++I) {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef CheckerState = (*I)->getState();
|
2011-08-11 07:14:54 +08:00
|
|
|
|
|
|
|
// The constraint manager has not been cleaned up yet, so clean up now.
|
|
|
|
CheckerState = getConstraintManager().removeDeadBindings(CheckerState,
|
|
|
|
SymReaper);
|
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
assert(StateMgr.haveEqualEnvironments(CheckerState, Pred->getState()) &&
|
2011-08-11 07:14:54 +08:00
|
|
|
"Checkers are not allowed to modify the Environment as a part of "
|
|
|
|
"checkDeadSymbols processing.");
|
2012-04-21 05:59:08 +08:00
|
|
|
assert(StateMgr.haveEqualStores(CheckerState, Pred->getState()) &&
|
2011-08-11 07:14:54 +08:00
|
|
|
"Checkers are not allowed to modify the Store as a part of "
|
|
|
|
"checkDeadSymbols processing.");
|
|
|
|
|
|
|
|
// Create a state based on CleanedState with CheckerState GDM and
|
|
|
|
// generate a transition to that state.
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef CleanedCheckerSt =
|
2011-08-11 07:14:54 +08:00
|
|
|
StateMgr.getPersistentStateWithGDM(CleanedState, CheckerState);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(DiagnosticStmt, *I, CleanedCheckerSt, &cleanupTag, K);
|
2011-08-11 07:14:54 +08:00
|
|
|
}
|
2008-04-25 02:31:42 +08:00
|
|
|
}
|
2012-04-21 05:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExprEngine::ProcessStmt(const CFGStmt S,
|
|
|
|
ExplodedNode *Pred) {
|
|
|
|
// Reclaim any unnecessary nodes in the ExplodedGraph.
|
|
|
|
G.reclaimRecentlyAllocatedNodes();
|
|
|
|
|
2012-12-07 02:58:26 +08:00
|
|
|
const Stmt *currStmt = S.getStmt();
|
2012-04-21 05:59:08 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
2012-08-22 14:26:15 +08:00
|
|
|
currStmt->getLocStart(),
|
2012-04-21 05:59:08 +08:00
|
|
|
"Error evaluating statement");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
// Remove dead bindings and symbols.
|
|
|
|
ExplodedNodeSet CleanedStates;
|
2012-12-07 02:58:26 +08:00
|
|
|
if (shouldRemoveDeadBindings(AMgr, S, Pred, Pred->getLocationContext())){
|
|
|
|
removeDead(Pred, CleanedStates, currStmt, Pred->getLocationContext());
|
2012-04-21 05:59:08 +08:00
|
|
|
} else
|
2012-12-07 02:58:26 +08:00
|
|
|
CleanedStates.Add(Pred);
|
2012-04-21 05:59:08 +08:00
|
|
|
|
|
|
|
// Visit the statement.
|
2011-10-27 08:59:23 +08:00
|
|
|
ExplodedNodeSet Dst;
|
2012-04-21 05:59:08 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = CleanedStates.begin(),
|
|
|
|
E = CleanedStates.end(); I != E; ++I) {
|
2011-10-27 08:59:23 +08:00
|
|
|
ExplodedNodeSet DstI;
|
2009-09-09 23:08:12 +08:00
|
|
|
// Visit the statement.
|
2012-08-22 14:26:15 +08:00
|
|
|
Visit(currStmt, *I, DstI);
|
2011-10-27 08:59:23 +08:00
|
|
|
Dst.insert(DstI);
|
2011-10-25 02:26:19 +08:00
|
|
|
}
|
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
// Enqueue the new nodes onto the work list.
|
2012-08-22 14:26:15 +08:00
|
|
|
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
|
2008-04-16 07:06:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessInitializer(const CFGInitializer Init,
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNode *Pred) {
|
2011-01-09 04:30:50 +08:00
|
|
|
const CXXCtorInitializer *BMI = Init.getInitializer();
|
2012-08-04 07:31:15 +08:00
|
|
|
|
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
|
|
|
BMI->getSourceLocation(),
|
|
|
|
"Error evaluating initializer");
|
|
|
|
|
2012-12-07 02:58:26 +08:00
|
|
|
// We don't clean up dead bindings here.
|
2011-10-25 05:19:48 +08:00
|
|
|
const StackFrameContext *stackFrame =
|
|
|
|
cast<StackFrameContext>(Pred->getLocationContext());
|
|
|
|
const CXXConstructorDecl *decl =
|
|
|
|
cast<CXXConstructorDecl>(stackFrame->getDecl());
|
2012-08-25 09:06:23 +08:00
|
|
|
|
|
|
|
ProgramStateRef State = Pred->getState();
|
2012-07-27 04:04:21 +08:00
|
|
|
SVal thisVal = State->getSVal(svalBuilder.getCXXThis(decl, stackFrame));
|
2010-11-16 15:52:17 +08:00
|
|
|
|
2012-08-25 09:06:23 +08:00
|
|
|
PostInitializer PP(BMI, stackFrame);
|
|
|
|
ExplodedNodeSet Tmp(Pred);
|
|
|
|
|
2012-07-27 04:04:21 +08:00
|
|
|
// Evaluate the initializer, if necessary
|
2010-12-04 17:14:42 +08:00
|
|
|
if (BMI->isAnyMemberInitializer()) {
|
2012-07-27 04:04:21 +08:00
|
|
|
// Constructors build the object directly in the field,
|
|
|
|
// but non-objects must be copied in from the initializer.
|
2013-01-26 11:16:31 +08:00
|
|
|
const Expr *Init = BMI->getInit()->IgnoreImplicit();
|
2012-08-25 09:06:23 +08:00
|
|
|
if (!isa<CXXConstructExpr>(Init)) {
|
2012-07-27 04:04:21 +08:00
|
|
|
SVal FieldLoc;
|
|
|
|
if (BMI->isIndirectMemberInitializer())
|
|
|
|
FieldLoc = State->getLValue(BMI->getIndirectMember(), thisVal);
|
|
|
|
else
|
|
|
|
FieldLoc = State->getLValue(BMI->getMember(), thisVal);
|
|
|
|
|
|
|
|
SVal InitVal = State->getSVal(BMI->getInit(), stackFrame);
|
2012-08-25 09:06:23 +08:00
|
|
|
|
|
|
|
Tmp.clear();
|
|
|
|
evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP);
|
2012-07-27 04:04:21 +08:00
|
|
|
}
|
2011-10-25 05:19:48 +08:00
|
|
|
} else {
|
2012-08-04 07:31:15 +08:00
|
|
|
assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer());
|
2012-07-27 04:04:13 +08:00
|
|
|
// We already did all the work when visiting the CXXConstructExpr.
|
2011-10-25 05:19:48 +08:00
|
|
|
}
|
2011-10-27 08:59:23 +08:00
|
|
|
|
2012-08-25 09:06:23 +08:00
|
|
|
// Construct PostInitializer nodes whether the state changed or not,
|
2012-07-27 04:04:21 +08:00
|
|
|
// so that the diagnostics don't get confused.
|
2012-08-25 09:06:23 +08:00
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
NodeBuilder Bldr(Tmp, Dst, *currBldrCtx);
|
|
|
|
for (ExplodedNodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E; ++I) {
|
|
|
|
ExplodedNode *N = *I;
|
|
|
|
Bldr.generateNode(PP, N->getState(), N);
|
|
|
|
}
|
2012-07-27 04:04:21 +08:00
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
// Enqueue the new nodes onto the work list.
|
2012-08-22 14:26:15 +08:00
|
|
|
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
|
2010-11-15 16:48:43 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessImplicitDtor(const CFGImplicitDtor D,
|
2011-10-25 02:26:19 +08:00
|
|
|
ExplodedNode *Pred) {
|
|
|
|
ExplodedNodeSet Dst;
|
2011-03-01 11:15:10 +08:00
|
|
|
switch (D.getKind()) {
|
2010-11-17 17:16:19 +08:00
|
|
|
case CFGElement::AutomaticObjectDtor:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessAutomaticObjDtor(D.castAs<CFGAutomaticObjDtor>(), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::BaseDtor:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessBaseDtor(D.castAs<CFGBaseDtor>(), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::MemberDtor:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessMemberDtor(D.castAs<CFGMemberDtor>(), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::TemporaryDtor:
|
2013-02-22 04:58:29 +08:00
|
|
|
ProcessTemporaryDtor(D.castAs<CFGTemporaryDtor>(), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected dtor kind.");
|
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
// Enqueue the new nodes onto the work list.
|
2012-08-22 14:26:15 +08:00
|
|
|
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
|
2010-11-17 17:16:19 +08:00
|
|
|
}
|
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-10-25 05:19:48 +08:00
|
|
|
const VarDecl *varDecl = Dtor.getVarDecl();
|
2010-11-25 14:35:14 +08:00
|
|
|
|
|
|
|
QualType varType = varDecl->getType();
|
|
|
|
|
|
|
|
if (const ReferenceType *refType = varType->getAs<ReferenceType>())
|
|
|
|
varType = refType->getPointeeType();
|
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
Loc dest = state->getLValue(varDecl, Pred->getLocationContext());
|
2010-11-20 14:53:12 +08:00
|
|
|
|
2013-02-20 13:52:05 +08:00
|
|
|
VisitCXXDestructor(varType, dest.castAs<loc::MemRegionVal>().getRegion(),
|
|
|
|
Dtor.getTriggerStmt(), /*IsBase=*/ false, Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessBaseDtor(const CFGBaseDtor D,
|
2012-07-27 04:04:13 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
|
|
|
|
const CXXDestructorDecl *CurDtor = cast<CXXDestructorDecl>(LCtx->getDecl());
|
|
|
|
Loc ThisPtr = getSValBuilder().getCXXThis(CurDtor,
|
|
|
|
LCtx->getCurrentStackFrame());
|
|
|
|
SVal ThisVal = Pred->getState()->getSVal(ThisPtr);
|
|
|
|
|
|
|
|
// Create the base object region.
|
2013-02-21 11:12:32 +08:00
|
|
|
const CXXBaseSpecifier *Base = D.getBaseSpecifier();
|
|
|
|
QualType BaseTy = Base->getType();
|
|
|
|
SVal BaseVal = getStoreManager().evalDerivedToBase(ThisVal, BaseTy,
|
|
|
|
Base->isVirtual());
|
2012-07-27 04:04:13 +08:00
|
|
|
|
2013-02-20 13:52:05 +08:00
|
|
|
VisitCXXDestructor(BaseTy, BaseVal.castAs<loc::MemRegionVal>().getRegion(),
|
|
|
|
CurDtor->getBody(), /*IsBase=*/ true, Pred, Dst);
|
2012-07-27 04:04:13 +08:00
|
|
|
}
|
2010-11-17 17:16:19 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessMemberDtor(const CFGMemberDtor D,
|
2012-07-27 04:04:21 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
|
|
|
|
const FieldDecl *Member = D.getFieldDecl();
|
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
|
|
|
|
const CXXDestructorDecl *CurDtor = cast<CXXDestructorDecl>(LCtx->getDecl());
|
|
|
|
Loc ThisVal = getSValBuilder().getCXXThis(CurDtor,
|
|
|
|
LCtx->getCurrentStackFrame());
|
2013-02-20 13:52:05 +08:00
|
|
|
SVal FieldVal =
|
|
|
|
State->getLValue(Member, State->getSVal(ThisVal).castAs<Loc>());
|
2012-07-27 04:04:21 +08:00
|
|
|
|
|
|
|
VisitCXXDestructor(Member->getType(),
|
2013-02-20 13:52:05 +08:00
|
|
|
FieldVal.castAs<loc::MemRegionVal>().getRegion(),
|
2012-09-07 04:37:08 +08:00
|
|
|
CurDtor->getBody(), /*IsBase=*/false, Pred, Dst);
|
2012-07-27 04:04:21 +08:00
|
|
|
}
|
2010-11-17 17:16:19 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessTemporaryDtor(const CFGTemporaryDtor D,
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {}
|
2010-11-15 16:48:43 +08:00
|
|
|
|
2012-07-11 06:08:01 +08:00
|
|
|
void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
|
2011-11-02 06:41:09 +08:00
|
|
|
ExplodedNodeSet &DstTop) {
|
2009-03-11 10:41:36 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
|
|
|
S->getLocStart(),
|
|
|
|
"Error evaluating statement");
|
2011-11-02 06:41:09 +08:00
|
|
|
ExplodedNodeSet Dst;
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, DstTop, *currBldrCtx);
|
2009-03-11 10:41:36 +08:00
|
|
|
|
2012-12-07 02:58:22 +08:00
|
|
|
assert(!isa<Expr>(S) || S == cast<Expr>(S)->IgnoreParens());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
switch (S->getStmtClass()) {
|
2011-06-16 07:02:42 +08:00
|
|
|
// C++ and ARC stuff we don't support yet.
|
|
|
|
case Expr::ObjCIndirectCopyRestoreExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::CXXDependentScopeMemberExprClass:
|
|
|
|
case Stmt::CXXPseudoDestructorExprClass:
|
|
|
|
case Stmt::CXXTryStmtClass:
|
|
|
|
case Stmt::CXXTypeidExprClass:
|
2010-09-09 07:47:05 +08:00
|
|
|
case Stmt::CXXUuidofExprClass:
|
2009-12-15 09:38:04 +08:00
|
|
|
case Stmt::CXXUnresolvedConstructExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::DependentScopeDeclRefExprClass:
|
|
|
|
case Stmt::UnaryTypeTraitExprClass:
|
2010-12-07 08:08:36 +08:00
|
|
|
case Stmt::BinaryTypeTraitExprClass:
|
2012-02-24 15:38:34 +08:00
|
|
|
case Stmt::TypeTraitExprClass:
|
2011-04-28 08:16:57 +08:00
|
|
|
case Stmt::ArrayTypeTraitExprClass:
|
2011-04-25 14:54:41 +08:00
|
|
|
case Stmt::ExpressionTraitExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::UnresolvedLookupExprClass:
|
2009-12-15 09:38:04 +08:00
|
|
|
case Stmt::UnresolvedMemberExprClass:
|
2010-09-11 04:55:54 +08:00
|
|
|
case Stmt::CXXNoexceptExprClass:
|
2011-01-04 01:17:50 +08:00
|
|
|
case Stmt::PackExpansionExprClass:
|
2011-01-15 09:15:58 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmPackExprClass:
|
2012-09-12 08:56:43 +08:00
|
|
|
case Stmt::FunctionParmPackExprClass:
|
2011-04-28 09:08:34 +08:00
|
|
|
case Stmt::SEHTryStmtClass:
|
|
|
|
case Stmt::SEHExceptStmtClass:
|
2012-02-07 18:09:13 +08:00
|
|
|
case Stmt::LambdaExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
case Stmt::SEHFinallyStmtClass: {
|
2012-08-21 02:43:42 +08:00
|
|
|
const ExplodedNode *node = Bldr.generateSink(S, Pred, Pred->getState());
|
2012-08-22 14:26:15 +08:00
|
|
|
Engine.addAbortedBlock(node, currBldrCtx->getBlock());
|
2009-12-15 09:38:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-09 06:42:35 +08:00
|
|
|
|
2010-12-04 11:47:34 +08:00
|
|
|
case Stmt::ParenExprClass:
|
|
|
|
llvm_unreachable("ParenExprs already handled.");
|
2011-04-15 08:35:48 +08:00
|
|
|
case Stmt::GenericSelectionExprClass:
|
|
|
|
llvm_unreachable("GenericSelectionExprs already handled.");
|
2010-04-16 01:33:31 +08:00
|
|
|
// Cases that should never be evaluated simply because they shouldn't
|
|
|
|
// appear in the CFG.
|
|
|
|
case Stmt::BreakStmtClass:
|
|
|
|
case Stmt::CaseStmtClass:
|
|
|
|
case Stmt::CompoundStmtClass:
|
|
|
|
case Stmt::ContinueStmtClass:
|
2011-10-11 06:36:31 +08:00
|
|
|
case Stmt::CXXForRangeStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::DefaultStmtClass:
|
|
|
|
case Stmt::DoStmtClass:
|
2011-04-05 07:29:12 +08:00
|
|
|
case Stmt::ForStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::GotoStmtClass:
|
2011-04-05 07:29:12 +08:00
|
|
|
case Stmt::IfStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::IndirectGotoStmtClass:
|
|
|
|
case Stmt::LabelStmtClass:
|
2012-04-14 08:33:13 +08:00
|
|
|
case Stmt::AttributedStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::NoStmtClass:
|
|
|
|
case Stmt::NullStmtClass:
|
2011-04-05 07:29:12 +08:00
|
|
|
case Stmt::SwitchStmtClass:
|
|
|
|
case Stmt::WhileStmtClass:
|
2011-10-25 09:33:02 +08:00
|
|
|
case Expr::MSDependentExistsStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
llvm_unreachable("Stmt should not be in analyzer evaluation loop");
|
|
|
|
|
2012-07-19 05:59:37 +08:00
|
|
|
case Stmt::ObjCSubscriptRefExprClass:
|
|
|
|
case Stmt::ObjCPropertyRefExprClass:
|
|
|
|
llvm_unreachable("These are handled by PseudoObjectExpr");
|
|
|
|
|
2010-06-23 03:05:10 +08:00
|
|
|
case Stmt::GNUNullExprClass: {
|
2011-07-16 04:29:02 +08:00
|
|
|
// GNU __null is a pointer-width integer, not an actual pointer.
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
state = state->BindExpr(S, Pred->getLocationContext(),
|
|
|
|
svalBuilder.makeIntValWithPtrWidth(0, false));
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(S, Pred, state);
|
2010-06-23 03:05:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-10 11:05:33 +08:00
|
|
|
case Stmt::ObjCAtSynchronizedStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-09-10 11:05:33 +08:00
|
|
|
VisitObjCAtSynchronizedStmt(cast<ObjCAtSynchronizedStmt>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2010-09-10 11:05:33 +08:00
|
|
|
break;
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
case Stmt::ExprWithCleanupsClass:
|
2012-03-15 02:01:43 +08:00
|
|
|
// Handled due to fully linearised CFG.
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
|
|
|
|
2010-04-16 01:33:31 +08:00
|
|
|
// Cases not handled yet; but will handle some day.
|
|
|
|
case Stmt::DesignatedInitExprClass:
|
|
|
|
case Stmt::ExtVectorElementExprClass:
|
|
|
|
case Stmt::ImaginaryLiteralClass:
|
|
|
|
case Stmt::ObjCAtCatchStmtClass:
|
|
|
|
case Stmt::ObjCAtFinallyStmtClass:
|
|
|
|
case Stmt::ObjCAtTryStmtClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Stmt::ObjCAutoreleasePoolStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::ObjCEncodeExprClass:
|
|
|
|
case Stmt::ObjCIsaExprClass:
|
|
|
|
case Stmt::ObjCProtocolExprClass:
|
|
|
|
case Stmt::ObjCSelectorExprClass:
|
|
|
|
case Stmt::ParenListExprClass:
|
|
|
|
case Stmt::PredefinedExprClass:
|
|
|
|
case Stmt::ShuffleVectorExprClass:
|
|
|
|
case Stmt::VAArgExprClass:
|
2011-02-10 05:07:24 +08:00
|
|
|
case Stmt::CUDAKernelCallExprClass:
|
2011-02-17 18:25:35 +08:00
|
|
|
case Stmt::OpaqueValueExprClass:
|
2011-06-04 08:47:47 +08:00
|
|
|
case Stmt::AsTypeExprClass:
|
2011-10-11 10:20:01 +08:00
|
|
|
case Stmt::AtomicExprClass:
|
2012-03-10 09:34:17 +08:00
|
|
|
// Fall through.
|
2010-04-16 01:33:31 +08:00
|
|
|
|
|
|
|
// Cases we intentionally don't evaluate, since they don't need
|
|
|
|
// to be explicitly evaluated.
|
2010-04-13 21:15:19 +08:00
|
|
|
case Stmt::AddrLabelExprClass:
|
|
|
|
case Stmt::IntegerLiteralClass:
|
|
|
|
case Stmt::CharacterLiteralClass:
|
2012-05-08 13:13:40 +08:00
|
|
|
case Stmt::ImplicitValueInitExprClass:
|
|
|
|
case Stmt::CXXScalarValueInitExprClass:
|
2010-04-14 14:29:29 +08:00
|
|
|
case Stmt::CXXBoolLiteralExprClass:
|
2012-03-07 04:06:12 +08:00
|
|
|
case Stmt::ObjCBoolLiteralExprClass:
|
2010-04-13 21:15:19 +08:00
|
|
|
case Stmt::FloatingLiteralClass:
|
2011-01-05 02:46:34 +08:00
|
|
|
case Stmt::SizeOfPackExprClass:
|
2012-02-28 07:34:19 +08:00
|
|
|
case Stmt::StringLiteralClass:
|
|
|
|
case Stmt::ObjCStringLiteralClass:
|
2012-03-02 07:06:04 +08:00
|
|
|
case Stmt::CXXBindTemporaryExprClass:
|
2012-07-27 09:15:02 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmExprClass:
|
2012-02-17 04:56:01 +08:00
|
|
|
case Stmt::CXXNullPtrLiteralExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet preVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, preVisit, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2012-02-17 04:56:01 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-02-13 11:11:06 +08:00
|
|
|
case Stmt::CXXDefaultArgExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet PreVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
|
|
|
|
|
|
|
|
ExplodedNodeSet Tmp;
|
|
|
|
StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx);
|
|
|
|
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
const Expr *ArgE = cast<CXXDefaultArgExpr>(S)->getExpr();
|
|
|
|
|
|
|
|
// Avoid creating and destroying a lot of APSInts.
|
|
|
|
SVal V;
|
|
|
|
llvm::APSInt Result;
|
|
|
|
|
|
|
|
for (ExplodedNodeSet::iterator I = PreVisit.begin(), E = PreVisit.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ProgramStateRef State = (*I)->getState();
|
|
|
|
|
|
|
|
if (ArgE->EvaluateAsInt(Result, getContext()))
|
|
|
|
V = svalBuilder.makeIntVal(Result);
|
|
|
|
else
|
|
|
|
V = State->getSVal(ArgE, LCtx);
|
|
|
|
|
|
|
|
State = State->BindExpr(S, LCtx, V);
|
|
|
|
Bldr2.generateNode(S, *I, State);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-07 04:06:12 +08:00
|
|
|
case Expr::ObjCArrayLiteralClass:
|
2012-05-12 13:10:43 +08:00
|
|
|
case Expr::ObjCDictionaryLiteralClass:
|
|
|
|
// FIXME: explicitly model with a region and the actual contents
|
|
|
|
// of the container. For now, conjure a symbol.
|
|
|
|
case Expr::ObjCBoxedExprClass: {
|
2012-03-07 04:06:12 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
|
|
|
|
ExplodedNodeSet preVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);
|
|
|
|
|
|
|
|
ExplodedNodeSet Tmp;
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr2(preVisit, Tmp, *currBldrCtx);
|
2012-03-07 04:06:12 +08:00
|
|
|
|
2012-05-12 13:10:43 +08:00
|
|
|
const Expr *Ex = cast<Expr>(S);
|
|
|
|
QualType resultType = Ex->getType();
|
|
|
|
|
2012-03-07 04:06:12 +08:00
|
|
|
for (ExplodedNodeSet::iterator it = preVisit.begin(), et = preVisit.end();
|
|
|
|
it != et; ++it) {
|
|
|
|
ExplodedNode *N = *it;
|
|
|
|
const LocationContext *LCtx = N->getLocationContext();
|
2012-08-22 14:26:06 +08:00
|
|
|
SVal result = svalBuilder.conjureSymbolVal(0, Ex, LCtx, resultType,
|
2012-08-22 14:26:15 +08:00
|
|
|
currBldrCtx->blockCount());
|
2012-03-07 04:06:12 +08:00
|
|
|
ProgramStateRef state = N->getState()->BindExpr(Ex, LCtx, result);
|
|
|
|
Bldr2.generateNode(S, N, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-22 12:56:29 +08:00
|
|
|
case Stmt::ArraySubscriptExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitLvalArraySubscriptExpr(cast<ArraySubscriptExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-22 12:56:29 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
case Stmt::GCCAsmStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-08-25 08:11:56 +08:00
|
|
|
VisitGCCAsmStmt(cast<GCCAsmStmt>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2012-06-12 04:47:18 +08:00
|
|
|
case Stmt::MSAsmStmtClass:
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
VisitMSAsmStmt(cast<MSAsmStmt>(S), Pred, Dst);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
|
2009-11-25 09:33:13 +08:00
|
|
|
case Stmt::BlockExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2009-11-25 09:33:13 +08:00
|
|
|
VisitBlockExpr(cast<BlockExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2009-11-25 09:33:13 +08:00
|
|
|
break;
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::BinaryOperatorClass: {
|
2010-07-20 14:22:24 +08:00
|
|
|
const BinaryOperator* B = cast<BinaryOperator>(S);
|
2008-04-16 07:06:53 +08:00
|
|
|
if (B->isLogicalOp()) {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-04-16 07:06:53 +08:00
|
|
|
VisitLogicalExpr(B, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-08-25 19:45:40 +08:00
|
|
|
else if (B->getOpcode() == BO_Comma) {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(B, Pred,
|
2012-01-07 06:09:28 +08:00
|
|
|
state->BindExpr(B, Pred->getLocationContext(),
|
|
|
|
state->getSVal(B->getRHS(),
|
|
|
|
Pred->getLocationContext())));
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-15 03:47:18 +08:00
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
|
2012-08-31 03:26:48 +08:00
|
|
|
if (AMgr.options.eagerlyAssumeBinOpBifurcation &&
|
2009-12-16 19:27:52 +08:00
|
|
|
(B->isRelationalOp() || B->isEqualityOp())) {
|
2009-08-06 20:48:26 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Tmp);
|
2012-08-31 03:26:48 +08:00
|
|
|
evalEagerlyAssumeBinOpBifurcation(Dst, Tmp, cast<Expr>(S));
|
2009-02-26 06:32:02 +08:00
|
|
|
}
|
|
|
|
else
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
|
2009-02-26 06:32:02 +08:00
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-15 03:47:18 +08:00
|
|
|
|
2012-10-18 03:35:37 +08:00
|
|
|
case Stmt::CXXOperatorCallExprClass: {
|
|
|
|
const CXXOperatorCallExpr *OCE = cast<CXXOperatorCallExpr>(S);
|
|
|
|
|
|
|
|
// For instance method operators, make sure the 'this' argument has a
|
|
|
|
// valid region.
|
|
|
|
const Decl *Callee = OCE->getCalleeDecl();
|
|
|
|
if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(Callee)) {
|
|
|
|
if (MD->isInstance()) {
|
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
ProgramStateRef NewState =
|
|
|
|
createTemporaryRegionIfNeeded(State, LCtx, OCE->getArg(0));
|
|
|
|
if (NewState != State)
|
|
|
|
Pred = Bldr.generateNode(OCE, Pred, NewState, /*Tag=*/0,
|
|
|
|
ProgramPoint::PreStmtKind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
|
|
|
}
|
2011-03-31 01:41:19 +08:00
|
|
|
case Stmt::CallExprClass:
|
2012-03-07 16:35:16 +08:00
|
|
|
case Stmt::CXXMemberCallExprClass:
|
|
|
|
case Stmt::UserDefinedLiteralClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-03-31 01:41:19 +08:00
|
|
|
VisitCallExpr(cast<CallExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-11-15 03:47:18 +08:00
|
|
|
break;
|
2008-04-16 07:06:53 +08:00
|
|
|
}
|
2012-03-10 09:34:17 +08:00
|
|
|
|
|
|
|
case Stmt::CXXCatchStmtClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
VisitCXXCatchStmt(cast<CXXCatchStmt>(S), Pred, Dst);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-15 03:47:18 +08:00
|
|
|
|
2011-10-08 06:48:13 +08:00
|
|
|
case Stmt::CXXTemporaryObjectExprClass:
|
2012-07-27 04:04:13 +08:00
|
|
|
case Stmt::CXXConstructExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-07-27 04:04:13 +08:00
|
|
|
VisitCXXConstructExpr(cast<CXXConstructExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2010-11-01 17:09:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-15 04:28:48 +08:00
|
|
|
case Stmt::CXXNewExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet PostVisit;
|
|
|
|
VisitCXXNewExpr(cast<CXXNewExpr>(S), Pred, PostVisit);
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::CXXDeleteExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet PreVisit;
|
|
|
|
const CXXDeleteExpr *CDE = cast<CXXDeleteExpr>(S);
|
|
|
|
getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
|
|
|
|
|
|
|
|
for (ExplodedNodeSet::iterator i = PreVisit.begin(),
|
|
|
|
e = PreVisit.end(); i != e ; ++i)
|
|
|
|
VisitCXXDeleteExpr(CDE, *i, Dst);
|
|
|
|
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 07:06:53 +08:00
|
|
|
// FIXME: ChooseExpr is really a constant. We need to fix
|
|
|
|
// the CFG do not model them as explicit control-flow.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::ChooseExprClass: { // __builtin_choose_expr
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-08-13 07:37:29 +08:00
|
|
|
const ChooseExpr *C = cast<ChooseExpr>(S);
|
2008-04-16 07:06:53 +08:00
|
|
|
VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::CompoundAssignOperatorClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2008-11-07 18:38:33 +08:00
|
|
|
|
|
|
|
case Stmt::CompoundLiteralExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitCompoundLiteralExpr(cast<CompoundLiteralExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-11-07 18:38:33 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
case Stmt::BinaryConditionalOperatorClass:
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::ConditionalOperatorClass: { // '?' operator
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-02-17 18:25:35 +08:00
|
|
|
const AbstractConditionalOperator *C
|
|
|
|
= cast<AbstractConditionalOperator>(S);
|
|
|
|
VisitGuardedExpr(C, C->getTrueExpr(), C->getFalseExpr(), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-16 19:27:52 +08:00
|
|
|
case Stmt::CXXThisExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2009-12-16 19:27:52 +08:00
|
|
|
VisitCXXThisExpr(cast<CXXThisExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2009-12-16 19:27:52 +08:00
|
|
|
break;
|
|
|
|
|
2010-12-16 15:46:53 +08:00
|
|
|
case Stmt::DeclRefExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
const DeclRefExpr *DE = cast<DeclRefExpr>(S);
|
|
|
|
VisitCommonDeclRefExpr(DE, DE->getDecl(), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::DeclStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-04-16 07:06:53 +08:00
|
|
|
VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-19 07:01:59 +08:00
|
|
|
case Stmt::ImplicitCastExprClass:
|
2010-04-13 20:38:32 +08:00
|
|
|
case Stmt::CStyleCastExprClass:
|
|
|
|
case Stmt::CXXStaticCastExprClass:
|
|
|
|
case Stmt::CXXDynamicCastExprClass:
|
|
|
|
case Stmt::CXXReinterpretCastExprClass:
|
|
|
|
case Stmt::CXXConstCastExprClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Stmt::CXXFunctionalCastExprClass:
|
|
|
|
case Stmt::ObjCBridgedCastExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-08-13 07:37:29 +08:00
|
|
|
const CastExpr *C = cast<CastExpr>(S);
|
2011-06-16 07:02:42 +08:00
|
|
|
// Handle the previsit checks.
|
|
|
|
ExplodedNodeSet dstPrevisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(dstPrevisit, Pred, C, *this);
|
|
|
|
|
|
|
|
// Handle the expression itself.
|
|
|
|
ExplodedNodeSet dstExpr;
|
|
|
|
for (ExplodedNodeSet::iterator i = dstPrevisit.begin(),
|
|
|
|
e = dstPrevisit.end(); i != e ; ++i) {
|
|
|
|
VisitCast(C, C->getSubExpr(), *i, dstExpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the postvisit checks.
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, dstExpr, C, *this);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2011-06-22 01:03:29 +08:00
|
|
|
case Expr::MaterializeTemporaryExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-08-28 01:50:07 +08:00
|
|
|
const MaterializeTemporaryExpr *MTE = cast<MaterializeTemporaryExpr>(S);
|
|
|
|
CreateCXXTemporaryObject(MTE, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2011-06-22 01:03:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-30 13:02:23 +08:00
|
|
|
case Stmt::InitListExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-10-30 13:02:23 +08:00
|
|
|
VisitInitListExpr(cast<InitListExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-10-30 13:02:23 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-17 08:03:18 +08:00
|
|
|
case Stmt::MemberExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitMemberExpr(cast<MemberExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-22 07:43:38 +08:00
|
|
|
break;
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2008-10-17 08:03:18 +08:00
|
|
|
case Stmt::ObjCIvarRefExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitLvalObjCIvarRefExpr(cast<ObjCIvarRefExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-10-17 08:03:18 +08:00
|
|
|
break;
|
2008-11-13 03:24:17 +08:00
|
|
|
|
|
|
|
case Stmt::ObjCForCollectionStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-11-13 03:24:17 +08:00
|
|
|
VisitObjCForCollectionStmt(cast<ObjCForCollectionStmt>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-11-13 03:24:17 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-07-31 04:22:09 +08:00
|
|
|
case Stmt::ObjCMessageExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-07-31 04:22:09 +08:00
|
|
|
VisitObjCMessage(cast<ObjCMessageExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-18 08:30:23 +08:00
|
|
|
case Stmt::ObjCAtThrowStmtClass:
|
|
|
|
case Stmt::CXXThrowExprClass:
|
2008-12-10 04:18:58 +08:00
|
|
|
// FIXME: This is not complete. We basically treat @throw as
|
|
|
|
// an abort.
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateSink(S, Pred, Pred->getState());
|
2008-12-10 04:18:58 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-30 05:04:26 +08:00
|
|
|
case Stmt::ReturnStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-04-30 05:04:26 +08:00
|
|
|
VisitReturnStmt(cast<ReturnStmt>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-30 05:04:26 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
case Stmt::OffsetOfExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
VisitOffsetOfExpr(cast<OffsetOfExpr>(S), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
break;
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
case Stmt::UnaryExprOrTypeTraitExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-03-12 03:24:49 +08:00
|
|
|
VisitUnaryExprOrTypeTraitExpr(cast<UnaryExprOrTypeTraitExpr>(S),
|
|
|
|
Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::StmtExprClass: {
|
2011-08-13 07:37:29 +08:00
|
|
|
const StmtExpr *SE = cast<StmtExpr>(S);
|
2009-02-14 13:55:08 +08:00
|
|
|
|
|
|
|
if (SE->getSubStmt()->body_empty()) {
|
|
|
|
// Empty statement expression.
|
|
|
|
assert(SE->getType() == getContext().VoidTy
|
|
|
|
&& "Empty statement expression must have void type.");
|
|
|
|
break;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (Expr *LastExpr = dyn_cast<Expr>(*SE->getSubStmt()->body_rbegin())) {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(SE, Pred,
|
2012-01-07 06:09:28 +08:00
|
|
|
state->BindExpr(SE, Pred->getLocationContext(),
|
|
|
|
state->getSVal(LastExpr,
|
|
|
|
Pred->getLocationContext())));
|
2009-02-14 13:55:08 +08:00
|
|
|
}
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-30 13:49:49 +08:00
|
|
|
|
2009-03-19 07:49:26 +08:00
|
|
|
case Stmt::UnaryOperatorClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-07-20 14:22:24 +08:00
|
|
|
const UnaryOperator *U = cast<UnaryOperator>(S);
|
2012-08-31 03:26:48 +08:00
|
|
|
if (AMgr.options.eagerlyAssumeBinOpBifurcation && (U->getOpcode() == UO_LNot)) {
|
2009-08-06 20:48:26 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitUnaryOperator(U, Pred, Tmp);
|
2012-08-31 03:26:48 +08:00
|
|
|
evalEagerlyAssumeBinOpBifurcation(Dst, Tmp, U);
|
2009-03-19 07:49:26 +08:00
|
|
|
}
|
|
|
|
else
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitUnaryOperator(U, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-30 05:04:26 +08:00
|
|
|
break;
|
2009-03-19 07:49:26 +08:00
|
|
|
}
|
2011-11-06 17:01:30 +08:00
|
|
|
|
|
|
|
case Stmt::PseudoObjectExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-11-06 17:01:30 +08:00
|
|
|
const PseudoObjectExpr *PE = cast<PseudoObjectExpr>(S);
|
|
|
|
if (const Expr *Result = PE->getResultExpr()) {
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal V = state->getSVal(Result, Pred->getLocationContext());
|
|
|
|
Bldr.generateNode(S, Pred,
|
|
|
|
state->BindExpr(S, Pred->getLocationContext(), V));
|
2011-11-06 17:01:30 +08:00
|
|
|
}
|
|
|
|
else
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(S, Pred,
|
|
|
|
state->BindExpr(S, Pred->getLocationContext(),
|
|
|
|
UnknownVal()));
|
2011-11-06 17:01:30 +08:00
|
|
|
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
bool ExprEngine::replayWithoutInlining(ExplodedNode *N,
|
|
|
|
const LocationContext *CalleeLC) {
|
|
|
|
const StackFrameContext *CalleeSF = CalleeLC->getCurrentStackFrame();
|
|
|
|
const StackFrameContext *CallerSF = CalleeSF->getParent()->getCurrentStackFrame();
|
|
|
|
assert(CalleeSF && CallerSF);
|
|
|
|
ExplodedNode *BeforeProcessingCall = 0;
|
2012-07-11 06:07:42 +08:00
|
|
|
const Stmt *CE = CalleeSF->getCallSite();
|
2012-03-28 04:02:53 +08:00
|
|
|
|
|
|
|
// Find the first node before we started processing the call expression.
|
|
|
|
while (N) {
|
|
|
|
ProgramPoint L = N->getLocation();
|
|
|
|
BeforeProcessingCall = N;
|
|
|
|
N = N->pred_empty() ? NULL : *(N->pred_begin());
|
|
|
|
|
|
|
|
// Skip the nodes corresponding to the inlined code.
|
|
|
|
if (L.getLocationContext()->getCurrentStackFrame() != CallerSF)
|
|
|
|
continue;
|
|
|
|
// We reached the caller. Find the node right before we started
|
2012-07-11 06:07:42 +08:00
|
|
|
// processing the call.
|
2012-04-21 05:59:08 +08:00
|
|
|
if (L.isPurgeKind())
|
2012-03-28 04:02:53 +08:00
|
|
|
continue;
|
2013-02-22 06:23:56 +08:00
|
|
|
if (L.getAs<PreImplicitCall>())
|
2012-07-11 06:07:42 +08:00
|
|
|
continue;
|
2013-02-22 06:23:56 +08:00
|
|
|
if (L.getAs<CallEnter>())
|
2012-07-11 06:07:52 +08:00
|
|
|
continue;
|
2013-02-22 06:23:56 +08:00
|
|
|
if (Optional<StmtPoint> SP = L.getAs<StmtPoint>())
|
2012-07-11 06:07:42 +08:00
|
|
|
if (SP->getStmt() == CE)
|
2012-03-28 04:02:53 +08:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-29 01:05:50 +08:00
|
|
|
if (!BeforeProcessingCall)
|
2012-03-28 04:02:53 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: Clean up the unneeded nodes.
|
|
|
|
|
|
|
|
// Build an Epsilon node from which we will restart the analyzes.
|
2012-07-11 06:07:42 +08:00
|
|
|
// Note that CE is permitted to be NULL!
|
2012-03-28 04:02:53 +08:00
|
|
|
ProgramPoint NewNodeLoc =
|
|
|
|
EpsilonPoint(BeforeProcessingCall->getLocationContext(), CE);
|
|
|
|
// Add the special flag to GDM to signal retrying with no inlining.
|
|
|
|
// Note, changing the state ensures that we are not going to cache out.
|
|
|
|
ProgramStateRef NewNodeState = BeforeProcessingCall->getState();
|
2013-01-16 06:09:45 +08:00
|
|
|
NewNodeState =
|
|
|
|
NewNodeState->set<ReplayWithoutInlining>(const_cast<Stmt *>(CE));
|
2012-03-28 04:02:53 +08:00
|
|
|
|
|
|
|
// Make the new node a successor of BeforeProcessingCall.
|
|
|
|
bool IsNew = false;
|
|
|
|
ExplodedNode *NewNode = G.getNode(NewNodeLoc, NewNodeState, false, &IsNew);
|
2012-03-29 01:05:50 +08:00
|
|
|
// We cached out at this point. Caching out is common due to us backtracking
|
|
|
|
// from the inlined function, which might spawn several paths.
|
|
|
|
if (!IsNew)
|
|
|
|
return true;
|
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
NewNode->addPredecessor(BeforeProcessingCall, G);
|
|
|
|
|
|
|
|
// Add the new node to the work list.
|
|
|
|
Engine.enqueueStmtNode(NewNode, CalleeSF->getCallSiteBlock(),
|
|
|
|
CalleeSF->getIndex());
|
|
|
|
NumTimesRetriedWithoutInlining++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
/// Block entrance. (Update counters).
|
2012-03-29 01:05:50 +08:00
|
|
|
void ExprEngine::processCFGBlockEntrance(const BlockEdge &L,
|
2012-11-03 10:54:11 +08:00
|
|
|
NodeBuilderWithSinks &nodeBuilder,
|
|
|
|
ExplodedNode *Pred) {
|
2011-01-11 14:37:47 +08:00
|
|
|
|
|
|
|
// FIXME: Refactor this into a checker.
|
2012-08-31 03:26:56 +08:00
|
|
|
if (nodeBuilder.getContext().blockCount() >= AMgr.options.maxBlockVisitOnPath) {
|
2011-08-13 07:04:46 +08:00
|
|
|
static SimpleProgramPointTag tag("ExprEngine : Block count exceeded");
|
2012-03-29 01:05:50 +08:00
|
|
|
const ExplodedNode *Sink =
|
2012-11-03 10:54:11 +08:00
|
|
|
nodeBuilder.generateSink(Pred->getState(), Pred, &tag);
|
2012-03-23 05:06:03 +08:00
|
|
|
|
|
|
|
// Check if we stopped at the top level function or not.
|
|
|
|
// Root node should have the location context of the top most function.
|
2012-11-03 10:54:11 +08:00
|
|
|
const LocationContext *CalleeLC = Pred->getLocation().getLocationContext();
|
2012-03-30 13:48:10 +08:00
|
|
|
const LocationContext *CalleeSF = CalleeLC->getCurrentStackFrame();
|
2012-03-28 04:02:53 +08:00
|
|
|
const LocationContext *RootLC =
|
|
|
|
(*G.roots_begin())->getLocation().getLocationContext();
|
2012-03-30 13:48:10 +08:00
|
|
|
if (RootLC->getCurrentStackFrame() != CalleeSF) {
|
2012-04-03 10:05:47 +08:00
|
|
|
Engine.FunctionSummaries->markReachedMaxBlockCount(CalleeSF->getDecl());
|
2012-03-30 13:48:10 +08:00
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
// Re-run the call evaluation without inlining it, by storing the
|
|
|
|
// no-inlining policy in the state and enqueuing the new work item on
|
|
|
|
// the list. Replay should almost never fail. Use the stats to catch it
|
|
|
|
// if it does.
|
2012-08-31 03:26:43 +08:00
|
|
|
if ((!AMgr.options.NoRetryExhausted &&
|
2012-11-03 10:54:11 +08:00
|
|
|
replayWithoutInlining(Pred, CalleeLC)))
|
2012-03-29 01:05:50 +08:00
|
|
|
return;
|
|
|
|
NumMaxBlockCountReachedInInlined++;
|
2012-03-28 04:02:53 +08:00
|
|
|
} else
|
2012-03-23 05:06:03 +08:00
|
|
|
NumMaxBlockCountReached++;
|
2012-03-29 01:05:50 +08:00
|
|
|
|
|
|
|
// Make sink nodes as exhausted(for stats) only if retry failed.
|
|
|
|
Engine.blocksExhausted.push_back(std::make_pair(L, Sink));
|
2011-01-11 14:37:47 +08:00
|
|
|
}
|
2008-04-16 07:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch processing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
/// RecoverCastedSymbol - A helper function for ProcessBranch that is used
|
|
|
|
/// to try to recover some path-sensitivity for casts of symbolic
|
|
|
|
/// integers that promote their values (which are currently not tracked well).
|
|
|
|
/// This function returns the SVal bound to Condition->IgnoreCasts if all the
|
|
|
|
// cast(s) did was sign-extend the original value.
|
2011-08-20 14:00:03 +08:00
|
|
|
static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state,
|
2011-08-20 14:00:03 +08:00
|
|
|
const Stmt *Condition,
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx,
|
2011-08-20 14:00:03 +08:00
|
|
|
ASTContext &Ctx) {
|
2009-03-14 00:32:54 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
const Expr *Ex = dyn_cast<Expr>(Condition);
|
2009-03-14 00:32:54 +08:00
|
|
|
if (!Ex)
|
|
|
|
return UnknownVal();
|
|
|
|
|
|
|
|
uint64_t bits = 0;
|
|
|
|
bool bitsInit = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
while (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) {
|
2009-03-14 00:32:54 +08:00
|
|
|
QualType T = CE->getType();
|
|
|
|
|
|
|
|
if (!T->isIntegerType())
|
|
|
|
return UnknownVal();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
uint64_t newBits = Ctx.getTypeSize(T);
|
|
|
|
if (!bitsInit || newBits < bits) {
|
|
|
|
bitsInit = true;
|
|
|
|
bits = newBits;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
Ex = CE->getSubExpr();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We reached a non-cast. Is it a symbolic value?
|
|
|
|
QualType T = Ex->getType();
|
|
|
|
|
|
|
|
if (!bitsInit || !T->isIntegerType() || Ctx.getTypeSize(T) > bits)
|
|
|
|
return UnknownVal();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
return state->getSVal(Ex, LCtx);
|
2009-03-14 00:32:54 +08:00
|
|
|
}
|
|
|
|
|
2012-07-14 13:04:10 +08:00
|
|
|
static const Stmt *ResolveCondition(const Stmt *Condition,
|
|
|
|
const CFGBlock *B) {
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(Condition))
|
|
|
|
Condition = Ex->IgnoreParens();
|
|
|
|
|
|
|
|
const BinaryOperator *BO = dyn_cast<BinaryOperator>(Condition);
|
|
|
|
if (!BO || !BO->isLogicalOp())
|
|
|
|
return Condition;
|
|
|
|
|
|
|
|
// For logical operations, we still have the case where some branches
|
|
|
|
// use the traditional "merge" approach and others sink the branch
|
|
|
|
// directly into the basic blocks representing the logical operation.
|
|
|
|
// We need to distinguish between those two cases here.
|
|
|
|
|
|
|
|
// The invariants are still shifting, but it is possible that the
|
|
|
|
// last element in a CFGBlock is not a CFGStmt. Look for the last
|
|
|
|
// CFGStmt as the value of the condition.
|
|
|
|
CFGBlock::const_reverse_iterator I = B->rbegin(), E = B->rend();
|
|
|
|
for (; I != E; ++I) {
|
|
|
|
CFGElement Elem = *I;
|
2013-02-23 08:29:34 +08:00
|
|
|
Optional<CFGStmt> CS = Elem.getAs<CFGStmt>();
|
2012-07-14 13:04:10 +08:00
|
|
|
if (!CS)
|
|
|
|
continue;
|
2013-02-23 08:29:34 +08:00
|
|
|
if (CS->getStmt() != Condition)
|
2012-07-14 13:04:10 +08:00
|
|
|
break;
|
|
|
|
return Condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(I != E);
|
|
|
|
|
|
|
|
while (Condition) {
|
|
|
|
BO = dyn_cast<BinaryOperator>(Condition);
|
|
|
|
if (!BO || !BO->isLogicalOp())
|
|
|
|
return Condition;
|
|
|
|
Condition = BO->getRHS()->IgnoreParens();
|
|
|
|
}
|
|
|
|
llvm_unreachable("could not resolve condition");
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::processBranch(const Stmt *Condition, const Stmt *Term,
|
2011-10-19 07:06:04 +08:00
|
|
|
NodeBuilderContext& BldCtx,
|
2011-10-19 07:06:16 +08:00
|
|
|
ExplodedNode *Pred,
|
2011-10-25 02:25:53 +08:00
|
|
|
ExplodedNodeSet &Dst,
|
2011-10-19 07:06:04 +08:00
|
|
|
const CFGBlock *DstT,
|
|
|
|
const CFGBlock *DstF) {
|
2012-08-22 14:26:15 +08:00
|
|
|
currBldrCtx = &BldCtx;
|
2011-10-26 03:56:54 +08:00
|
|
|
|
2008-02-16 06:29:00 +08:00
|
|
|
// Check for NULL conditions; e.g. "for(;;)"
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!Condition) {
|
2011-10-25 02:25:53 +08:00
|
|
|
BranchNodeBuilder NullCondBldr(Pred, Dst, BldCtx, DstT, DstF);
|
2011-10-19 07:06:04 +08:00
|
|
|
NullCondBldr.markInfeasible(false);
|
2011-10-19 07:06:44 +08:00
|
|
|
NullCondBldr.generateNode(Pred->getState(), true, Pred);
|
2008-02-16 06:29:00 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-07-14 13:04:10 +08:00
|
|
|
|
|
|
|
// Resolve the condition in the precense of nested '||' and '&&'.
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(Condition))
|
|
|
|
Condition = Ex->IgnoreParens();
|
|
|
|
|
|
|
|
Condition = ResolveCondition(Condition, BldCtx.getBlock());
|
2009-03-11 11:54:24 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
|
|
|
Condition->getLocStart(),
|
|
|
|
"Error evaluating branch");
|
2009-08-27 09:39:13 +08:00
|
|
|
|
2011-10-26 03:56:54 +08:00
|
|
|
ExplodedNodeSet CheckersOutSet;
|
|
|
|
getCheckerManager().runCheckersForBranchCondition(Condition, CheckersOutSet,
|
2011-10-19 07:06:44 +08:00
|
|
|
Pred, *this);
|
2011-10-25 02:25:58 +08:00
|
|
|
// We generated only sinks.
|
2011-10-26 03:56:54 +08:00
|
|
|
if (CheckersOutSet.empty())
|
2011-10-25 02:25:58 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-26 03:56:54 +08:00
|
|
|
BranchNodeBuilder builder(CheckersOutSet, Dst, BldCtx, DstT, DstF);
|
|
|
|
for (NodeBuilder::iterator I = CheckersOutSet.begin(),
|
|
|
|
E = CheckersOutSet.end(); E != I; ++I) {
|
2011-10-19 07:06:21 +08:00
|
|
|
ExplodedNode *PredI = *I;
|
|
|
|
|
|
|
|
if (PredI->isSink())
|
|
|
|
continue;
|
|
|
|
|
2012-12-15 03:08:20 +08:00
|
|
|
ProgramStateRef PrevState = PredI->getState();
|
|
|
|
SVal X = PrevState->getSVal(Condition, PredI->getLocationContext());
|
2011-10-19 07:06:21 +08:00
|
|
|
|
|
|
|
if (X.isUnknownOrUndef()) {
|
|
|
|
// Give it a chance to recover from unknown.
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(Condition)) {
|
|
|
|
if (Ex->getType()->isIntegerType()) {
|
|
|
|
// Try to recover some path-sensitivity. Right now casts of symbolic
|
|
|
|
// integers that promote their values are currently not tracked well.
|
|
|
|
// If 'Condition' is such an expression, try and recover the
|
|
|
|
// underlying value and use that instead.
|
|
|
|
SVal recovered = RecoverCastedSymbol(getStateManager(),
|
|
|
|
PrevState, Condition,
|
2012-12-15 03:08:20 +08:00
|
|
|
PredI->getLocationContext(),
|
2011-10-19 07:06:21 +08:00
|
|
|
getContext());
|
|
|
|
|
|
|
|
if (!recovered.isUnknown()) {
|
|
|
|
X = recovered;
|
|
|
|
}
|
2009-11-23 11:20:54 +08:00
|
|
|
}
|
2008-01-31 07:03:39 +08:00
|
|
|
}
|
2009-11-23 11:20:54 +08:00
|
|
|
}
|
2012-01-07 06:09:28 +08:00
|
|
|
|
2009-11-23 11:20:54 +08:00
|
|
|
// If the condition is still unknown, give up.
|
2011-02-28 09:27:57 +08:00
|
|
|
if (X.isUnknownOrUndef()) {
|
2012-07-26 05:58:29 +08:00
|
|
|
builder.generateNode(PrevState, true, PredI);
|
|
|
|
builder.generateNode(PrevState, false, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2013-02-20 13:52:05 +08:00
|
|
|
DefinedSVal V = X.castAs<DefinedSVal>();
|
2009-11-23 11:20:54 +08:00
|
|
|
|
2012-12-07 02:58:09 +08:00
|
|
|
ProgramStateRef StTrue, StFalse;
|
|
|
|
tie(StTrue, StFalse) = PrevState->assume(V);
|
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
// Process the true branch.
|
|
|
|
if (builder.isFeasible(true)) {
|
2012-12-07 02:58:09 +08:00
|
|
|
if (StTrue)
|
|
|
|
builder.generateNode(StTrue, true, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(true);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
// Process the false branch.
|
|
|
|
if (builder.isFeasible(false)) {
|
2012-12-07 02:58:09 +08:00
|
|
|
if (StFalse)
|
|
|
|
builder.generateNode(StFalse, false, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(false);
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 14:26:15 +08:00
|
|
|
currBldrCtx = 0;
|
2008-02-05 08:26:40 +08:00
|
|
|
}
|
|
|
|
|
2011-01-11 10:34:45 +08:00
|
|
|
/// processIndirectGoto - Called by CoreEngine. Used to generate successor
|
2008-02-13 08:24:44 +08:00
|
|
|
/// nodes by processing the 'effects' of a computed goto jump.
|
2011-02-17 15:39:24 +08:00
|
|
|
void ExprEngine::processIndirectGoto(IndirectGotoNodeBuilder &builder) {
|
2008-02-13 08:24:44 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = builder.getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal V = state->getSVal(builder.getTarget(), builder.getLocationContext());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
// Three possibilities:
|
|
|
|
//
|
|
|
|
// (1) We know the computed label.
|
2008-02-28 17:25:22 +08:00
|
|
|
// (2) The label is NULL (or some other constant), or Undefined.
|
2008-02-13 08:24:44 +08:00
|
|
|
// (3) We have no clue about the label. Dispatch to all targets.
|
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
typedef IndirectGotoNodeBuilder::iterator iterator;
|
2008-02-13 08:24:44 +08:00
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<loc::GotoLabel> LV = V.getAs<loc::GotoLabel>()) {
|
2013-02-20 13:52:05 +08:00
|
|
|
const LabelDecl *L = LV->getLabel();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-17 15:39:24 +08:00
|
|
|
for (iterator I = builder.begin(), E = builder.end(); I != E; ++I) {
|
2008-02-14 01:27:37 +08:00
|
|
|
if (I.getLabel() == L) {
|
2009-02-13 09:45:31 +08:00
|
|
|
builder.generateNode(I, state);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("No block with label.");
|
2008-02-13 08:24:44 +08:00
|
|
|
}
|
|
|
|
|
2013-02-20 13:52:05 +08:00
|
|
|
if (V.getAs<loc::ConcreteInt>() || V.getAs<UndefinedVal>()) {
|
2008-02-13 08:24:44 +08:00
|
|
|
// Dispatch to the first target and mark it as a sink.
|
2009-11-24 15:06:39 +08:00
|
|
|
//ExplodedNode* N = builder.generateNode(builder.begin(), state, true);
|
|
|
|
// FIXME: add checker visit.
|
|
|
|
// UndefBranches.insert(N);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
// This is really a catch-all. We don't support symbolics yet.
|
2009-04-24 01:49:43 +08:00
|
|
|
// FIXME: Implement dispatch for symbolic pointers.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I)
|
2009-02-13 09:45:31 +08:00
|
|
|
builder.generateNode(I, state);
|
2008-02-13 08:24:44 +08:00
|
|
|
}
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
/// ProcessEndPath - Called by CoreEngine. Used to generate end-of-path
|
2009-11-14 09:05:20 +08:00
|
|
|
/// nodes when the control reaches the end of a function.
|
2012-11-03 10:54:11 +08:00
|
|
|
void ExprEngine::processEndOfFunction(NodeBuilderContext& BC,
|
|
|
|
ExplodedNode *Pred) {
|
|
|
|
StateMgr.EndPath(Pred->getState());
|
2012-11-03 10:54:20 +08:00
|
|
|
|
2011-10-26 03:56:48 +08:00
|
|
|
ExplodedNodeSet Dst;
|
2012-11-03 10:54:20 +08:00
|
|
|
if (Pred->getLocationContext()->inTopFrame()) {
|
|
|
|
// Remove dead symbols.
|
|
|
|
ExplodedNodeSet AfterRemovedDead;
|
|
|
|
removeDeadOnEndOfFunction(BC, Pred, AfterRemovedDead);
|
|
|
|
|
|
|
|
// Notify checkers.
|
|
|
|
for (ExplodedNodeSet::iterator I = AfterRemovedDead.begin(),
|
|
|
|
E = AfterRemovedDead.end(); I != E; ++I) {
|
2013-01-03 08:25:29 +08:00
|
|
|
getCheckerManager().runCheckersForEndFunction(BC, Dst, *I, *this);
|
2012-11-03 10:54:20 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-01-03 08:25:29 +08:00
|
|
|
getCheckerManager().runCheckersForEndFunction(BC, Dst, Pred, *this);
|
2012-11-03 10:54:20 +08:00
|
|
|
}
|
|
|
|
|
2011-10-27 08:59:28 +08:00
|
|
|
Engine.enqueueEndOfFunction(Dst);
|
2009-11-14 09:05:20 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
/// ProcessSwitch - Called by CoreEngine. Used to generate successor
|
2008-02-14 07:08:21 +08:00
|
|
|
/// nodes by processing the 'effects' of a switch statement.
|
2011-01-11 10:34:45 +08:00
|
|
|
void ExprEngine::processSwitch(SwitchNodeBuilder& builder) {
|
2010-12-23 02:53:44 +08:00
|
|
|
typedef SwitchNodeBuilder::iterator iterator;
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = builder.getState();
|
2011-08-13 07:37:29 +08:00
|
|
|
const Expr *CondE = builder.getCondition();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal CondV_untested = state->getSVal(CondE, builder.getLocationContext());
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2009-09-12 06:07:28 +08:00
|
|
|
if (CondV_untested.isUndef()) {
|
2009-11-24 15:06:39 +08:00
|
|
|
//ExplodedNode* N = builder.generateDefaultCaseNode(state, true);
|
2010-02-16 07:02:46 +08:00
|
|
|
// FIXME: add checker
|
2009-11-24 15:06:39 +08:00
|
|
|
//UndefBranches.insert(N);
|
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-02-20 13:52:05 +08:00
|
|
|
DefinedOrUnknownSVal CondV = CondV_untested.castAs<DefinedOrUnknownSVal>();
|
2008-02-19 06:57:02 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef DefaultSt = state;
|
2010-08-27 06:19:33 +08:00
|
|
|
|
|
|
|
iterator I = builder.begin(), EI = builder.end();
|
|
|
|
bool defaultIsFeasible = I == EI;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-27 06:19:33 +08:00
|
|
|
for ( ; I != EI; ++I) {
|
2011-03-02 07:12:55 +08:00
|
|
|
// Successor may be pruned out during CFG construction.
|
|
|
|
if (!I.getBlock())
|
|
|
|
continue;
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const CaseStmt *Case = I.getCase();
|
2009-01-17 09:54:16 +08:00
|
|
|
|
|
|
|
// Evaluate the LHS of the case value.
|
2011-10-15 04:22:00 +08:00
|
|
|
llvm::APSInt V1 = Case->getLHS()->EvaluateKnownConstInt(getContext());
|
|
|
|
assert(V1.getBitWidth() == getContext().getTypeSize(CondE->getType()));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
// Get the RHS of the case, if it exists.
|
2011-10-15 04:22:00 +08:00
|
|
|
llvm::APSInt V2;
|
|
|
|
if (const Expr *E = Case->getRHS())
|
|
|
|
V2 = E->EvaluateKnownConstInt(getContext());
|
2008-03-18 06:17:56 +08:00
|
|
|
else
|
|
|
|
V2 = V1;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
// FIXME: Eventually we should replace the logic below with a range
|
|
|
|
// comparison, rather than concretize the values within the range.
|
2008-02-22 02:02:17 +08:00
|
|
|
// This should be easy once we have "ranges" for NonLVals.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
do {
|
2011-10-15 04:22:00 +08:00
|
|
|
nonloc::ConcreteInt CaseVal(getBasicVals().getValue(V1));
|
2010-12-02 05:57:22 +08:00
|
|
|
DefinedOrUnknownSVal Res = svalBuilder.evalEQ(DefaultSt ? DefaultSt : state,
|
2010-01-09 02:54:04 +08:00
|
|
|
CondV, CaseVal);
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Now "assume" that the case matches.
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef stateNew = state->assume(Res, true)) {
|
2009-06-19 06:57:13 +08:00
|
|
|
builder.generateCaseStmtNode(I, stateNew);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
// If CondV evaluates to a constant, then we know that this
|
|
|
|
// is the *only* case that we can take, so stop evaluating the
|
|
|
|
// others.
|
2013-02-20 13:52:05 +08:00
|
|
|
if (CondV.getAs<nonloc::ConcreteInt>())
|
2008-02-14 07:08:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
// Now "assume" that the case doesn't match. Add this state
|
|
|
|
// to the default state (if it is feasible).
|
2010-01-09 02:54:04 +08:00
|
|
|
if (DefaultSt) {
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef stateNew = DefaultSt->assume(Res, false)) {
|
2010-01-09 02:54:04 +08:00
|
|
|
defaultIsFeasible = true;
|
|
|
|
DefaultSt = stateNew;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
defaultIsFeasible = false;
|
|
|
|
DefaultSt = NULL;
|
|
|
|
}
|
2008-04-23 13:03:18 +08:00
|
|
|
}
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
// Concretize the next value in the range.
|
2011-10-15 04:22:00 +08:00
|
|
|
if (V1 == V2)
|
2008-03-18 06:17:56 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-15 04:22:00 +08:00
|
|
|
++V1;
|
|
|
|
assert (V1 <= V2);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
} while (true);
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-09-09 08:40:40 +08:00
|
|
|
if (!defaultIsFeasible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we have switch(enum value), the default branch is not
|
|
|
|
// feasible if all of the enum constants not covered by 'case:' statements
|
|
|
|
// are not feasible values for the switch condition.
|
|
|
|
//
|
|
|
|
// Note that this isn't as accurate as it could be. Even if there isn't
|
|
|
|
// a case for a particular enum value as long as that enum value isn't
|
|
|
|
// feasible then it shouldn't be considered for making 'default:' reachable.
|
|
|
|
const SwitchStmt *SS = builder.getSwitch();
|
|
|
|
const Expr *CondExpr = SS->getCond()->IgnoreParenImpCasts();
|
|
|
|
if (CondExpr->getType()->getAs<EnumType>()) {
|
|
|
|
if (SS->isAllEnumCasesCovered())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.generateDefaultCaseNode(DefaultSt);
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-04-17 02:39:06 +08:00
|
|
|
// Transfer functions: Loads and stores.
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-16 07:55:06 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, const NamedDecl *D,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2008-10-16 14:09:51 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2012-05-19 08:22:07 +08:00
|
|
|
assert(Ex->isGLValue());
|
2009-08-22 06:28:32 +08:00
|
|
|
SVal V = state->getLValue(VD, Pred->getLocationContext());
|
2008-10-17 10:20:14 +08:00
|
|
|
|
2010-12-16 15:46:53 +08:00
|
|
|
// For references, the 'lvalue' is the pointer address stored in the
|
|
|
|
// reference region.
|
|
|
|
if (VD->getType()->isReferenceType()) {
|
|
|
|
if (const MemRegion *R = V.getAsRegion())
|
|
|
|
V = state->getSVal(R);
|
|
|
|
else
|
|
|
|
V = UnknownVal();
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
}
|
2008-10-16 14:09:51 +08:00
|
|
|
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0,
|
2011-10-25 02:26:19 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
return;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) {
|
2012-05-19 08:22:07 +08:00
|
|
|
assert(!Ex->isGLValue());
|
2010-12-02 15:49:45 +08:00
|
|
|
SVal V = svalBuilder.makeIntVal(ED->getInitVal());
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V));
|
2008-10-16 14:09:51 +08:00
|
|
|
return;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2010-12-02 15:49:45 +08:00
|
|
|
SVal V = svalBuilder.getFunctionPointer(FD);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0,
|
2011-10-25 02:26:19 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
2008-10-16 14:09:51 +08:00
|
|
|
return;
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
2012-03-23 05:42:31 +08:00
|
|
|
if (isa<FieldDecl>(D)) {
|
2012-08-21 02:43:42 +08:00
|
|
|
// FIXME: Compute lvalue of field pointers-to-member.
|
2012-08-24 07:01:43 +08:00
|
|
|
// Right now we just use a non-null void pointer, so that it gives proper
|
|
|
|
// results in boolean contexts.
|
|
|
|
SVal V = svalBuilder.conjureSymbolVal(Ex, LCtx, getContext().VoidPtrTy,
|
|
|
|
currBldrCtx->blockCount());
|
2013-02-20 13:52:05 +08:00
|
|
|
state = state->assume(V.castAs<DefinedOrUnknownSVal>(), true);
|
2012-08-24 07:01:43 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), 0,
|
2012-08-21 02:43:42 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
2012-03-23 05:42:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-21 02:43:42 +08:00
|
|
|
llvm_unreachable("Support for this Decl not implemented.");
|
2008-02-07 12:16:04 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 12:56:29 +08:00
|
|
|
/// VisitArraySubscriptExpr - Transfer function for array accesses
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitLvalArraySubscriptExpr(const ArraySubscriptExpr *A,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst){
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const Expr *Base = A->getBase()->IgnoreParens();
|
|
|
|
const Expr *Idx = A->getIdx()->IgnoreParens();
|
2010-12-16 15:46:53 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-30 05:18:17 +08:00
|
|
|
ExplodedNodeSet checkerPreStmt;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(checkerPreStmt, Pred, A, *this);
|
|
|
|
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(checkerPreStmt, Dst, *currBldrCtx);
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2011-07-30 05:18:17 +08:00
|
|
|
for (ExplodedNodeSet::iterator it = checkerPreStmt.begin(),
|
|
|
|
ei = checkerPreStmt.end(); it != ei; ++it) {
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx = (*it)->getLocationContext();
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = (*it)->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal V = state->getLValue(A->getType(),
|
|
|
|
state->getSVal(Idx, LCtx),
|
|
|
|
state->getSVal(Base, LCtx));
|
2012-05-19 08:22:07 +08:00
|
|
|
assert(A->isGLValue());
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(A, *it, state->BindExpr(A, LCtx, V), 0,
|
|
|
|
ProgramPoint::PostLValueKind);
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
2008-04-22 12:56:29 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
/// VisitMemberExpr - Transfer function for member expressions.
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
|
2011-11-02 06:41:09 +08:00
|
|
|
ExplodedNodeSet &TopDst) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, TopDst, *currBldrCtx);
|
2011-11-02 06:41:09 +08:00
|
|
|
ExplodedNodeSet Dst;
|
2012-10-24 07:59:08 +08:00
|
|
|
ValueDecl *Member = M->getMemberDecl();
|
2012-06-23 07:55:50 +08:00
|
|
|
|
2012-10-24 07:59:08 +08:00
|
|
|
// Handle static member variables and enum constants accessed via
|
|
|
|
// member syntax.
|
|
|
|
if (isa<VarDecl>(Member) || isa<EnumConstantDecl>(Member)) {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-10-24 07:59:08 +08:00
|
|
|
VisitCommonDeclRefExpr(M, Member, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2011-08-17 05:37:52 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-06-23 07:55:50 +08:00
|
|
|
|
2012-10-18 03:35:37 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
Expr *BaseExpr = M->getBase();
|
|
|
|
|
2012-06-23 07:55:50 +08:00
|
|
|
// Handle C++ method calls.
|
2012-10-24 07:59:08 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
|
2012-10-18 03:35:37 +08:00
|
|
|
if (MD->isInstance())
|
|
|
|
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
|
2012-06-23 07:55:50 +08:00
|
|
|
|
2012-10-18 03:35:37 +08:00
|
|
|
SVal MDVal = svalBuilder.getFunctionPointer(MD);
|
|
|
|
state = state->BindExpr(M, LCtx, MDVal);
|
2012-09-29 09:36:47 +08:00
|
|
|
|
2012-10-18 03:35:37 +08:00
|
|
|
Bldr.generateNode(M, Pred, state);
|
2012-09-29 09:36:51 +08:00
|
|
|
return;
|
2012-09-29 09:36:47 +08:00
|
|
|
}
|
|
|
|
|
2012-10-18 03:35:37 +08:00
|
|
|
// Handle regular struct fields / member variables.
|
|
|
|
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
|
|
|
|
SVal baseExprVal = state->getSVal(BaseExpr, LCtx);
|
2012-10-02 03:07:15 +08:00
|
|
|
|
2012-10-24 07:59:08 +08:00
|
|
|
FieldDecl *field = cast<FieldDecl>(Member);
|
2011-07-30 05:18:19 +08:00
|
|
|
SVal L = state->getLValue(field, baseExprVal);
|
2012-08-01 00:34:07 +08:00
|
|
|
if (M->isGLValue()) {
|
|
|
|
if (field->getType()->isReferenceType()) {
|
2012-10-02 03:07:15 +08:00
|
|
|
if (const MemRegion *R = L.getAsRegion())
|
|
|
|
L = state->getSVal(R);
|
|
|
|
else
|
2012-08-01 00:34:07 +08:00
|
|
|
L = UnknownVal();
|
|
|
|
}
|
|
|
|
|
2012-10-02 03:07:15 +08:00
|
|
|
Bldr.generateNode(M, Pred, state->BindExpr(M, LCtx, L), 0,
|
|
|
|
ProgramPoint::PostLValueKind);
|
2012-08-01 00:34:07 +08:00
|
|
|
} else {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-04-07 06:10:18 +08:00
|
|
|
evalLoad(Dst, M, M, Pred, state, L);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
}
|
2008-04-22 07:43:38 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 08:38:25 +08:00
|
|
|
namespace {
|
|
|
|
class CollectReachableSymbolsCallback : public SymbolVisitor {
|
|
|
|
InvalidatedSymbols Symbols;
|
|
|
|
public:
|
|
|
|
CollectReachableSymbolsCallback(ProgramStateRef State) {}
|
|
|
|
const InvalidatedSymbols &getSymbols() const { return Symbols; }
|
|
|
|
|
|
|
|
bool VisitSymbol(SymbolRef Sym) {
|
|
|
|
Symbols.insert(Sym);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2012-12-21 09:50:14 +08:00
|
|
|
// A value escapes in three possible cases:
|
|
|
|
// (1) We are binding to something that is not a memory region.
|
|
|
|
// (2) We are binding to a MemrRegion that does not have stack storage.
|
|
|
|
// (3) We are binding to a MemRegion with stack storage that the store
|
|
|
|
// does not understand.
|
2012-12-20 08:38:25 +08:00
|
|
|
ProgramStateRef ExprEngine::processPointerEscapedOnBind(ProgramStateRef State,
|
2012-12-21 09:50:14 +08:00
|
|
|
SVal Loc, SVal Val) {
|
2012-12-20 08:38:25 +08:00
|
|
|
// Are we storing to something that causes the value to "escape"?
|
|
|
|
bool escapes = true;
|
|
|
|
|
|
|
|
// TODO: Move to StoreManager.
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<loc::MemRegionVal> regionLoc = Loc.getAs<loc::MemRegionVal>()) {
|
2012-12-20 08:38:25 +08:00
|
|
|
escapes = !regionLoc->getRegion()->hasStackStorage();
|
|
|
|
|
|
|
|
if (!escapes) {
|
|
|
|
// To test (3), generate a new state with the binding added. If it is
|
|
|
|
// the same state, then it escapes (since the store cannot represent
|
|
|
|
// the binding).
|
|
|
|
// Do this only if we know that the store is not supposed to generate the
|
|
|
|
// same state.
|
|
|
|
SVal StoredVal = State->getSVal(regionLoc->getRegion());
|
|
|
|
if (StoredVal != Val)
|
|
|
|
escapes = (State == (State->bindLoc(*regionLoc, Val)));
|
|
|
|
}
|
2013-02-06 08:01:14 +08:00
|
|
|
if (!escapes) {
|
|
|
|
// Case 4: We do not currently model what happens when a symbol is
|
|
|
|
// assigned to a struct field, so be conservative here and let the symbol
|
|
|
|
// go. TODO: This could definitely be improved upon.
|
|
|
|
escapes = !isa<VarRegion>(regionLoc->getRegion());
|
|
|
|
}
|
2012-12-20 08:38:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If our store can represent the binding and we aren't storing to something
|
|
|
|
// that doesn't have local storage then just return and have the simulation
|
|
|
|
// state continue as is.
|
|
|
|
if (!escapes)
|
|
|
|
return State;
|
|
|
|
|
|
|
|
// Otherwise, find all symbols referenced by 'val' that we are tracking
|
|
|
|
// and stop tracking them.
|
|
|
|
CollectReachableSymbolsCallback Scanner =
|
|
|
|
State->scanReachableSymbols<CollectReachableSymbolsCallback>(Val);
|
|
|
|
const InvalidatedSymbols &EscapedSymbols = Scanner.getSymbols();
|
|
|
|
State = getCheckerManager().runCheckersForPointerEscape(State,
|
|
|
|
EscapedSymbols,
|
2013-02-08 07:05:43 +08:00
|
|
|
/*CallEvent*/ 0,
|
|
|
|
PSK_EscapeOnBind);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramStateRef
|
|
|
|
ExprEngine::processPointerEscapedOnInvalidateRegions(ProgramStateRef State,
|
|
|
|
const InvalidatedSymbols *Invalidated,
|
|
|
|
ArrayRef<const MemRegion *> ExplicitRegions,
|
|
|
|
ArrayRef<const MemRegion *> Regions,
|
|
|
|
const CallEvent *Call) {
|
|
|
|
|
|
|
|
if (!Invalidated || Invalidated->empty())
|
|
|
|
return State;
|
|
|
|
|
|
|
|
if (!Call)
|
|
|
|
return getCheckerManager().runCheckersForPointerEscape(State,
|
2013-02-08 07:05:43 +08:00
|
|
|
*Invalidated,
|
|
|
|
0,
|
|
|
|
PSK_EscapeOther);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
// If the symbols were invalidated by a call, we want to find out which ones
|
|
|
|
// were invalidated directly due to being arguments to the call.
|
|
|
|
InvalidatedSymbols SymbolsDirectlyInvalidated;
|
|
|
|
for (ArrayRef<const MemRegion *>::iterator I = ExplicitRegions.begin(),
|
|
|
|
E = ExplicitRegions.end(); I != E; ++I) {
|
|
|
|
if (const SymbolicRegion *R = (*I)->StripCasts()->getAs<SymbolicRegion>())
|
|
|
|
SymbolsDirectlyInvalidated.insert(R->getSymbol());
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidatedSymbols SymbolsIndirectlyInvalidated;
|
|
|
|
for (InvalidatedSymbols::const_iterator I=Invalidated->begin(),
|
|
|
|
E = Invalidated->end(); I!=E; ++I) {
|
|
|
|
SymbolRef sym = *I;
|
|
|
|
if (SymbolsDirectlyInvalidated.count(sym))
|
|
|
|
continue;
|
|
|
|
SymbolsIndirectlyInvalidated.insert(sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SymbolsDirectlyInvalidated.empty())
|
|
|
|
State = getCheckerManager().runCheckersForPointerEscape(State,
|
2013-02-08 07:05:43 +08:00
|
|
|
SymbolsDirectlyInvalidated, Call, PSK_DirectEscapeOnCall);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
// Notify about the symbols that get indirectly invalidated by the call.
|
|
|
|
if (!SymbolsIndirectlyInvalidated.empty())
|
|
|
|
State = getCheckerManager().runCheckersForPointerEscape(State,
|
2013-02-08 07:05:43 +08:00
|
|
|
SymbolsIndirectlyInvalidated, Call, PSK_IndirectEscapeOnCall);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
2010-12-02 05:57:22 +08:00
|
|
|
/// evalBind - Handle the semantics of binding a value to a specific location.
|
|
|
|
/// This method is used by evalStore and (soon) VisitDeclStmt, and others.
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::evalBind(ExplodedNodeSet &Dst, const Stmt *StoreE,
|
2011-08-28 14:02:28 +08:00
|
|
|
ExplodedNode *Pred,
|
2012-08-22 14:00:18 +08:00
|
|
|
SVal location, SVal Val,
|
2012-08-25 09:06:23 +08:00
|
|
|
bool atDeclInit, const ProgramPoint *PP) {
|
|
|
|
|
|
|
|
const LocationContext *LC = Pred->getLocationContext();
|
|
|
|
PostStmt PS(StoreE, LC);
|
|
|
|
if (!PP)
|
|
|
|
PP = &PS;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2009-11-04 12:24:16 +08:00
|
|
|
// Do a previsit of the bind.
|
2011-08-28 13:54:23 +08:00
|
|
|
ExplodedNodeSet CheckedSet;
|
|
|
|
getCheckerManager().runCheckersForBind(CheckedSet, Pred, location, Val,
|
2012-08-25 09:06:23 +08:00
|
|
|
StoreE, *this, *PP);
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
StmtNodeBuilder Bldr(CheckedSet, Dst, *currBldrCtx);
|
|
|
|
|
2012-08-22 14:00:18 +08:00
|
|
|
// If the location is not a 'Loc', it will already be handled by
|
|
|
|
// the checkers. There is nothing left to do.
|
2013-02-20 13:52:05 +08:00
|
|
|
if (!location.getAs<Loc>()) {
|
2012-12-20 08:38:25 +08:00
|
|
|
const ProgramPoint L = PostStore(StoreE, LC, /*Loc*/0, /*tag*/0);
|
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
state = processPointerEscapedOnBind(state, location, Val);
|
|
|
|
Bldr.generateNode(L, state, Pred);
|
2012-08-22 14:00:18 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-25 02:26:08 +08:00
|
|
|
|
2009-11-04 12:24:16 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
|
|
|
|
I!=E; ++I) {
|
2012-03-22 03:45:08 +08:00
|
|
|
ExplodedNode *PredI = *I;
|
|
|
|
ProgramStateRef state = PredI->getState();
|
2012-08-22 14:00:18 +08:00
|
|
|
|
2012-12-20 08:38:25 +08:00
|
|
|
state = processPointerEscapedOnBind(state, location, Val);
|
|
|
|
|
2012-08-22 14:00:18 +08:00
|
|
|
// When binding the value, pass on the hint that this is a initialization.
|
|
|
|
// For initializations, we do not need to inform clients of region
|
|
|
|
// changes.
|
2013-02-20 13:52:05 +08:00
|
|
|
state = state->bindLoc(location.castAs<Loc>(),
|
2012-08-22 14:00:18 +08:00
|
|
|
Val, /* notifyChanges = */ !atDeclInit);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
2012-03-22 03:45:08 +08:00
|
|
|
const MemRegion *LocReg = 0;
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<loc::MemRegionVal> LocRegVal =
|
2013-02-20 13:52:05 +08:00
|
|
|
location.getAs<loc::MemRegionVal>()) {
|
2012-03-22 03:45:08 +08:00
|
|
|
LocReg = LocRegVal->getRegion();
|
2012-08-22 14:00:18 +08:00
|
|
|
}
|
2012-08-25 09:06:23 +08:00
|
|
|
|
2012-03-22 03:45:08 +08:00
|
|
|
const ProgramPoint L = PostStore(StoreE, LC, LocReg, 0);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(L, state, PredI);
|
2009-11-04 12:24:16 +08:00
|
|
|
}
|
2009-02-13 09:45:31 +08:00
|
|
|
}
|
|
|
|
|
2010-12-02 05:57:22 +08:00
|
|
|
/// evalStore - Handle the semantics of a store via an assignment.
|
2009-02-13 09:45:31 +08:00
|
|
|
/// @param Dst The node set to store generated state nodes
|
2012-06-16 06:32:14 +08:00
|
|
|
/// @param AssignE The assignment expression if the store happens in an
|
2010-09-02 09:56:39 +08:00
|
|
|
/// assignment.
|
2012-06-16 06:32:14 +08:00
|
|
|
/// @param LocationE The location expression that is stored to.
|
2009-02-13 09:45:31 +08:00
|
|
|
/// @param state The current simulation state
|
|
|
|
/// @param location The location to store the value
|
|
|
|
/// @param Val The value to be stored
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::evalStore(ExplodedNodeSet &Dst, const Expr *AssignE,
|
|
|
|
const Expr *LocationE,
|
|
|
|
ExplodedNode *Pred,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state, SVal location, SVal Val,
|
2011-08-13 07:04:46 +08:00
|
|
|
const ProgramPointTag *tag) {
|
2011-01-25 08:04:03 +08:00
|
|
|
// Proceed with the store. We use AssignE as the anchor for the PostStore
|
|
|
|
// ProgramPoint if it is non-NULL, and LocationE otherwise.
|
|
|
|
const Expr *StoreE = AssignE ? AssignE : LocationE;
|
|
|
|
|
2008-04-30 05:04:26 +08:00
|
|
|
// Evaluate the location (checks for bad dereferences).
|
2009-11-11 11:26:34 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2012-04-07 06:10:18 +08:00
|
|
|
evalLocation(Tmp, AssignE, LocationE, Pred, state, location, tag, false);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-11 11:26:34 +08:00
|
|
|
if (Tmp.empty())
|
2008-04-30 05:04:26 +08:00
|
|
|
return;
|
2008-04-19 04:35:30 +08:00
|
|
|
|
2011-02-28 09:27:57 +08:00
|
|
|
if (location.isUndef())
|
|
|
|
return;
|
2009-02-13 09:45:31 +08:00
|
|
|
|
2009-11-11 11:26:34 +08:00
|
|
|
for (ExplodedNodeSet::iterator NI=Tmp.begin(), NE=Tmp.end(); NI!=NE; ++NI)
|
2012-03-22 03:45:08 +08:00
|
|
|
evalBind(Dst, StoreE, *NI, location, Val, false);
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 06:10:18 +08:00
|
|
|
void ExprEngine::evalLoad(ExplodedNodeSet &Dst,
|
|
|
|
const Expr *NodeEx,
|
|
|
|
const Expr *BoundEx,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ProgramStateRef state,
|
|
|
|
SVal location,
|
|
|
|
const ProgramPointTag *tag,
|
|
|
|
QualType LoadTy)
|
|
|
|
{
|
2013-02-20 13:52:05 +08:00
|
|
|
assert(!location.getAs<NonLoc>() && "location cannot be a NonLoc.");
|
2011-01-25 08:04:03 +08:00
|
|
|
|
2012-06-12 08:20:22 +08:00
|
|
|
// Are we loading from a region? This actually results in two loads; one
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
// to fetch the address of the referenced value and one to fetch the
|
|
|
|
// referenced value.
|
2011-08-13 04:02:48 +08:00
|
|
|
if (const TypedValueRegion *TR =
|
|
|
|
dyn_cast_or_null<TypedValueRegion>(location.getAsRegion())) {
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2010-08-11 14:10:55 +08:00
|
|
|
QualType ValTy = TR->getValueType();
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
if (const ReferenceType *RT = ValTy->getAs<ReferenceType>()) {
|
2011-08-13 07:04:46 +08:00
|
|
|
static SimpleProgramPointTag
|
|
|
|
loadReferenceTag("ExprEngine : Load Reference");
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2012-04-07 06:10:18 +08:00
|
|
|
evalLoadCommon(Tmp, NodeEx, BoundEx, Pred, state,
|
|
|
|
location, &loadReferenceTag,
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
getContext().getPointerType(RT->getPointeeType()));
|
|
|
|
|
|
|
|
// Perform the load from the referenced value.
|
|
|
|
for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end() ; I!=E; ++I) {
|
2011-08-11 07:34:53 +08:00
|
|
|
state = (*I)->getState();
|
2012-04-07 06:10:18 +08:00
|
|
|
location = state->getSVal(BoundEx, (*I)->getLocationContext());
|
|
|
|
evalLoadCommon(Dst, NodeEx, BoundEx, *I, state, location, tag, LoadTy);
|
2010-02-16 07:02:46 +08:00
|
|
|
}
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2012-04-07 06:10:18 +08:00
|
|
|
evalLoadCommon(Dst, NodeEx, BoundEx, Pred, state, location, tag, LoadTy);
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 06:10:18 +08:00
|
|
|
void ExprEngine::evalLoadCommon(ExplodedNodeSet &Dst,
|
|
|
|
const Expr *NodeEx,
|
|
|
|
const Expr *BoundEx,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ProgramStateRef state,
|
|
|
|
SVal location,
|
|
|
|
const ProgramPointTag *tag,
|
|
|
|
QualType LoadTy) {
|
|
|
|
assert(NodeEx);
|
|
|
|
assert(BoundEx);
|
2009-09-09 23:08:12 +08:00
|
|
|
// Evaluate the location (checks for bad dereferences).
|
2009-11-11 11:26:34 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2012-04-07 06:10:18 +08:00
|
|
|
evalLocation(Tmp, NodeEx, BoundEx, Pred, state, location, tag, true);
|
2009-11-11 11:26:34 +08:00
|
|
|
if (Tmp.empty())
|
2008-04-30 05:04:26 +08:00
|
|
|
return;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Tmp, Dst, *currBldrCtx);
|
2011-02-28 09:27:57 +08:00
|
|
|
if (location.isUndef())
|
|
|
|
return;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2008-04-30 05:04:26 +08:00
|
|
|
// Proceed with the load.
|
2009-11-11 11:26:34 +08:00
|
|
|
for (ExplodedNodeSet::iterator NI=Tmp.begin(), NE=Tmp.end(); NI!=NE; ++NI) {
|
2011-08-11 07:34:53 +08:00
|
|
|
state = (*NI)->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx = (*NI)->getLocationContext();
|
2010-09-09 15:13:00 +08:00
|
|
|
|
2012-12-07 02:58:01 +08:00
|
|
|
SVal V = UnknownVal();
|
|
|
|
if (location.isValid()) {
|
2010-09-09 15:13:00 +08:00
|
|
|
if (LoadTy.isNull())
|
2012-04-07 06:10:18 +08:00
|
|
|
LoadTy = BoundEx->getType();
|
2013-02-20 13:52:05 +08:00
|
|
|
V = state->getSVal(location.castAs<Loc>(), LoadTy);
|
2009-11-11 11:26:34 +08:00
|
|
|
}
|
2012-12-07 02:58:01 +08:00
|
|
|
|
|
|
|
Bldr.generateNode(NodeEx, *NI, state->BindExpr(BoundEx, LCtx, V), tag,
|
|
|
|
ProgramPoint::PostLoadKind);
|
2008-11-28 16:34:30 +08:00
|
|
|
}
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
|
|
|
|
2012-04-07 06:10:18 +08:00
|
|
|
void ExprEngine::evalLocation(ExplodedNodeSet &Dst,
|
|
|
|
const Stmt *NodeEx,
|
|
|
|
const Stmt *BoundEx,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ProgramStateRef state,
|
|
|
|
SVal location,
|
|
|
|
const ProgramPointTag *tag,
|
|
|
|
bool isLoad) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder BldrTop(Pred, Dst, *currBldrCtx);
|
2009-11-20 11:50:46 +08:00
|
|
|
// Early checks for performance reason.
|
2011-02-23 01:30:38 +08:00
|
|
|
if (location.isUnknown()) {
|
2009-11-11 11:26:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2011-02-24 16:42:04 +08:00
|
|
|
ExplodedNodeSet Src;
|
2011-10-25 02:26:19 +08:00
|
|
|
BldrTop.takeNodes(Pred);
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Src, *currBldrCtx);
|
2011-10-25 02:26:19 +08:00
|
|
|
if (Pred->getState() != state) {
|
2011-03-01 09:16:03 +08:00
|
|
|
// Associate this new state with an ExplodedNode.
|
|
|
|
// FIXME: If I pass null tag, the graph is incorrect, e.g for
|
|
|
|
// int *p;
|
|
|
|
// p = 0;
|
|
|
|
// *p = 0xDEADBEEF;
|
|
|
|
// "p = 0" is not noted as "Null pointer value stored to 'p'" but
|
|
|
|
// instead "int *p" is noted as
|
|
|
|
// "Variable 'p' initialized to a null pointer value"
|
2011-08-13 07:04:46 +08:00
|
|
|
|
2012-08-21 02:43:42 +08:00
|
|
|
static SimpleProgramPointTag tag("ExprEngine: Location");
|
|
|
|
Bldr.generateNode(NodeEx, Pred, state, &tag);
|
2009-11-03 07:19:29 +08:00
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2012-04-07 06:10:18 +08:00
|
|
|
getCheckerManager().runCheckersForLocation(Tmp, Src, location, isLoad,
|
|
|
|
NodeEx, BoundEx, *this);
|
2011-10-25 02:26:19 +08:00
|
|
|
BldrTop.addNodes(Tmp);
|
2008-04-17 02:39:06 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 09:53:39 +08:00
|
|
|
std::pair<const ProgramPointTag *, const ProgramPointTag*>
|
2012-08-31 03:26:48 +08:00
|
|
|
ExprEngine::geteagerlyAssumeBinOpBifurcationTags() {
|
2011-08-16 09:53:39 +08:00
|
|
|
static SimpleProgramPointTag
|
2012-08-31 03:26:48 +08:00
|
|
|
eagerlyAssumeBinOpBifurcationTrue("ExprEngine : Eagerly Assume True"),
|
|
|
|
eagerlyAssumeBinOpBifurcationFalse("ExprEngine : Eagerly Assume False");
|
|
|
|
return std::make_pair(&eagerlyAssumeBinOpBifurcationTrue,
|
|
|
|
&eagerlyAssumeBinOpBifurcationFalse);
|
2011-08-16 09:53:39 +08:00
|
|
|
}
|
|
|
|
|
2012-08-31 03:26:48 +08:00
|
|
|
void ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst,
|
|
|
|
ExplodedNodeSet &Src,
|
|
|
|
const Expr *Ex) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Src, Dst, *currBldrCtx);
|
2011-08-16 08:49:19 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
for (ExplodedNodeSet::iterator I=Src.begin(), E=Src.end(); I!=E; ++I) {
|
|
|
|
ExplodedNode *Pred = *I;
|
2009-02-26 07:32:10 +08:00
|
|
|
// Test if the previous node was as the same expression. This can happen
|
|
|
|
// when the expression fails to evaluate to anything meaningful and
|
|
|
|
// (as an optimization) we don't generate a node.
|
2009-09-09 23:08:12 +08:00
|
|
|
ProgramPoint P = Pred->getLocation();
|
2013-02-22 06:23:56 +08:00
|
|
|
if (!P.getAs<PostStmt>() || P.castAs<PostStmt>().getStmt() != Ex) {
|
2009-02-26 07:32:10 +08:00
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-02-26 07:32:10 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal V = state->getSVal(Ex, Pred->getLocationContext());
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<nonloc::SymbolVal> SEV = V.getAs<nonloc::SymbolVal>();
|
2011-12-06 02:58:30 +08:00
|
|
|
if (SEV && SEV->isExpression()) {
|
2011-08-16 09:53:39 +08:00
|
|
|
const std::pair<const ProgramPointTag *, const ProgramPointTag*> &tags =
|
2012-08-31 03:26:48 +08:00
|
|
|
geteagerlyAssumeBinOpBifurcationTags();
|
2011-08-16 09:53:39 +08:00
|
|
|
|
2012-12-07 02:58:09 +08:00
|
|
|
ProgramStateRef StateTrue, StateFalse;
|
|
|
|
tie(StateTrue, StateFalse) = state->assume(*SEV);
|
|
|
|
|
2009-02-26 06:32:02 +08:00
|
|
|
// First assume that the condition is true.
|
2012-12-07 02:58:09 +08:00
|
|
|
if (StateTrue) {
|
2011-08-16 08:49:19 +08:00
|
|
|
SVal Val = svalBuilder.makeIntVal(1U, Ex->getType());
|
2012-01-07 06:09:28 +08:00
|
|
|
StateTrue = StateTrue->BindExpr(Ex, Pred->getLocationContext(), Val);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, StateTrue, tags.first);
|
2009-02-26 06:32:02 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-26 06:32:02 +08:00
|
|
|
// Next, assume that the condition is false.
|
2012-12-07 02:58:09 +08:00
|
|
|
if (StateFalse) {
|
2011-08-16 08:49:19 +08:00
|
|
|
SVal Val = svalBuilder.makeIntVal(0U, Ex->getType());
|
2012-01-07 06:09:28 +08:00
|
|
|
StateFalse = StateFalse->BindExpr(Ex, Pred->getLocationContext(), Val);
|
2012-08-21 02:43:42 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, StateFalse, tags.second);
|
2009-02-26 06:32:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
void ExprEngine::VisitGCCAsmStmt(const GCCAsmStmt *A, ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-03-05 02:12:21 +08:00
|
|
|
// We have processed both the inputs and the outputs. All of the outputs
|
|
|
|
// should evaluate to Locs. Nuke all of their values.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-05 02:12:21 +08:00
|
|
|
// FIXME: Some day in the future it would be nice to allow a "plug-in"
|
|
|
|
// which interprets the inline asm and stores proper results in the
|
|
|
|
// outputs.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-05 02:12:21 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-08-25 08:11:56 +08:00
|
|
|
for (GCCAsmStmt::const_outputs_iterator OI = A->begin_outputs(),
|
2012-03-05 02:12:21 +08:00
|
|
|
OE = A->end_outputs(); OI != OE; ++OI) {
|
|
|
|
SVal X = state->getSVal(*OI, Pred->getLocationContext());
|
2013-02-20 13:52:05 +08:00
|
|
|
assert (!X.getAs<NonLoc>()); // Should be an Lval, or unknown, undef.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<Loc> LV = X.getAs<Loc>())
|
2013-02-20 13:52:05 +08:00
|
|
|
state = state->bindLoc(*LV, UnknownVal());
|
2008-03-18 05:11:24 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-05 02:12:21 +08:00
|
|
|
Bldr.generateNode(A, Pred, state);
|
2008-03-18 05:11:24 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 04:47:18 +08:00
|
|
|
void ExprEngine::VisitMSAsmStmt(const MSAsmStmt *A, ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-08-22 14:26:15 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
2012-06-12 04:47:18 +08:00
|
|
|
Bldr.generateNode(A, Pred, Pred->getState());
|
|
|
|
}
|
|
|
|
|
2008-07-18 05:27:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-15 06:36:46 +08:00
|
|
|
// Visualization.
|
2008-01-17 02:18:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
#ifndef NDEBUG
|
2010-12-23 02:53:44 +08:00
|
|
|
static ExprEngine* GraphPrintCheckerState;
|
2008-03-08 04:57:30 +08:00
|
|
|
static SourceManager* GraphPrintSourceManager;
|
2008-01-31 07:24:39 +08:00
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
namespace llvm {
|
|
|
|
template<>
|
2009-12-01 00:08:24 +08:00
|
|
|
struct DOTGraphTraits<ExplodedNode*> :
|
2008-01-17 05:46:15 +08:00
|
|
|
public DefaultDOTGraphTraits {
|
2009-11-30 22:16:05 +08:00
|
|
|
|
|
|
|
DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
// FIXME: Since we do not cache error nodes in ExprEngine now, this does not
|
2009-10-29 10:09:30 +08:00
|
|
|
// work.
|
2011-08-13 07:37:29 +08:00
|
|
|
static std::string getNodeAttributes(const ExplodedNode *N, void*) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 04:16:36 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to tell if the node is
|
|
|
|
// an error node.
|
2008-02-15 06:54:53 +08:00
|
|
|
if (GraphPrintCheckerState->isImplicitNullDeref(N) ||
|
2008-02-19 08:22:37 +08:00
|
|
|
GraphPrintCheckerState->isExplicitNullDeref(N) ||
|
2008-02-28 17:25:22 +08:00
|
|
|
GraphPrintCheckerState->isUndefDeref(N) ||
|
|
|
|
GraphPrintCheckerState->isUndefStore(N) ||
|
|
|
|
GraphPrintCheckerState->isUndefControlFlow(N) ||
|
2008-03-01 07:14:48 +08:00
|
|
|
GraphPrintCheckerState->isUndefResult(N) ||
|
2008-03-01 07:53:11 +08:00
|
|
|
GraphPrintCheckerState->isBadCall(N) ||
|
|
|
|
GraphPrintCheckerState->isUndefArg(N))
|
2008-02-15 06:54:53 +08:00
|
|
|
return "color=\"red\",style=\"filled\"";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-29 04:32:03 +08:00
|
|
|
if (GraphPrintCheckerState->isNoReturnCall(N))
|
|
|
|
return "color=\"blue\",style=\"filled\"";
|
2009-11-24 15:06:39 +08:00
|
|
|
#endif
|
2008-02-15 06:54:53 +08:00
|
|
|
return "";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
static void printLocation(raw_ostream &Out, SourceLocation SLoc) {
|
2012-07-11 06:07:42 +08:00
|
|
|
if (SLoc.isFileID()) {
|
|
|
|
Out << "\\lline="
|
|
|
|
<< GraphPrintSourceManager->getExpansionLineNumber(SLoc)
|
|
|
|
<< " col="
|
|
|
|
<< GraphPrintSourceManager->getExpansionColumnNumber(SLoc)
|
|
|
|
<< "\\l";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
static std::string getNodeLabel(const ExplodedNode *N, void*){
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-25 07:06:47 +08:00
|
|
|
std::string sbuf;
|
|
|
|
llvm::raw_string_ostream Out(sbuf);
|
2008-01-24 06:30:44 +08:00
|
|
|
|
|
|
|
// Program Location.
|
2008-01-17 05:46:15 +08:00
|
|
|
ProgramPoint Loc = N->getLocation();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
switch (Loc.getKind()) {
|
2012-04-21 05:59:08 +08:00
|
|
|
case ProgramPoint::BlockEntranceKind: {
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "Block Entrance: B"
|
2013-02-22 06:23:56 +08:00
|
|
|
<< Loc.castAs<BlockEntrance>().getBlock()->getBlockID();
|
2012-04-21 05:59:08 +08:00
|
|
|
if (const NamedDecl *ND =
|
|
|
|
dyn_cast<NamedDecl>(Loc.getLocationContext()->getDecl())) {
|
|
|
|
Out << " (";
|
|
|
|
ND->printName(Out);
|
|
|
|
Out << ")";
|
|
|
|
}
|
2008-01-17 05:46:15 +08:00
|
|
|
break;
|
2012-04-21 05:59:08 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
case ProgramPoint::BlockExitKind:
|
|
|
|
assert (false);
|
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-02-26 03:01:53 +08:00
|
|
|
case ProgramPoint::CallEnterKind:
|
|
|
|
Out << "CallEnter";
|
|
|
|
break;
|
|
|
|
|
2012-04-21 05:59:08 +08:00
|
|
|
case ProgramPoint::CallExitBeginKind:
|
|
|
|
Out << "CallExitBegin";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::CallExitEndKind:
|
|
|
|
Out << "CallExitEnd";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
|
|
|
|
Out << "PostStmtPurgeDeadSymbols";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
|
|
|
|
Out << "PreStmtPurgeDeadSymbols";
|
2010-02-26 03:01:53 +08:00
|
|
|
break;
|
|
|
|
|
2012-03-28 04:02:53 +08:00
|
|
|
case ProgramPoint::EpsilonKind:
|
|
|
|
Out << "Epsilon Point";
|
|
|
|
break;
|
|
|
|
|
2012-07-11 06:07:42 +08:00
|
|
|
case ProgramPoint::PreImplicitCallKind: {
|
2013-02-22 06:23:56 +08:00
|
|
|
ImplicitCallPoint PC = Loc.castAs<ImplicitCallPoint>();
|
2012-07-11 06:07:42 +08:00
|
|
|
Out << "PreCall: ";
|
|
|
|
|
|
|
|
// FIXME: Get proper printing options.
|
2013-02-22 06:23:56 +08:00
|
|
|
PC.getDecl()->print(Out, LangOptions());
|
|
|
|
printLocation(Out, PC.getLocation());
|
2012-07-11 06:07:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ProgramPoint::PostImplicitCallKind: {
|
2013-02-22 06:23:56 +08:00
|
|
|
ImplicitCallPoint PC = Loc.castAs<ImplicitCallPoint>();
|
2012-07-11 06:07:42 +08:00
|
|
|
Out << "PostCall: ";
|
|
|
|
|
|
|
|
// FIXME: Get proper printing options.
|
2013-02-22 06:23:56 +08:00
|
|
|
PC.getDecl()->print(Out, LangOptions());
|
|
|
|
printLocation(Out, PC.getLocation());
|
2012-07-11 06:07:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
default: {
|
2013-02-22 06:23:56 +08:00
|
|
|
if (Optional<StmtPoint> L = Loc.getAs<StmtPoint>()) {
|
2011-08-13 07:37:29 +08:00
|
|
|
const Stmt *S = L->getStmt();
|
2008-12-17 06:02:27 +08:00
|
|
|
|
2012-09-06 23:59:27 +08:00
|
|
|
Out << S->getStmtClassName() << ' ' << (const void*) S << ' ';
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
S->printPretty(Out, 0, PrintingPolicy(LO));
|
2012-07-11 06:07:42 +08:00
|
|
|
printLocation(Out, S->getLocStart());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-02-22 06:23:56 +08:00
|
|
|
if (Loc.getAs<PreStmt>())
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "\\lPreStmt\\l;";
|
2013-02-22 06:23:56 +08:00
|
|
|
else if (Loc.getAs<PostLoad>())
|
2009-05-08 02:27:16 +08:00
|
|
|
Out << "\\lPostLoad\\l;";
|
2013-02-22 06:23:56 +08:00
|
|
|
else if (Loc.getAs<PostStore>())
|
2009-05-08 02:27:16 +08:00
|
|
|
Out << "\\lPostStore\\l";
|
2013-02-22 06:23:56 +08:00
|
|
|
else if (Loc.getAs<PostLValue>())
|
2009-05-08 02:27:16 +08:00
|
|
|
Out << "\\lPostLValue\\l";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 04:16:36 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to determine
|
|
|
|
// the name of the check.
|
2008-12-17 06:02:27 +08:00
|
|
|
if (GraphPrintCheckerState->isImplicitNullDeref(N))
|
|
|
|
Out << "\\|Implicit-Null Dereference.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isExplicitNullDeref(N))
|
|
|
|
Out << "\\|Explicit-Null Dereference.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isUndefDeref(N))
|
|
|
|
Out << "\\|Dereference of undefialied value.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isUndefStore(N))
|
|
|
|
Out << "\\|Store to Undefined Loc.";
|
|
|
|
else if (GraphPrintCheckerState->isUndefResult(N))
|
|
|
|
Out << "\\|Result of operation is undefined.";
|
|
|
|
else if (GraphPrintCheckerState->isNoReturnCall(N))
|
|
|
|
Out << "\\|Call to function marked \"noreturn\".";
|
|
|
|
else if (GraphPrintCheckerState->isBadCall(N))
|
|
|
|
Out << "\\|Call to NULL/Undefined.";
|
|
|
|
else if (GraphPrintCheckerState->isUndefArg(N))
|
|
|
|
Out << "\\|Argument in call is undefined";
|
2009-11-12 04:16:36 +08:00
|
|
|
#endif
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-17 06:02:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-22 06:23:56 +08:00
|
|
|
const BlockEdge &E = Loc.castAs<BlockEdge>();
|
2008-01-17 05:46:15 +08:00
|
|
|
Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B"
|
|
|
|
<< E.getDst()->getBlockID() << ')';
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const Stmt *T = E.getSrc()->getTerminator()) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 04:57:30 +08:00
|
|
|
SourceLocation SLoc = T->getLocStart();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
Out << "\\|Terminator: ";
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
E.getSrc()->printTerminator(Out, LO);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 11:30:59 +08:00
|
|
|
if (SLoc.isFileID()) {
|
|
|
|
Out << "\\lline="
|
2011-07-26 05:09:52 +08:00
|
|
|
<< GraphPrintSourceManager->getExpansionLineNumber(SLoc)
|
2009-02-04 08:55:58 +08:00
|
|
|
<< " col="
|
2011-07-26 04:57:57 +08:00
|
|
|
<< GraphPrintSourceManager->getExpansionColumnNumber(SLoc);
|
2008-03-09 11:30:59 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
if (isa<SwitchStmt>(T)) {
|
2011-08-13 07:37:29 +08:00
|
|
|
const Stmt *Label = E.getDst()->getLabel();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
if (Label) {
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const CaseStmt *C = dyn_cast<CaseStmt>(Label)) {
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << "\\lcase ";
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
C->getLHS()->printPretty(Out, 0, PrintingPolicy(LO));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const Stmt *RHS = C->getRHS()) {
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << " .. ";
|
2009-06-30 09:26:17 +08:00
|
|
|
RHS->printPretty(Out, 0, PrintingPolicy(LO));
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << ":";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (isa<DefaultStmt>(Label));
|
|
|
|
Out << "\\ldefault:";
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
else
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << "\\l(implicit) default:";
|
|
|
|
}
|
|
|
|
else if (isa<IndirectGotoStmt>(T)) {
|
2008-01-31 07:03:39 +08:00
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Out << "\\lCondition: ";
|
|
|
|
if (*E.getSrc()->succ_begin() == E.getDst())
|
|
|
|
Out << "true";
|
|
|
|
else
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "false";
|
2008-01-31 07:03:39 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
Out << "\\l";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 04:16:36 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to determine
|
|
|
|
// the name of the check.
|
2008-02-28 17:25:22 +08:00
|
|
|
if (GraphPrintCheckerState->isUndefControlFlow(N)) {
|
|
|
|
Out << "\\|Control-flow based on\\lUndefined value.\\l";
|
2008-01-31 07:24:39 +08:00
|
|
|
}
|
2009-11-12 04:16:36 +08:00
|
|
|
#endif
|
2008-01-17 05:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = N->getState();
|
2012-09-06 23:59:27 +08:00
|
|
|
Out << "\\|StateID: " << (const void*) state.getPtr()
|
|
|
|
<< " NodeID: " << (const void*) N << "\\|";
|
2012-01-07 06:09:28 +08:00
|
|
|
state->printDOT(Out);
|
2011-08-13 07:04:46 +08:00
|
|
|
|
|
|
|
Out << "\\l";
|
|
|
|
|
|
|
|
if (const ProgramPointTag *tag = Loc.getTag()) {
|
|
|
|
Out << "\\|Tag: " << tag->getTagDescription();
|
|
|
|
Out << "\\l";
|
|
|
|
}
|
2008-01-17 05:46:15 +08:00
|
|
|
return Out.str();
|
|
|
|
}
|
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
} // end llvm namespace
|
2008-01-17 05:46:15 +08:00
|
|
|
#endif
|
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-13 01:18:20 +08:00
|
|
|
template <typename ITERATOR>
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *GetGraphNode(ITERATOR I) { return *I; }
|
2008-03-13 01:18:20 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
template <> ExplodedNode*
|
|
|
|
GetGraphNode<llvm::DenseMap<ExplodedNode*, Expr*>::iterator>
|
|
|
|
(llvm::DenseMap<ExplodedNode*, Expr*>::iterator I) {
|
2008-03-13 01:18:20 +08:00
|
|
|
return I->first;
|
|
|
|
}
|
2008-03-08 06:58:01 +08:00
|
|
|
#endif
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ViewGraph(bool trim) {
|
2009-09-09 23:08:12 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-08 06:58:01 +08:00
|
|
|
if (trim) {
|
2009-08-06 20:48:26 +08:00
|
|
|
std::vector<ExplodedNode*> Src;
|
2009-03-11 09:41:22 +08:00
|
|
|
|
|
|
|
// Flush any outstanding reports to make sure we cover all the nodes.
|
|
|
|
// This does not cause them to get displayed.
|
|
|
|
for (BugReporter::iterator I=BR.begin(), E=BR.end(); I!=E; ++I)
|
|
|
|
const_cast<BugType*>(*I)->FlushReports(BR);
|
|
|
|
|
|
|
|
// Iterate through the reports and get their nodes.
|
2011-02-23 08:16:01 +08:00
|
|
|
for (BugReporter::EQClasses_iterator
|
|
|
|
EI = BR.EQClasses_begin(), EE = BR.EQClasses_end(); EI != EE; ++EI) {
|
2012-04-02 03:30:51 +08:00
|
|
|
ExplodedNode *N = const_cast<ExplodedNode*>(EI->begin()->getErrorNode());
|
2011-02-23 08:16:01 +08:00
|
|
|
if (N) Src.push_back(N);
|
2009-03-11 09:41:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-13 01:18:20 +08:00
|
|
|
ViewGraph(&Src[0], &Src[0]+Src.size());
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
2008-03-12 02:25:33 +08:00
|
|
|
else {
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2008-08-14 05:24:49 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
llvm::ViewGraph(*G.roots_begin(), "ExprEngine");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-12 02:25:33 +08:00
|
|
|
GraphPrintCheckerState = NULL;
|
|
|
|
GraphPrintSourceManager = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ViewGraph(ExplodedNode** Beg, ExplodedNode** End) {
|
2008-03-12 02:25:33 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
std::auto_ptr<ExplodedGraph> TrimmedG(G.Trim(Beg, End).first);
|
2008-03-12 02:25:33 +08:00
|
|
|
|
2009-02-05 07:49:09 +08:00
|
|
|
if (!TrimmedG.get())
|
2009-08-23 20:08:50 +08:00
|
|
|
llvm::errs() << "warning: Trimmed ExplodedGraph is empty.\n";
|
2009-02-05 07:49:09 +08:00
|
|
|
else
|
2010-12-23 02:53:44 +08:00
|
|
|
llvm::ViewGraph(*TrimmedG->roots_begin(), "TrimmedExprEngine");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:24:39 +08:00
|
|
|
GraphPrintCheckerState = NULL;
|
2008-03-08 04:57:30 +08:00
|
|
|
GraphPrintSourceManager = NULL;
|
2008-02-15 06:36:46 +08:00
|
|
|
#endif
|
2008-01-17 02:18:48 +08:00
|
|
|
}
|