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
|
|
|
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2013-07-19 08:59:08 +08:00
|
|
|
#include "PrettyStackTraceLocationContext.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
|
|
|
|
2014-04-22 11:17:02 +08:00
|
|
|
#define DEBUG_TYPE "ExprEngine"
|
|
|
|
|
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");
|
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
typedef std::pair<const CXXBindTemporaryExpr *, const StackFrameContext *>
|
|
|
|
CXXBindTemporaryContext;
|
|
|
|
|
|
|
|
// Keeps track of whether CXXBindTemporaryExpr nodes have been evaluated.
|
|
|
|
// The StackFrameContext assures that nested calls due to inlined recursive
|
|
|
|
// functions do not interfere.
|
|
|
|
REGISTER_TRAIT_WITH_PROGRAMSTATE(InitializedTemporariesSet,
|
|
|
|
llvm::ImmutableSet<CXXBindTemporaryContext>)
|
|
|
|
|
2008-07-12 02:37:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Engine construction and deletion.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-02-18 02:25:34 +08:00
|
|
|
static const char* TagProviderName = "ExprEngine";
|
|
|
|
|
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()),
|
2014-05-27 10:45:47 +08:00
|
|
|
currStmtIdx(0), currBldrCtx(nullptr),
|
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();
|
2013-04-09 10:30:33 +08:00
|
|
|
const BuiltinType *BT = dyn_cast<BuiltinType>(T);
|
|
|
|
if (!BT || !BT->isInteger())
|
2009-12-18 03:17:27 +08:00
|
|
|
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),
|
2013-12-20 06:32:39 +08:00
|
|
|
svalBuilder.getConditionType());
|
2009-12-18 03:17:27 +08:00
|
|
|
|
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();
|
2014-05-27 10:45:47 +08:00
|
|
|
if (SFC->getParent() == nullptr) {
|
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-04-04 05:16:58 +08:00
|
|
|
if (!Result) {
|
|
|
|
// If we don't have an explicit result expression, we're in "if needed"
|
|
|
|
// mode. Only create a region if the current value is a NonLoc.
|
|
|
|
if (!V.getAs<NonLoc>())
|
|
|
|
return State;
|
|
|
|
Result = Ex;
|
|
|
|
} else {
|
|
|
|
// We need to create a region no matter what. For sanity, make sure we don't
|
|
|
|
// try to stuff a Loc into a non-pointer temporary region.
|
2013-04-16 06:03:38 +08:00
|
|
|
assert(!V.getAs<Loc>() || Loc::isLocType(Result->getType()) ||
|
|
|
|
Result->getType()->isMemberPointerType());
|
2013-04-04 05:16:58 +08:00
|
|
|
}
|
2013-02-22 09:51:15 +08:00
|
|
|
|
|
|
|
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
|
2013-04-04 05:16:58 +08:00
|
|
|
// bindings for a base type. Unless we're creating a temporary pointer region,
|
|
|
|
// start by stripping and recording base casts.
|
2013-02-22 09:51:15 +08:00
|
|
|
SmallVector<const CastExpr *, 4> Casts;
|
|
|
|
const Expr *Inner = Ex->IgnoreParens();
|
2013-04-04 05:16:58 +08:00
|
|
|
if (!Loc::isLocType(Result->getType())) {
|
2013-02-26 09:21:27 +08:00
|
|
|
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;
|
2013-02-22 09:51:15 +08:00
|
|
|
|
2013-02-26 09:21:27 +08:00
|
|
|
Inner = CE->getSubExpr()->IgnoreParens();
|
|
|
|
}
|
2013-02-22 09:51:15 +08:00
|
|
|
}
|
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
|
2013-04-04 05:16:58 +08:00
|
|
|
// a more derived type) and bind the value into it.
|
2014-05-27 10:45:47 +08:00
|
|
|
const TypedValueRegion *TR = nullptr;
|
2013-07-26 19:50:42 +08:00
|
|
|
if (const MaterializeTemporaryExpr *MT =
|
|
|
|
dyn_cast<MaterializeTemporaryExpr>(Result)) {
|
|
|
|
StorageDuration SD = MT->getStorageDuration();
|
|
|
|
// If this object is bound to a reference with static storage duration, we
|
|
|
|
// put it in a different region to prevent "address leakage" warnings.
|
|
|
|
if (SD == SD_Static || SD == SD_Thread)
|
|
|
|
TR = MRMgr.getCXXStaticTempObjectRegion(Inner);
|
|
|
|
}
|
|
|
|
if (!TR)
|
|
|
|
TR = MRMgr.getCXXTempObjectRegion(Inner, LC);
|
|
|
|
|
2013-04-04 05:16:58 +08:00
|
|
|
SVal Reg = loc::MemRegionVal(TR);
|
|
|
|
|
|
|
|
if (V.isUnknown())
|
|
|
|
V = getSValBuilder().conjureSymbolVal(Result, LC, TR->getValueType(),
|
|
|
|
currBldrCtx->blockCount());
|
2013-02-22 09:51:15 +08:00
|
|
|
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-04-04 05:16:58 +08:00
|
|
|
State = State->BindExpr(Result, 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) {
|
2013-07-19 08:59:08 +08:00
|
|
|
PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
|
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;
|
2014-01-14 01:59:19 +08:00
|
|
|
case CFGElement::NewAllocator:
|
|
|
|
ProcessNewAllocator(E.castAs<CFGNewAllocator>().getAllocatorExpr(),
|
|
|
|
Pred);
|
|
|
|
return;
|
2011-03-01 11:15:10 +08:00
|
|
|
case CFGElement::AutomaticObjectDtor:
|
2013-09-04 01:00:57 +08:00
|
|
|
case CFGElement::DeleteDtor:
|
2011-03-01 11:15:10 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 ||
|
2014-05-27 10:45:47 +08:00
|
|
|
ReferenceStmt == nullptr || 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();
|
|
|
|
}
|
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
const StackFrameContext *SFC = LC ? LC->getCurrentStackFrame() : nullptr;
|
2012-11-16 03:11:27 +08:00
|
|
|
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.
|
2014-02-18 02:25:34 +08:00
|
|
|
static SimpleProgramPointTag cleanupTag(TagProviderName, "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
|
|
|
ExplodedNodeSet Tmp(Pred);
|
2013-04-05 08:59:33 +08:00
|
|
|
SVal FieldLoc;
|
2012-08-25 09:06:23 +08:00
|
|
|
|
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)) {
|
2013-04-03 09:39:08 +08:00
|
|
|
const ValueDecl *Field;
|
|
|
|
if (BMI->isIndirectMemberInitializer()) {
|
|
|
|
Field = BMI->getIndirectMember();
|
2012-07-27 04:04:21 +08:00
|
|
|
FieldLoc = State->getLValue(BMI->getIndirectMember(), thisVal);
|
2013-04-03 09:39:08 +08:00
|
|
|
} else {
|
|
|
|
Field = BMI->getMember();
|
2012-07-27 04:04:21 +08:00
|
|
|
FieldLoc = State->getLValue(BMI->getMember(), thisVal);
|
2013-04-03 09:39:08 +08:00
|
|
|
}
|
2012-07-27 04:04:21 +08:00
|
|
|
|
2013-04-03 09:39:08 +08:00
|
|
|
SVal InitVal;
|
|
|
|
if (BMI->getNumArrayIndices() > 0) {
|
|
|
|
// Handle arrays of trivial type. We can represent this with a
|
|
|
|
// primitive load/copy from the base array region.
|
|
|
|
const ArraySubscriptExpr *ASE;
|
|
|
|
while ((ASE = dyn_cast<ArraySubscriptExpr>(Init)))
|
|
|
|
Init = ASE->getBase()->IgnoreImplicit();
|
|
|
|
|
|
|
|
SVal LValue = State->getSVal(Init, stackFrame);
|
|
|
|
if (Optional<Loc> LValueLoc = LValue.getAs<Loc>())
|
|
|
|
InitVal = State->getSVal(*LValueLoc);
|
|
|
|
|
|
|
|
// If we fail to get the value for some reason, use a symbolic value.
|
|
|
|
if (InitVal.isUnknownOrUndef()) {
|
|
|
|
SValBuilder &SVB = getSValBuilder();
|
|
|
|
InitVal = SVB.conjureSymbolVal(BMI->getInit(), stackFrame,
|
|
|
|
Field->getType(),
|
|
|
|
currBldrCtx->blockCount());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
InitVal = State->getSVal(BMI->getInit(), stackFrame);
|
|
|
|
}
|
2012-08-25 09:06:23 +08:00
|
|
|
|
2013-04-03 09:39:08 +08:00
|
|
|
assert(Tmp.size() == 1 && "have not generated any new nodes yet");
|
|
|
|
assert(*Tmp.begin() == Pred && "have not generated any new nodes yet");
|
2012-08-25 09:06:23 +08:00
|
|
|
Tmp.clear();
|
2013-04-05 08:59:33 +08:00
|
|
|
|
|
|
|
PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
|
2012-08-25 09:06:23 +08:00
|
|
|
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.
|
2013-04-05 08:59:33 +08:00
|
|
|
PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame);
|
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;
|
2013-09-04 01:00:57 +08:00
|
|
|
case CFGElement::DeleteDtor:
|
|
|
|
ProcessDeleteDtor(D.castAs<CFGDeleteDtor>(), Pred, Dst);
|
|
|
|
break;
|
2010-11-17 17:16:19 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-14 01:59:19 +08:00
|
|
|
void ExprEngine::ProcessNewAllocator(const CXXNewExpr *NE,
|
|
|
|
ExplodedNode *Pred) {
|
|
|
|
ExplodedNodeSet Dst;
|
2014-02-11 10:21:06 +08:00
|
|
|
AnalysisManager &AMgr = getAnalysisManager();
|
|
|
|
AnalyzerOptions &Opts = AMgr.options;
|
|
|
|
// TODO: We're not evaluating allocators for all cases just yet as
|
|
|
|
// we're not handling the return value correctly, which causes false
|
|
|
|
// positives when the alpha.cplusplus.NewDeleteLeaks check is on.
|
|
|
|
if (Opts.mayInlineCXXAllocator())
|
|
|
|
VisitCXXNewAllocatorCall(NE, Pred, Dst);
|
|
|
|
else {
|
|
|
|
NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
PostImplicitCall PP(NE->getOperatorNew(), NE->getLocStart(), LCtx);
|
|
|
|
Bldr.generateNode(PP, Pred->getState(), Pred);
|
|
|
|
}
|
2014-01-14 01:59:19 +08:00
|
|
|
Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
|
|
|
|
}
|
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
|
|
|
const VarDecl *varDecl = Dtor.getVarDecl();
|
2010-11-25 14:35:14 +08:00
|
|
|
QualType varType = varDecl->getType();
|
|
|
|
|
2013-04-04 05:16:58 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
SVal dest = state->getLValue(varDecl, Pred->getLocationContext());
|
|
|
|
const MemRegion *Region = dest.castAs<loc::MemRegionVal>().getRegion();
|
2010-11-25 14:35:14 +08:00
|
|
|
|
2013-04-04 05:16:58 +08:00
|
|
|
if (const ReferenceType *refType = varType->getAs<ReferenceType>()) {
|
|
|
|
varType = refType->getPointeeType();
|
|
|
|
Region = state->getSVal(Region).getAsRegion();
|
|
|
|
}
|
2010-11-20 14:53:12 +08:00
|
|
|
|
2013-04-04 05:16:58 +08:00
|
|
|
VisitCXXDestructor(varType, Region, Dtor.getTriggerStmt(), /*IsBase=*/ false,
|
|
|
|
Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
}
|
|
|
|
|
2013-09-04 01:00:57 +08:00
|
|
|
void ExprEngine::ProcessDeleteDtor(const CFGDeleteDtor Dtor,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2013-09-26 00:06:17 +08:00
|
|
|
ProgramStateRef State = Pred->getState();
|
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
const CXXDeleteExpr *DE = Dtor.getDeleteExpr();
|
|
|
|
const Stmt *Arg = DE->getArgument();
|
|
|
|
SVal ArgVal = State->getSVal(Arg, LCtx);
|
|
|
|
|
|
|
|
// If the argument to delete is known to be a null value,
|
|
|
|
// don't run destructor.
|
|
|
|
if (State->isNull(ArgVal).isConstrainedTrue()) {
|
|
|
|
QualType DTy = DE->getDestroyedType();
|
|
|
|
QualType BTy = getContext().getBaseElementType(DTy);
|
|
|
|
const CXXRecordDecl *RD = BTy->getAsCXXRecordDecl();
|
|
|
|
const CXXDestructorDecl *Dtor = RD->getDestructor();
|
|
|
|
|
|
|
|
PostImplicitCall PP(Dtor, DE->getLocStart(), LCtx);
|
|
|
|
NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
|
|
|
|
Bldr.generateNode(PP, Pred->getState(), Pred);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitCXXDestructor(DE->getDestroyedType(),
|
|
|
|
ArgVal.getAsRegion(),
|
|
|
|
DE, /*IsBase=*/ false,
|
|
|
|
Pred, Dst);
|
2013-09-04 01:00:57 +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();
|
|
|
|
|
|
|
|
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,
|
2013-09-02 17:09:15 +08:00
|
|
|
ExplodedNodeSet &Dst) {
|
2014-08-07 18:42:17 +08:00
|
|
|
ExplodedNodeSet CleanDtorState;
|
|
|
|
StmtNodeBuilder StmtBldr(Pred, CleanDtorState, *currBldrCtx);
|
|
|
|
ProgramStateRef State = Pred->getState();
|
2014-08-11 22:54:30 +08:00
|
|
|
if (State->contains<InitializedTemporariesSet>(
|
|
|
|
std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()))) {
|
|
|
|
// FIXME: Currently we insert temporary destructors for default parameters,
|
|
|
|
// but we don't insert the constructors.
|
|
|
|
State = State->remove<InitializedTemporariesSet>(
|
|
|
|
std::make_pair(D.getBindTemporaryExpr(), Pred->getStackFrame()));
|
|
|
|
}
|
2014-08-07 18:42:17 +08:00
|
|
|
StmtBldr.generateNode(D.getBindTemporaryExpr(), Pred, State);
|
2013-09-02 17:09:15 +08:00
|
|
|
|
|
|
|
QualType varType = D.getBindTemporaryExpr()->getSubExpr()->getType();
|
2014-08-13 23:25:55 +08:00
|
|
|
// FIXME: Currently CleanDtorState can be empty here due to temporaries being
|
|
|
|
// bound to default parameters.
|
|
|
|
assert(CleanDtorState.size() <= 1);
|
|
|
|
ExplodedNode *CleanPred =
|
|
|
|
CleanDtorState.empty() ? Pred : *CleanDtorState.begin();
|
2014-08-07 18:42:17 +08:00
|
|
|
// FIXME: Inlining of temporary destructors is not supported yet anyway, so
|
|
|
|
// we just put a NULL region for now. This will need to be changed later.
|
2014-08-07 06:01:54 +08:00
|
|
|
VisitCXXDestructor(varType, nullptr, D.getBindTemporaryExpr(),
|
2014-08-07 18:42:17 +08:00
|
|
|
/*IsBase=*/false, CleanPred, Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExprEngine::processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE,
|
|
|
|
NodeBuilderContext &BldCtx,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst,
|
|
|
|
const CFGBlock *DstT,
|
|
|
|
const CFGBlock *DstF) {
|
|
|
|
BranchNodeBuilder TempDtorBuilder(Pred, Dst, BldCtx, DstT, DstF);
|
|
|
|
if (Pred->getState()->contains<InitializedTemporariesSet>(
|
|
|
|
std::make_pair(BTE, Pred->getStackFrame()))) {
|
|
|
|
TempDtorBuilder.markInfeasible(false);
|
|
|
|
TempDtorBuilder.generateNode(Pred->getState(), true, Pred);
|
|
|
|
} else {
|
|
|
|
TempDtorBuilder.markInfeasible(true);
|
|
|
|
TempDtorBuilder.generateNode(Pred->getState(), false, Pred);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExprEngine::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE,
|
|
|
|
ExplodedNodeSet &PreVisit,
|
|
|
|
ExplodedNodeSet &Dst) {
|
|
|
|
if (!getAnalysisManager().options.includeTemporaryDtorsInCFG()) {
|
|
|
|
// In case we don't have temporary destructors in the CFG, do not mark
|
|
|
|
// the initialization - we would otherwise never clean it up.
|
|
|
|
Dst = PreVisit;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StmtNodeBuilder StmtBldr(PreVisit, Dst, *currBldrCtx);
|
|
|
|
for (ExplodedNode *Node : PreVisit) {
|
|
|
|
ProgramStateRef State = Node->getState();
|
2014-08-13 23:25:55 +08:00
|
|
|
|
|
|
|
if (!State->contains<InitializedTemporariesSet>(
|
|
|
|
std::make_pair(BTE, Node->getStackFrame()))) {
|
|
|
|
// FIXME: Currently the state might already contain the marker due to
|
|
|
|
// incorrect handling of temporaries bound to default parameters; for
|
|
|
|
// those, we currently skip the CXXBindTemporaryExpr but rely on adding
|
|
|
|
// temporary destructor nodes.
|
|
|
|
State = State->add<InitializedTemporariesSet>(
|
|
|
|
std::make_pair(BTE, Node->getStackFrame()));
|
|
|
|
}
|
2014-08-07 18:42:17 +08:00
|
|
|
StmtBldr.generateNode(BTE, Node, State);
|
|
|
|
}
|
2013-09-02 17:09:15 +08:00
|
|
|
}
|
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::CXXTryStmtClass:
|
|
|
|
case Stmt::CXXTypeidExprClass:
|
2010-09-09 07:47:05 +08:00
|
|
|
case Stmt::CXXUuidofExprClass:
|
2014-11-08 13:07:16 +08:00
|
|
|
case Stmt::CXXFoldExprClass:
|
2013-04-16 15:28:30 +08:00
|
|
|
case Stmt::MSPropertyRefExprClass:
|
2009-12-15 09:38:04 +08:00
|
|
|
case Stmt::CXXUnresolvedConstructExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::DependentScopeDeclRefExprClass:
|
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:
|
2014-10-28 02:07:20 +08:00
|
|
|
case Stmt::TypoExprClass:
|
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:
|
2014-07-07 14:20:50 +08:00
|
|
|
case Stmt::SEHLeaveStmtClass:
|
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:
|
|
|
|
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:
|
2013-04-17 02:53:08 +08:00
|
|
|
case Stmt::CapturedStmtClass:
|
2013-07-19 11:13:43 +08:00
|
|
|
case Stmt::OMPParallelDirectiveClass:
|
2014-02-27 16:29:12 +08:00
|
|
|
case Stmt::OMPSimdDirectiveClass:
|
2014-06-18 12:14:57 +08:00
|
|
|
case Stmt::OMPForDirectiveClass:
|
2014-09-18 13:12:34 +08:00
|
|
|
case Stmt::OMPForSimdDirectiveClass:
|
2014-06-25 19:44:49 +08:00
|
|
|
case Stmt::OMPSectionsDirectiveClass:
|
2014-06-26 16:21:58 +08:00
|
|
|
case Stmt::OMPSectionDirectiveClass:
|
2014-06-26 20:05:45 +08:00
|
|
|
case Stmt::OMPSingleDirectiveClass:
|
2014-07-17 16:54:58 +08:00
|
|
|
case Stmt::OMPMasterDirectiveClass:
|
2014-07-21 17:42:05 +08:00
|
|
|
case Stmt::OMPCriticalDirectiveClass:
|
2014-07-07 21:01:15 +08:00
|
|
|
case Stmt::OMPParallelForDirectiveClass:
|
2014-09-23 17:33:00 +08:00
|
|
|
case Stmt::OMPParallelForSimdDirectiveClass:
|
2014-07-08 16:12:03 +08:00
|
|
|
case Stmt::OMPParallelSectionsDirectiveClass:
|
2014-07-11 19:25:16 +08:00
|
|
|
case Stmt::OMPTaskDirectiveClass:
|
2014-07-18 15:47:19 +08:00
|
|
|
case Stmt::OMPTaskyieldDirectiveClass:
|
2014-07-18 17:11:51 +08:00
|
|
|
case Stmt::OMPBarrierDirectiveClass:
|
2014-07-18 18:17:07 +08:00
|
|
|
case Stmt::OMPTaskwaitDirectiveClass:
|
2015-06-18 20:14:09 +08:00
|
|
|
case Stmt::OMPTaskgroupDirectiveClass:
|
2014-07-21 19:26:11 +08:00
|
|
|
case Stmt::OMPFlushDirectiveClass:
|
2014-07-22 14:45:04 +08:00
|
|
|
case Stmt::OMPOrderedDirectiveClass:
|
2014-07-22 18:10:35 +08:00
|
|
|
case Stmt::OMPAtomicDirectiveClass:
|
2014-09-19 16:19:49 +08:00
|
|
|
case Stmt::OMPTargetDirectiveClass:
|
2015-07-21 21:44:28 +08:00
|
|
|
case Stmt::OMPTargetDataDirectiveClass:
|
2014-10-09 12:18:56 +08:00
|
|
|
case Stmt::OMPTeamsDirectiveClass:
|
2015-07-01 14:57:41 +08:00
|
|
|
case Stmt::OMPCancellationPointDirectiveClass:
|
2015-07-02 19:25:17 +08:00
|
|
|
case Stmt::OMPCancelDirectiveClass:
|
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;
|
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
case Stmt::CXXBindTemporaryExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet PreVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
|
|
|
|
ExplodedNodeSet Next;
|
|
|
|
VisitCXXBindTemporaryExpr(cast<CXXBindTemporaryExpr>(S), PreVisit, Next);
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, Next, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-16 01:33:31 +08:00
|
|
|
// Cases not handled yet; but will handle some day.
|
|
|
|
case Stmt::DesignatedInitExprClass:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Stmt::DesignatedInitUpdateExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
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::ShuffleVectorExprClass:
|
2013-09-18 11:29:45 +08:00
|
|
|
case Stmt::ConvertVectorExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
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.
|
2014-10-09 16:45:04 +08:00
|
|
|
case Stmt::PredefinedExprClass:
|
2010-04-13 21:15:19 +08:00
|
|
|
case Stmt::AddrLabelExprClass:
|
2013-07-02 17:38:48 +08:00
|
|
|
case Stmt::AttributedStmtClass:
|
2010-04-13 21:15:19 +08:00
|
|
|
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:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Stmt::NoInitExprClass:
|
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:
|
2013-07-23 10:15:20 +08:00
|
|
|
case Stmt::CXXPseudoDestructorExprClass:
|
2012-07-27 09:15:02 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmExprClass:
|
2015-08-25 22:24:04 +08:00
|
|
|
case Stmt::CXXNullPtrLiteralExprClass:
|
|
|
|
case Stmt::OMPArraySectionExprClass: {
|
2012-02-17 04:56:01 +08:00
|
|
|
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-07-18 01:16:42 +08:00
|
|
|
case Stmt::CXXDefaultArgExprClass:
|
|
|
|
case Stmt::CXXDefaultInitExprClass: {
|
2013-02-13 11:11:06 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet PreVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
|
|
|
|
|
|
|
|
ExplodedNodeSet Tmp;
|
|
|
|
StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx);
|
|
|
|
|
2013-07-18 01:16:42 +08:00
|
|
|
const Expr *ArgE;
|
|
|
|
if (const CXXDefaultArgExpr *DefE = dyn_cast<CXXDefaultArgExpr>(S))
|
|
|
|
ArgE = DefE->getExpr();
|
|
|
|
else if (const CXXDefaultInitExpr *DefE = dyn_cast<CXXDefaultInitExpr>(S))
|
|
|
|
ArgE = DefE->getExpr();
|
|
|
|
else
|
|
|
|
llvm_unreachable("unknown constant wrapper kind");
|
2013-02-13 11:11:06 +08:00
|
|
|
|
2013-05-03 03:51:20 +08:00
|
|
|
bool IsTemporary = false;
|
|
|
|
if (const MaterializeTemporaryExpr *MTE =
|
|
|
|
dyn_cast<MaterializeTemporaryExpr>(ArgE)) {
|
|
|
|
ArgE = MTE->GetTemporaryExpr();
|
|
|
|
IsTemporary = true;
|
|
|
|
}
|
|
|
|
|
[analyzer] Consolidate constant evaluation logic in SValBuilder.
Previously, this was scattered across Environment (literal expressions),
ExprEngine (default arguments), and RegionStore (global constants). The
former special-cased several kinds of simple constant expressions, while
the latter two deferred to the AST's constant evaluator.
Now, these are all unified as SValBuilder::getConstantVal(). To keep
Environment fast, the special cases for simple constant expressions have
been left in, but the main benefits are that (a) unusual constants like
ObjCStringLiterals now work as default arguments and global constant
initializers, and (b) we're not duplicating code between ExprEngine and
RegionStore.
This actually caught a bug in our test suite, which is awesome: we stop
tracking allocated memory if it's passed as an argument along with some
kind of callback, but not if the callback is 0. We were testing this in
a case where the callback parameter had a default value, but that value
was 0. After this change, the analyzer now (correctly) flags that as a
leak!
<rdar://problem/13773117>
llvm-svn: 180894
2013-05-02 07:10:44 +08:00
|
|
|
Optional<SVal> ConstantVal = svalBuilder.getConstantVal(ArgE);
|
|
|
|
if (!ConstantVal)
|
|
|
|
ConstantVal = UnknownVal();
|
2013-02-13 11:11:06 +08:00
|
|
|
|
2013-07-18 01:16:42 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
2013-02-13 11:11:06 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = PreVisit.begin(), E = PreVisit.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ProgramStateRef State = (*I)->getState();
|
2013-07-18 01:16:42 +08:00
|
|
|
State = State->BindExpr(S, LCtx, *ConstantVal);
|
2013-05-03 03:51:20 +08:00
|
|
|
if (IsTemporary)
|
2013-07-18 01:16:42 +08:00
|
|
|
State = createTemporaryRegionIfNeeded(State, LCtx,
|
|
|
|
cast<Expr>(S),
|
|
|
|
cast<Expr>(S));
|
2013-02-13 11:11:06 +08:00
|
|
|
Bldr2.generateNode(S, *I, State);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-18 01:16:33 +08:00
|
|
|
// Cases we evaluate as opaque expressions, conjuring a symbol.
|
|
|
|
case Stmt::CXXStdInitializerListExprClass:
|
2012-03-07 04:06:12 +08:00
|
|
|
case Expr::ObjCArrayLiteralClass:
|
2012-05-12 13:10:43 +08:00
|
|
|
case Expr::ObjCDictionaryLiteralClass:
|
|
|
|
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();
|
2014-05-27 10:45:47 +08:00
|
|
|
SVal result = svalBuilder.conjureSymbolVal(nullptr, 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));
|
2013-04-19 00:33:40 +08:00
|
|
|
if (NewState != State) {
|
2014-05-27 10:45:47 +08:00
|
|
|
Pred = Bldr.generateNode(OCE, Pred, NewState, /*Tag=*/nullptr,
|
2012-10-18 03:35:37 +08:00
|
|
|
ProgramPoint::PreStmtKind);
|
2013-04-19 00:33:40 +08:00
|
|
|
// Did we cache out?
|
|
|
|
if (!Pred)
|
|
|
|
break;
|
|
|
|
}
|
2012-10-18 03:35:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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);
|
2014-05-27 10:45:47 +08:00
|
|
|
ExplodedNode *BeforeProcessingCall = nullptr;
|
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;
|
2014-05-27 10:45:47 +08:00
|
|
|
N = N->pred_empty() ? nullptr : *(N->pred_begin());
|
2012-03-28 04:02:53 +08:00
|
|
|
|
|
|
|
// 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) {
|
2013-07-19 08:59:08 +08:00
|
|
|
PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
|
|
|
|
|
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) {
|
2014-02-18 02:25:34 +08:00
|
|
|
static SimpleProgramPointTag tag(TagProviderName, "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();
|
|
|
|
|
2013-04-09 10:30:33 +08:00
|
|
|
if (!T->isIntegralOrEnumerationType())
|
2009-03-14 00:32:54 +08:00
|
|
|
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();
|
|
|
|
|
2013-04-09 10:30:33 +08:00
|
|
|
if (!bitsInit || !T->isIntegralOrEnumerationType() ||
|
|
|
|
Ctx.getTypeSize(T) > bits)
|
2009-03-14 00:32:54 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-11 17:31:47 +08:00
|
|
|
#ifndef NDEBUG
|
2014-05-11 01:13:34 +08:00
|
|
|
static const Stmt *getRightmostLeaf(const Stmt *Condition) {
|
2014-05-05 17:58:03 +08:00
|
|
|
while (Condition) {
|
|
|
|
const BinaryOperator *BO = dyn_cast<BinaryOperator>(Condition);
|
|
|
|
if (!BO || !BO->isLogicalOp()) {
|
|
|
|
return Condition;
|
|
|
|
}
|
|
|
|
Condition = BO->getRHS()->IgnoreParens();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-11 17:31:47 +08:00
|
|
|
#endif
|
2014-05-05 17:58:03 +08:00
|
|
|
|
|
|
|
// Returns the condition the branch at the end of 'B' depends on and whose value
|
|
|
|
// has been evaluated within 'B'.
|
|
|
|
// In most cases, the terminator condition of 'B' will be evaluated fully in
|
|
|
|
// the last statement of 'B'; in those cases, the resolved condition is the
|
|
|
|
// given 'Condition'.
|
|
|
|
// If the condition of the branch is a logical binary operator tree, the CFG is
|
|
|
|
// optimized: in that case, we know that the expression formed by all but the
|
|
|
|
// rightmost leaf of the logical binary operator tree must be true, and thus
|
|
|
|
// the branch condition is at this point equivalent to the truth value of that
|
|
|
|
// rightmost leaf; the CFG block thus only evaluates this rightmost leaf
|
|
|
|
// expression in its final statement. As the full condition in that case was
|
|
|
|
// not evaluated, and is thus not in the SVal cache, we need to use that leaf
|
|
|
|
// expression to evaluate the truth value of the condition in the current state
|
|
|
|
// space.
|
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;
|
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
assert(!B->getTerminator().isTemporaryDtorsBranch() &&
|
|
|
|
"Temporary destructor branches handled by processBindTemporary.");
|
2014-05-05 17:58:03 +08:00
|
|
|
|
2012-07-14 13:04:10 +08:00
|
|
|
// 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;
|
2014-05-05 17:58:03 +08:00
|
|
|
const Stmt *LastStmt = CS->getStmt();
|
|
|
|
assert(LastStmt == Condition || LastStmt == getRightmostLeaf(Condition));
|
|
|
|
return LastStmt;
|
2012-07-14 13:04:10 +08:00
|
|
|
}
|
|
|
|
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) {
|
2014-08-07 18:42:17 +08:00
|
|
|
assert((!Condition || !isa<CXXBindTemporaryExpr>(Condition)) &&
|
|
|
|
"CXXBindTemporaryExprs are handled by processBindTemporary.");
|
2013-09-02 17:09:15 +08:00
|
|
|
const LocationContext *LCtx = Pred->getLocationContext();
|
|
|
|
PrettyStackTraceLocationContext StackCrashInfo(LCtx);
|
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
|
|
|
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(Condition))
|
|
|
|
Condition = Ex->IgnoreParens();
|
2013-09-02 17:09:15 +08:00
|
|
|
|
2013-12-07 02:56:29 +08:00
|
|
|
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)) {
|
2013-04-09 10:30:33 +08:00
|
|
|
if (Ex->getType()->isIntegralOrEnumerationType()) {
|
2011-10-19 07:06:21 +08:00
|
|
|
// 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()) {
|
2013-12-07 02:56: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>();
|
2013-12-07 02:56:29 +08:00
|
|
|
|
|
|
|
ProgramStateRef StTrue, StFalse;
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(StTrue, StFalse) = PrevState->assume(V);
|
2012-12-07 02:58:09 +08:00
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
// Process the true branch.
|
|
|
|
if (builder.isFeasible(true)) {
|
2013-12-07 02:56:29 +08:00
|
|
|
if (StTrue)
|
2012-12-07 02:58:09 +08:00
|
|
|
builder.generateNode(StTrue, true, PredI);
|
2013-12-07 02:56:29 +08:00
|
|
|
else
|
2011-10-19 07:06:21 +08:00
|
|
|
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)) {
|
2013-12-07 02:56:29 +08:00
|
|
|
if (StFalse)
|
2012-12-07 02:58:09 +08:00
|
|
|
builder.generateNode(StFalse, false, PredI);
|
2013-12-07 02:56:29 +08:00
|
|
|
else
|
2011-10-19 07:06:21 +08:00
|
|
|
builder.markInfeasible(false);
|
|
|
|
}
|
|
|
|
}
|
2014-05-27 10:45:47 +08:00
|
|
|
currBldrCtx = nullptr;
|
2008-02-05 08:26:40 +08:00
|
|
|
}
|
|
|
|
|
2013-03-29 08:09:28 +08:00
|
|
|
/// The GDM component containing the set of global variables which have been
|
|
|
|
/// previously initialized with explicit initializers.
|
|
|
|
REGISTER_TRAIT_WITH_PROGRAMSTATE(InitializedGlobalsSet,
|
|
|
|
llvm::ImmutableSet<const VarDecl *>)
|
|
|
|
|
|
|
|
void ExprEngine::processStaticInitializer(const DeclStmt *DS,
|
|
|
|
NodeBuilderContext &BuilderCtx,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
clang::ento::ExplodedNodeSet &Dst,
|
|
|
|
const CFGBlock *DstT,
|
|
|
|
const CFGBlock *DstF) {
|
2013-07-19 08:59:08 +08:00
|
|
|
PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
|
2013-03-29 08:09:28 +08:00
|
|
|
currBldrCtx = &BuilderCtx;
|
|
|
|
|
|
|
|
const VarDecl *VD = cast<VarDecl>(DS->getSingleDecl());
|
|
|
|
ProgramStateRef state = Pred->getState();
|
|
|
|
bool initHasRun = state->contains<InitializedGlobalsSet>(VD);
|
|
|
|
BranchNodeBuilder builder(Pred, Dst, BuilderCtx, DstT, DstF);
|
|
|
|
|
|
|
|
if (!initHasRun) {
|
|
|
|
state = state->add<InitializedGlobalsSet>(VD);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.generateNode(state, initHasRun, Pred);
|
|
|
|
builder.markInfeasible(!initHasRun);
|
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
currBldrCtx = nullptr;
|
2013-03-29 08:09:28 +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
|
|
|
|
2014-08-07 18:42:17 +08:00
|
|
|
#if 0
|
|
|
|
static bool stackFrameDoesNotContainInitializedTemporaries(ExplodedNode &Pred) {
|
|
|
|
const StackFrameContext* Frame = Pred.getStackFrame();
|
|
|
|
const llvm::ImmutableSet<CXXBindTemporaryContext> &Set =
|
|
|
|
Pred.getState()->get<InitializedTemporariesSet>();
|
|
|
|
return std::find_if(Set.begin(), Set.end(),
|
|
|
|
[&](const CXXBindTemporaryContext &Ctx) {
|
|
|
|
if (Ctx.second == Frame) {
|
|
|
|
Ctx.first->dump();
|
|
|
|
llvm::errs() << "\n";
|
|
|
|
}
|
|
|
|
return Ctx.second == Frame;
|
|
|
|
}) == Set.end();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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) {
|
2014-08-07 18:42:17 +08:00
|
|
|
// FIXME: Assert that stackFrameDoesNotContainInitializedTemporaries(*Pred)).
|
|
|
|
// We currently cannot enable this assert, as lifetime extended temporaries
|
|
|
|
// are not modelled correctly.
|
2013-07-19 08:59:08 +08:00
|
|
|
PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
|
2012-11-03 10:54:11 +08:00
|
|
|
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;
|
2014-05-27 10:45:47 +08:00
|
|
|
DefaultSt = nullptr;
|
2010-01-09 02:54:04 +08:00
|
|
|
}
|
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)) {
|
2013-05-30 04:50:34 +08:00
|
|
|
// C permits "extern void v", and if you cast the address to a valid type,
|
|
|
|
// you can even do things with it. We simply pretend
|
|
|
|
assert(Ex->isGLValue() || VD->getType()->isVoidType());
|
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
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
|
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);
|
2014-05-27 10:45:47 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
|
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);
|
2014-05-27 10:45:47 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
|
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);
|
2015-02-05 09:02:59 +08:00
|
|
|
assert(A->isGLValue() ||
|
|
|
|
(!AMgr.getLangOpts().CPlusPlus &&
|
|
|
|
A->getType().isCForbiddenLValueType()));
|
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));
|
2014-05-27 10:45:47 +08:00
|
|
|
Bldr.generateNode(A, *it, state->BindExpr(A, LCtx, V), nullptr,
|
2012-08-21 02:43:42 +08:00
|
|
|
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,
|
2013-12-12 01:58:10 +08:00
|
|
|
ExplodedNodeSet &Dst) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
// FIXME: Prechecks eventually go in ::Visit().
|
|
|
|
ExplodedNodeSet CheckedSet;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(CheckedSet, Pred, M, *this);
|
|
|
|
|
|
|
|
ExplodedNodeSet EvalSet;
|
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)) {
|
2013-12-12 01:58:10 +08:00
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
VisitCommonDeclRefExpr(M, Member, Pred, EvalSet);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StmtNodeBuilder Bldr(CheckedSet, EvalSet, *currBldrCtx);
|
|
|
|
ExplodedNodeSet Tmp;
|
2012-10-18 03:35:37 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = CheckedSet.begin(), E = CheckedSet.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ProgramStateRef state = (*I)->getState();
|
|
|
|
const LocationContext *LCtx = (*I)->getLocationContext();
|
|
|
|
Expr *BaseExpr = M->getBase();
|
2012-06-23 07:55:50 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
// Handle C++ method calls.
|
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
|
|
|
|
if (MD->isInstance())
|
|
|
|
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
|
2012-09-29 09:36:47 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
SVal MDVal = svalBuilder.getFunctionPointer(MD);
|
|
|
|
state = state->BindExpr(M, LCtx, MDVal);
|
2012-09-29 09:36:47 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
Bldr.generateNode(M, *I, state);
|
|
|
|
continue;
|
2013-06-06 08:19:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
// Handle regular struct fields / member variables.
|
|
|
|
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
|
|
|
|
SVal baseExprVal = state->getSVal(BaseExpr, LCtx);
|
|
|
|
|
|
|
|
FieldDecl *field = cast<FieldDecl>(Member);
|
|
|
|
SVal L = state->getLValue(field, baseExprVal);
|
|
|
|
|
|
|
|
if (M->isGLValue() || M->getType()->isArrayType()) {
|
|
|
|
// We special-case rvalues of array type because the analyzer cannot
|
|
|
|
// reason about them, since we expect all regions to be wrapped in Locs.
|
|
|
|
// We instead treat these as lvalues and assume that they will decay to
|
|
|
|
// pointers as soon as they are used.
|
|
|
|
if (!M->isGLValue()) {
|
|
|
|
assert(M->getType()->isArrayType());
|
|
|
|
const ImplicitCastExpr *PE =
|
|
|
|
dyn_cast<ImplicitCastExpr>((*I)->getParentMap().getParent(M));
|
|
|
|
if (!PE || PE->getCastKind() != CK_ArrayToPointerDecay) {
|
|
|
|
llvm_unreachable("should always be wrapped in ArrayToPointerDecay");
|
|
|
|
}
|
|
|
|
}
|
2012-08-01 00:34:07 +08:00
|
|
|
|
2013-12-12 01:58:10 +08:00
|
|
|
if (field->getType()->isReferenceType()) {
|
|
|
|
if (const MemRegion *R = L.getAsRegion())
|
|
|
|
L = state->getSVal(R);
|
|
|
|
else
|
|
|
|
L = UnknownVal();
|
|
|
|
}
|
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
Bldr.generateNode(M, *I, state->BindExpr(M, LCtx, L), nullptr,
|
2013-12-12 01:58:10 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
|
|
|
} else {
|
|
|
|
Bldr.takeNodes(*I);
|
|
|
|
evalLoad(Tmp, M, M, *I, state, L);
|
|
|
|
Bldr.addNodes(Tmp);
|
|
|
|
}
|
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
}
|
2013-12-12 01:58:10 +08:00
|
|
|
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, M, *this);
|
2008-04-22 07:43:38 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 08:38:25 +08:00
|
|
|
namespace {
|
2015-08-14 06:50:09 +08:00
|
|
|
class CollectReachableSymbolsCallback final : public SymbolVisitor {
|
2012-12-20 08:38:25 +08:00
|
|
|
InvalidatedSymbols Symbols;
|
|
|
|
public:
|
|
|
|
CollectReachableSymbolsCallback(ProgramStateRef State) {}
|
|
|
|
const InvalidatedSymbols &getSymbols() const { return Symbols; }
|
|
|
|
|
2014-03-15 12:29:04 +08:00
|
|
|
bool VisitSymbol(SymbolRef Sym) override {
|
2012-12-20 08:38:25 +08:00
|
|
|
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)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2014-05-27 10:45:47 +08:00
|
|
|
/*CallEvent*/ nullptr,
|
2013-09-25 07:47:29 +08:00
|
|
|
PSK_EscapeOnBind,
|
2014-05-27 10:45:47 +08:00
|
|
|
nullptr);
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramStateRef
|
2013-03-29 07:15:29 +08:00
|
|
|
ExprEngine::notifyCheckersOfPointerEscape(ProgramStateRef State,
|
2012-12-20 08:38:25 +08:00
|
|
|
const InvalidatedSymbols *Invalidated,
|
|
|
|
ArrayRef<const MemRegion *> ExplicitRegions,
|
|
|
|
ArrayRef<const MemRegion *> Regions,
|
2013-03-29 07:15:29 +08:00
|
|
|
const CallEvent *Call,
|
2013-09-25 07:47:29 +08:00
|
|
|
RegionAndSymbolInvalidationTraits &ITraits) {
|
2012-12-20 08:38:25 +08:00
|
|
|
|
|
|
|
if (!Invalidated || Invalidated->empty())
|
|
|
|
return State;
|
|
|
|
|
|
|
|
if (!Call)
|
|
|
|
return getCheckerManager().runCheckersForPointerEscape(State,
|
2013-02-08 07:05:43 +08:00
|
|
|
*Invalidated,
|
2014-05-27 10:45:47 +08:00
|
|
|
nullptr,
|
2013-04-19 17:39:51 +08:00
|
|
|
PSK_EscapeOther,
|
2013-09-25 07:47:29 +08:00
|
|
|
&ITraits);
|
2013-03-29 07:15:29 +08:00
|
|
|
|
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-09-25 07:47:29 +08:00
|
|
|
SymbolsDirectlyInvalidated, Call, PSK_DirectEscapeOnCall, &ITraits);
|
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-09-25 07:47:29 +08:00
|
|
|
SymbolsIndirectlyInvalidated, Call, PSK_IndirectEscapeOnCall, &ITraits);
|
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>()) {
|
2014-05-27 10:45:47 +08:00
|
|
|
const ProgramPoint L = PostStore(StoreE, LC, /*Loc*/nullptr,
|
|
|
|
/*tag*/nullptr);
|
2012-12-20 08:38:25 +08:00
|
|
|
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
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
const MemRegion *LocReg = nullptr;
|
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
|
|
|
}
|
2014-05-27 10:45:47 +08:00
|
|
|
|
|
|
|
const ProgramPoint L = PostStore(StoreE, LC, LocReg, nullptr);
|
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
|
2014-02-18 02:25:34 +08:00
|
|
|
loadReferenceTag(TagProviderName, "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
|
|
|
|
2014-02-18 02:25:34 +08:00
|
|
|
static SimpleProgramPointTag tag(TagProviderName, "Location");
|
2012-08-21 02:43:42 +08:00
|
|
|
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
|
2014-02-18 02:25:34 +08:00
|
|
|
eagerlyAssumeBinOpBifurcationTrue(TagProviderName,
|
|
|
|
"Eagerly Assume True"),
|
|
|
|
eagerlyAssumeBinOpBifurcationFalse(TagProviderName,
|
|
|
|
"Eagerly Assume False");
|
2012-08-31 03:26:48 +08:00
|
|
|
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;
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(StateTrue, StateFalse) = state->assume(*SEV);
|
2012-12-07 02:58:09 +08:00
|
|
|
|
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
|
|
|
|
2014-06-23 10:16:38 +08:00
|
|
|
for (const Expr *O : A->outputs()) {
|
|
|
|
SVal X = state->getSVal(O, 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;
|
|
|
|
}
|
|
|
|
|
2013-03-23 05:15:16 +08:00
|
|
|
case ProgramPoint::PostInitializerKind: {
|
|
|
|
Out << "PostInitializer: ";
|
|
|
|
const CXXCtorInitializer *Init =
|
|
|
|
Loc.castAs<PostInitializer>().getInitializer();
|
|
|
|
if (const FieldDecl *FD = Init->getAnyMember())
|
|
|
|
Out << *FD;
|
|
|
|
else {
|
|
|
|
QualType Ty = Init->getTypeSourceInfo()->getType();
|
|
|
|
Ty = Ty.getLocalUnqualifiedType();
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
2013-03-23 05:15:16 +08:00
|
|
|
Ty.print(Out, LO);
|
2008-12-17 06:02:27 +08:00
|
|
|
}
|
2013-03-23 05:15:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-12-17 06:02:27 +08:00
|
|
|
|
2013-03-23 05:15:16 +08:00
|
|
|
case ProgramPoint::BlockEdgeKind: {
|
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()) {
|
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.
|
2014-06-10 06:53:25 +08:00
|
|
|
if (C->getLHS())
|
|
|
|
C->getLHS()->printPretty(Out, nullptr, 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 << " .. ";
|
2014-05-27 10:45:47 +08:00
|
|
|
RHS->printPretty(Out, nullptr, 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
|
2013-03-23 05:15:16 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
const Stmt *S = Loc.castAs<StmtPoint>().getStmt();
|
2014-06-10 06:53:25 +08:00
|
|
|
assert(S != nullptr && "Expecting non-null Stmt");
|
2013-03-23 05:15:16 +08:00
|
|
|
|
|
|
|
Out << S->getStmtClassName() << ' ' << (const void*) S << ' ';
|
|
|
|
LangOptions LO; // FIXME.
|
2014-05-27 10:45:47 +08:00
|
|
|
S->printPretty(Out, nullptr, PrintingPolicy(LO));
|
2013-03-23 05:15:16 +08:00
|
|
|
printLocation(Out, S->getLocStart());
|
|
|
|
|
|
|
|
if (Loc.getAs<PreStmt>())
|
|
|
|
Out << "\\lPreStmt\\l;";
|
|
|
|
else if (Loc.getAs<PostLoad>())
|
|
|
|
Out << "\\lPostLoad\\l;";
|
|
|
|
else if (Loc.getAs<PostStore>())
|
|
|
|
Out << "\\lPostStore\\l";
|
|
|
|
else if (Loc.getAs<PostLValue>())
|
|
|
|
Out << "\\lPostLValue\\l";
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to determine
|
|
|
|
// the name of the check.
|
|
|
|
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";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
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();
|
2014-07-05 11:08:06 +08:00
|
|
|
Out << "\\|StateID: " << (const void*) state.get()
|
2012-09-06 23:59:27 +08:00
|
|
|
<< " 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();
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
} // end llvm namespace
|
2008-01-17 05:46:15 +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) {
|
2013-03-16 09:07:53 +08:00
|
|
|
std::vector<const 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
|
|
|
|
2013-03-16 09:07:53 +08:00
|
|
|
ViewGraph(Src);
|
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
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
GraphPrintCheckerState = nullptr;
|
|
|
|
GraphPrintSourceManager = nullptr;
|
2008-03-12 02:25:33 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-16 09:07:53 +08:00
|
|
|
void ExprEngine::ViewGraph(ArrayRef<const ExplodedNode*> Nodes) {
|
2008-03-12 02:25:33 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<ExplodedGraph> TrimmedG(G.trim(Nodes));
|
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
|
|
|
|
2014-05-27 10:45:47 +08:00
|
|
|
GraphPrintCheckerState = nullptr;
|
|
|
|
GraphPrintSourceManager = nullptr;
|
2008-02-15 06:36:46 +08:00
|
|
|
#endif
|
2008-01-17 02:18:48 +08:00
|
|
|
}
|