2010-12-23 02:53:44 +08:00
|
|
|
//=-- ExprEngine.cpp - Path-Sensitive Expression-Level Dataflow ---*- C++ -*-=
|
2008-01-31 10:35:41 +08:00
|
|
|
//
|
2008-01-31 14:49:09 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2008-01-16 07:55:06 +08:00
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-02-15 06:13:12 +08:00
|
|
|
// This file defines a meta-engine for path-sensitive dataflow analysis that
|
|
|
|
// is built on GREngine, but provides the boilerplate to execute transfer
|
|
|
|
// functions and build the ExplodedGraph at the expression level.
|
2008-01-16 07:55:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-12-23 02:52:56 +08:00
|
|
|
|
2012-02-29 05:49:04 +08:00
|
|
|
#define DEBUG_TYPE "ExprEngine"
|
|
|
|
|
2011-02-15 02:13:31 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2011-09-02 16:02:59 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ObjCMessage.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"
|
|
|
|
#include "clang/AST/StmtObjC.h"
|
2010-03-16 21:14:16 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-06-14 09:54:56 +08:00
|
|
|
#include "clang/Basic/Builtins.h"
|
2009-04-26 09:32:48 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2009-03-11 10:41:36 +08:00
|
|
|
#include "clang/Basic/PrettyStackTrace.h"
|
2008-09-13 13:16:45 +08:00
|
|
|
#include "llvm/Support/raw_ostream.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"
|
2008-07-11 06:03:41 +08:00
|
|
|
|
2008-02-27 14:07:00 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include "llvm/Support/GraphWriter.h"
|
|
|
|
#endif
|
|
|
|
|
2008-02-15 06:16:04 +08:00
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2008-02-15 06:16:04 +08:00
|
|
|
using llvm::APSInt;
|
2008-01-24 03:59:44 +08:00
|
|
|
|
2012-02-29 05:49:04 +08:00
|
|
|
STATISTIC(NumRemoveDeadBindings,
|
|
|
|
"The # of times RemoveDeadBindings is called");
|
|
|
|
STATISTIC(NumRemoveDeadBindingsSkipped,
|
|
|
|
"The # of times RemoveDeadBindings is skipped");
|
|
|
|
|
2009-11-26 05:51:20 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
static inline Selector GetNullarySelector(const char* name, ASTContext &Ctx) {
|
2009-11-26 05:51:20 +08:00
|
|
|
IdentifierInfo* II = &Ctx.Idents.get(name);
|
|
|
|
return Ctx.Selectors.getSelector(0, &II);
|
|
|
|
}
|
|
|
|
|
2008-07-12 02:37:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Engine construction and deletion.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-02 13:55:19 +08:00
|
|
|
ExprEngine::ExprEngine(AnalysisManager &mgr, bool gcEnabled)
|
2009-08-15 11:17:38 +08:00
|
|
|
: AMgr(mgr),
|
2011-10-24 09:32:45 +08:00
|
|
|
AnalysisDeclContexts(mgr.getAnalysisDeclContextManager()),
|
2010-12-23 02:53:44 +08:00
|
|
|
Engine(*this),
|
|
|
|
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(),
|
|
|
|
*this),
|
2008-04-10 05:41:14 +08:00
|
|
|
SymMgr(StateMgr.getSymbolManager()),
|
2010-12-02 15:49:45 +08:00
|
|
|
svalBuilder(StateMgr.getSValBuilder()),
|
2011-10-25 02:26:03 +08:00
|
|
|
EntryNode(NULL),
|
|
|
|
currentStmt(NULL), currentStmtIdx(0), currentBuilderContext(0),
|
2008-12-22 16:30:52 +08:00
|
|
|
NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL),
|
2010-07-01 15:10:59 +08:00
|
|
|
RaiseSel(GetNullarySelector("raise", getContext())),
|
2011-09-02 14:21:26 +08:00
|
|
|
ObjCGCEnabled(gcEnabled), BR(mgr, *this) {
|
2011-02-09 09:27:33 +08:00
|
|
|
|
|
|
|
if (mgr.shouldEagerlyTrimExplodedGraph()) {
|
|
|
|
// Enable eager node reclaimation when constructing the ExplodedGraph.
|
|
|
|
G.enableNodeReclamation();
|
|
|
|
}
|
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-05-02 02:33:28 +08:00
|
|
|
delete [] NSExceptionInstanceRaiseSelectors;
|
2008-04-10 05:41:14 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef ExprEngine::getInitialState(const LocationContext *InitLoc) {
|
|
|
|
ProgramStateRef state = StateMgr.getInitialState(InitLoc);
|
2011-12-01 13:29:42 +08:00
|
|
|
const Decl *D = InitLoc->getDecl();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-10 04:36:12 +08:00
|
|
|
// Preconditions.
|
2009-04-10 08:59:50 +08:00
|
|
|
// FIXME: It would be nice if we had a more general mechanism to add
|
|
|
|
// such preconditions. Some day.
|
2009-12-18 03:17:27 +08:00
|
|
|
do {
|
2011-12-01 13:29:42 +08:00
|
|
|
|
2009-12-18 03:17:27 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
// Precondition: the first argument of 'main' is an integer guaranteed
|
|
|
|
// to be > 0.
|
|
|
|
const IdentifierInfo *II = FD->getIdentifier();
|
|
|
|
if (!II || !(II->getName() == "main" && FD->getNumParams() > 0))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const ParmVarDecl *PD = FD->getParamDecl(0);
|
|
|
|
QualType T = PD->getType();
|
|
|
|
if (!T->isIntegerType())
|
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2009-12-18 03:17:27 +08:00
|
|
|
const MemRegion *R = state->getRegion(PD, InitLoc);
|
|
|
|
if (!R)
|
|
|
|
break;
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2010-02-09 00:18:51 +08:00
|
|
|
SVal V = state->getSVal(loc::MemRegionVal(R));
|
2010-12-02 05:57:22 +08:00
|
|
|
SVal Constraint_untested = evalBinOp(state, BO_GT, V,
|
2010-12-02 15:49:45 +08:00
|
|
|
svalBuilder.makeZeroVal(T),
|
2009-12-18 03:17:27 +08:00
|
|
|
getContext().IntTy);
|
|
|
|
|
|
|
|
DefinedOrUnknownSVal *Constraint =
|
|
|
|
dyn_cast<DefinedOrUnknownSVal>(&Constraint_untested);
|
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));
|
|
|
|
|
|
|
|
if (const Loc *LV = dyn_cast<Loc>(&V)) {
|
|
|
|
// Assume that the pointer value in 'self' is non-null.
|
|
|
|
state = state->assume(*LV, true);
|
|
|
|
assert(state && "'self' cannot be null");
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 03:17:27 +08:00
|
|
|
|
2011-12-01 13:29:42 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
if (!MD->isStatic()) {
|
|
|
|
// Precondition: 'this' is always non-null upon entry to the
|
|
|
|
// top-level function. This is our starting assumption for
|
|
|
|
// analyzing an "open" program.
|
|
|
|
const StackFrameContext *SFC = InitLoc->getCurrentStackFrame();
|
|
|
|
if (SFC->getParent() == 0) {
|
|
|
|
loc::MemRegionVal L(getCXXThisRegion(MD, SFC));
|
|
|
|
SVal V = state->getSVal(L);
|
|
|
|
if (const Loc *LV = dyn_cast<Loc>(&V)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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,
|
2011-05-03 03:42:42 +08:00
|
|
|
const StoreManager::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,
|
|
|
|
const CallOrObjCMessage *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) {
|
|
|
|
currentStmtIdx = StmtIdx;
|
|
|
|
currentBuilderContext = Ctx;
|
|
|
|
|
2010-11-15 16:48:43 +08:00
|
|
|
switch (E.getKind()) {
|
2011-03-01 11:15:10 +08:00
|
|
|
case CFGElement::Invalid:
|
|
|
|
llvm_unreachable("Unexpected CFGElement kind.");
|
|
|
|
case CFGElement::Statement:
|
2011-10-25 02:26:19 +08:00
|
|
|
ProcessStmt(const_cast<Stmt*>(E.getAs<CFGStmt>()->getStmt()), Pred);
|
2011-03-01 11:15:10 +08:00
|
|
|
return;
|
|
|
|
case CFGElement::Initializer:
|
2011-10-25 02:26:19 +08:00
|
|
|
ProcessInitializer(E.getAs<CFGInitializer>()->getInitializer(), Pred);
|
2011-03-01 11:15:10 +08:00
|
|
|
return;
|
|
|
|
case CFGElement::AutomaticObjectDtor:
|
|
|
|
case CFGElement::BaseDtor:
|
|
|
|
case CFGElement::MemberDtor:
|
|
|
|
case CFGElement::TemporaryDtor:
|
2011-10-25 02:26:19 +08:00
|
|
|
ProcessImplicitDtor(*E.getAs<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?
|
|
|
|
if (AMgr.getPurgeMode() == PurgeNone)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Is this the beginning of a basic block?
|
2011-11-11 08:10:55 +08:00
|
|
|
if (isa<BlockEntrance>(Pred->getLocation()))
|
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.
|
|
|
|
if (isa<CallExpr>(S.getStmt()))
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
void ExprEngine::ProcessStmt(const CFGStmt S,
|
2012-02-17 04:48:04 +08:00
|
|
|
ExplodedNode *Pred) {
|
|
|
|
// Reclaim any unnecessary nodes in the ExplodedGraph.
|
|
|
|
G.reclaimRecentlyAllocatedNodes();
|
|
|
|
|
2010-12-17 12:44:39 +08:00
|
|
|
currentStmt = S.getStmt();
|
2009-03-11 10:41:36 +08:00
|
|
|
PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
|
2010-12-17 12:44:39 +08:00
|
|
|
currentStmt->getLocStart(),
|
2009-03-11 10:41:36 +08:00
|
|
|
"Error evaluating statement");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-19 07:06:44 +08:00
|
|
|
EntryNode = Pred;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef EntryState = EntryNode->getState();
|
2011-08-11 07:14:54 +08:00
|
|
|
CleanedState = EntryState;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Create the cleaned state.
|
2010-08-15 04:18:45 +08:00
|
|
|
const LocationContext *LC = EntryNode->getLocationContext();
|
2011-07-29 07:07:59 +08:00
|
|
|
SymbolReaper SymReaper(LC, currentStmt, SymMgr, getStoreManager());
|
2010-03-05 12:45:36 +08:00
|
|
|
|
2011-11-11 07:26:10 +08:00
|
|
|
if (shouldRemoveDeadBindings(AMgr, S, Pred, LC)) {
|
2012-02-29 05:49:04 +08:00
|
|
|
NumRemoveDeadBindings++;
|
2011-08-11 07:14:54 +08:00
|
|
|
getCheckerManager().runCheckersForLiveSymbols(CleanedState, SymReaper);
|
2011-02-24 09:05:30 +08:00
|
|
|
|
2010-08-15 04:18:45 +08:00
|
|
|
const StackFrameContext *SFC = LC->getCurrentStackFrame();
|
2011-08-11 07:14:54 +08:00
|
|
|
|
|
|
|
// 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);
|
2012-02-29 05:49:04 +08:00
|
|
|
} else {
|
|
|
|
NumRemoveDeadBindingsSkipped++;
|
2010-08-15 04:18:45 +08:00
|
|
|
}
|
2009-01-22 06:26:05 +08:00
|
|
|
|
2008-04-25 02:31:42 +08:00
|
|
|
// Process any special transfer function for dead symbols.
|
2009-08-06 20:48:26 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2011-10-25 05:19:43 +08:00
|
|
|
// A tag to track convenience transitions, which can be removed at cleanup.
|
|
|
|
static SimpleProgramPointTag cleanupTag("ExprEngine : Clean Node");
|
|
|
|
|
2011-08-11 07:14:54 +08:00
|
|
|
if (!SymReaper.hasDeadSymbols()) {
|
|
|
|
// Generate a CleanedNode that has the environment and store cleaned
|
|
|
|
// up. Since no symbols are dead, we can optimize and not clean out
|
|
|
|
// the constraint manager.
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Tmp, *currentBuilderContext);
|
2011-10-25 05:19:43 +08:00
|
|
|
Bldr.generateNode(currentStmt, EntryNode, CleanedState, false, &cleanupTag);
|
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;
|
|
|
|
getCheckerManager().runCheckersForDeadSymbols(CheckedSet, EntryNode,
|
2011-02-24 09:05:30 +08:00
|
|
|
SymReaper, currentStmt, *this);
|
|
|
|
|
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.
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(CheckedSet, Tmp, *currentBuilderContext);
|
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);
|
|
|
|
|
|
|
|
assert(StateMgr.haveEqualEnvironments(CheckerState, EntryState) &&
|
|
|
|
"Checkers are not allowed to modify the Environment as a part of "
|
|
|
|
"checkDeadSymbols processing.");
|
|
|
|
assert(StateMgr.haveEqualStores(CheckerState, EntryState) &&
|
|
|
|
"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);
|
2011-10-25 05:19:43 +08:00
|
|
|
Bldr.generateNode(currentStmt, *I, CleanedCheckerSt, false, &cleanupTag,
|
|
|
|
ProgramPoint::PostPurgeDeadSymbolsKind);
|
2011-08-11 07:14:54 +08:00
|
|
|
}
|
2008-04-25 02:31:42 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
ExplodedNodeSet Dst;
|
2009-08-06 20:48:26 +08:00
|
|
|
for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.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.
|
2011-10-27 08:59:23 +08:00
|
|
|
Visit(currentStmt, *I, DstI);
|
|
|
|
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.
|
|
|
|
Engine.enqueue(Dst, currentBuilderContext->getBlock(), currentStmtIdx);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
// NULL out these variables to cleanup.
|
2008-04-25 07:35:58 +08:00
|
|
|
CleanedState = NULL;
|
|
|
|
EntryNode = NULL;
|
2010-12-17 12:44:39 +08:00
|
|
|
currentStmt = 0;
|
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-10-25 02:26:19 +08:00
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
|
2010-12-17 12:44:39 +08:00
|
|
|
// We don't set EntryNode and currentStmt. And we don't clean up state.
|
2011-01-09 04:30:50 +08:00
|
|
|
const CXXCtorInitializer *BMI = Init.getInitializer();
|
2011-10-25 05:19:48 +08:00
|
|
|
const StackFrameContext *stackFrame =
|
|
|
|
cast<StackFrameContext>(Pred->getLocationContext());
|
|
|
|
const CXXConstructorDecl *decl =
|
|
|
|
cast<CXXConstructorDecl>(stackFrame->getDecl());
|
2011-01-13 20:30:12 +08:00
|
|
|
const CXXThisRegion *thisReg = getCXXThisRegion(decl, stackFrame);
|
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
SVal thisVal = Pred->getState()->getSVal(thisReg);
|
2010-11-16 15:52:17 +08:00
|
|
|
|
2010-12-04 17:14:42 +08:00
|
|
|
if (BMI->isAnyMemberInitializer()) {
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNodeSet AfterEval;
|
2010-11-16 15:52:17 +08:00
|
|
|
|
|
|
|
// Evaluate the initializer.
|
2011-10-25 05:19:48 +08:00
|
|
|
Visit(BMI->getInit(), Pred, AfterEval);
|
2010-11-16 15:52:17 +08:00
|
|
|
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(AfterEval, Dst, *currentBuilderContext);
|
2011-10-25 05:19:48 +08:00
|
|
|
for (ExplodedNodeSet::iterator I = AfterEval.begin(),
|
|
|
|
E = AfterEval.end(); I != E; ++I){
|
|
|
|
ExplodedNode *P = *I;
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = P->getState();
|
2010-11-16 15:52:17 +08:00
|
|
|
|
2010-12-04 17:14:42 +08:00
|
|
|
const FieldDecl *FD = BMI->getAnyMember();
|
2010-11-16 15:52:17 +08:00
|
|
|
|
2011-01-13 20:30:12 +08:00
|
|
|
SVal FieldLoc = state->getLValue(FD, thisVal);
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal InitVal = state->getSVal(BMI->getInit(), Pred->getLocationContext());
|
2010-11-16 15:52:17 +08:00
|
|
|
state = state->bindLoc(FieldLoc, InitVal);
|
|
|
|
|
|
|
|
// Use a custom node building process.
|
2011-01-13 20:30:12 +08:00
|
|
|
PostInitializer PP(BMI, stackFrame);
|
2010-11-16 15:52:17 +08:00
|
|
|
// Builder automatically add the generated node to the deferred set,
|
|
|
|
// which are processed in the builder's dtor.
|
2011-10-25 05:19:48 +08:00
|
|
|
Bldr.generateNode(PP, P, state);
|
2010-11-16 15:52:17 +08:00
|
|
|
}
|
2011-10-25 05:19:48 +08:00
|
|
|
} else {
|
|
|
|
assert(BMI->isBaseInitializer());
|
|
|
|
|
|
|
|
// Get the base class declaration.
|
|
|
|
const CXXConstructExpr *ctorExpr = cast<CXXConstructExpr>(BMI->getInit());
|
|
|
|
|
|
|
|
// Create the base object region.
|
|
|
|
SVal baseVal =
|
|
|
|
getStoreManager().evalDerivedToBase(thisVal, ctorExpr->getType());
|
|
|
|
const MemRegion *baseReg = baseVal.getAsRegion();
|
|
|
|
assert(baseReg);
|
2011-01-13 20:30:12 +08:00
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
VisitCXXConstructExpr(ctorExpr, baseReg, Pred, Dst);
|
|
|
|
}
|
2011-10-27 08:59:23 +08:00
|
|
|
|
|
|
|
// Enqueue the new nodes onto the work list.
|
|
|
|
Engine.enqueue(Dst, currentBuilderContext->getBlock(), currentStmtIdx);
|
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:
|
2011-10-25 05:19:48 +08:00
|
|
|
ProcessAutomaticObjDtor(cast<CFGAutomaticObjDtor>(D), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::BaseDtor:
|
2011-10-25 05:19:48 +08:00
|
|
|
ProcessBaseDtor(cast<CFGBaseDtor>(D), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::MemberDtor:
|
2011-10-25 05:19:48 +08:00
|
|
|
ProcessMemberDtor(cast<CFGMemberDtor>(D), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
case CFGElement::TemporaryDtor:
|
2011-10-25 05:19:48 +08:00
|
|
|
ProcessTemporaryDtor(cast<CFGTemporaryDtor>(D), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected dtor kind.");
|
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2011-10-27 08:59:23 +08:00
|
|
|
// Enqueue the new nodes onto the work list.
|
|
|
|
Engine.enqueue(Dst, currentBuilderContext->getBlock(), currentStmtIdx);
|
2010-11-17 17:16:19 +08:00
|
|
|
}
|
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-10-25 05:19:48 +08:00
|
|
|
const VarDecl *varDecl = Dtor.getVarDecl();
|
2010-11-25 14:35:14 +08:00
|
|
|
|
|
|
|
QualType varType = varDecl->getType();
|
|
|
|
|
|
|
|
if (const ReferenceType *refType = varType->getAs<ReferenceType>())
|
|
|
|
varType = refType->getPointeeType();
|
|
|
|
|
|
|
|
const CXXRecordDecl *recordDecl = varType->getAsCXXRecordDecl();
|
|
|
|
assert(recordDecl && "get CXXRecordDecl fail");
|
|
|
|
const CXXDestructorDecl *dtorDecl = recordDecl->getDestructor();
|
2010-11-20 14:53:12 +08:00
|
|
|
|
2011-10-25 05:19:48 +08:00
|
|
|
Loc dest = state->getLValue(varDecl, Pred->getLocationContext());
|
2010-11-20 14:53:12 +08:00
|
|
|
|
2010-11-25 14:35:14 +08:00
|
|
|
VisitCXXDestructor(dtorDecl, cast<loc::MemRegionVal>(dest).getRegion(),
|
2011-10-25 05:19:48 +08:00
|
|
|
Dtor.getTriggerStmt(), Pred, Dst);
|
2010-11-17 17:16:19 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessBaseDtor(const CFGBaseDtor D,
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {}
|
2010-11-17 17:16:19 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessMemberDtor(const CFGMemberDtor D,
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {}
|
2010-11-17 17:16:19 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ProcessTemporaryDtor(const CFGTemporaryDtor D,
|
2011-10-25 05:19:48 +08:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {}
|
2010-11-15 16:48:43 +08:00
|
|
|
|
2011-08-13 07:37:29 +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;
|
|
|
|
StmtNodeBuilder Bldr(Pred, DstTop, *currentBuilderContext);
|
2009-03-11 10:41:36 +08:00
|
|
|
|
2010-12-04 11:47:34 +08:00
|
|
|
// Expressions to ignore.
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(S))
|
2010-12-16 15:46:53 +08:00
|
|
|
S = Ex->IgnoreParens();
|
2010-12-04 11:47:34 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
// FIXME: add metadata to the CFG so that we can disable
|
|
|
|
// this check when we KNOW that there is no block-level subexpression.
|
|
|
|
// The motivation is that this check requires a hashtable lookup.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
if (S != currentStmt && Pred->getLocationContext()->getCFG()->isBlkExpr(S))
|
2008-04-16 07:06:53 +08:00
|
|
|
return;
|
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::CXXCatchStmtClass:
|
|
|
|
case Stmt::CXXDependentScopeMemberExprClass:
|
|
|
|
case Stmt::CXXPseudoDestructorExprClass:
|
|
|
|
case Stmt::CXXThrowExprClass:
|
|
|
|
case Stmt::CXXTryStmtClass:
|
|
|
|
case Stmt::CXXTypeidExprClass:
|
2010-09-09 07:47:05 +08:00
|
|
|
case Stmt::CXXUuidofExprClass:
|
2009-12-15 09:38:04 +08:00
|
|
|
case Stmt::CXXUnresolvedConstructExprClass:
|
2010-07-08 14:14:04 +08:00
|
|
|
case Stmt::CXXScalarValueInitExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::DependentScopeDeclRefExprClass:
|
|
|
|
case Stmt::UnaryTypeTraitExprClass:
|
2010-12-07 08:08:36 +08:00
|
|
|
case Stmt::BinaryTypeTraitExprClass:
|
2012-02-24 15:38:34 +08:00
|
|
|
case Stmt::TypeTraitExprClass:
|
2011-04-28 08:16:57 +08:00
|
|
|
case Stmt::ArrayTypeTraitExprClass:
|
2011-04-25 14:54:41 +08:00
|
|
|
case Stmt::ExpressionTraitExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::UnresolvedLookupExprClass:
|
2009-12-15 09:38:04 +08:00
|
|
|
case Stmt::UnresolvedMemberExprClass:
|
2010-09-11 04:55:54 +08:00
|
|
|
case Stmt::CXXNoexceptExprClass:
|
2011-01-04 01:17:50 +08:00
|
|
|
case Stmt::PackExpansionExprClass:
|
2011-01-15 09:15:58 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmPackExprClass:
|
2011-04-28 09:08:34 +08:00
|
|
|
case Stmt::SEHTryStmtClass:
|
|
|
|
case Stmt::SEHExceptStmtClass:
|
2012-02-07 18:09:13 +08:00
|
|
|
case Stmt::LambdaExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
case Stmt::SEHFinallyStmtClass: {
|
|
|
|
const ExplodedNode *node = Bldr.generateNode(S, Pred, Pred->getState());
|
|
|
|
Engine.addAbortedBlock(node, currentBuilderContext->getBlock());
|
2009-12-15 09:38:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-09 06:42:35 +08:00
|
|
|
|
|
|
|
// We don't handle default arguments either yet, but we can fake it
|
|
|
|
// for now by just skipping them.
|
2011-07-15 13:09:51 +08:00
|
|
|
case Stmt::SubstNonTypeTemplateParmExprClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
case Stmt::CXXDefaultArgExprClass:
|
2011-04-09 06:42:35 +08:00
|
|
|
break;
|
|
|
|
|
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:
|
2010-04-16 01:33:31 +08:00
|
|
|
llvm_unreachable("Stmt should not be in analyzer evaluation loop");
|
|
|
|
|
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-01-25 08:04:03 +08:00
|
|
|
case Stmt::ObjCPropertyRefExprClass:
|
2011-08-20 14:23:25 +08:00
|
|
|
// Implicitly handled by Environment::getSVal().
|
2011-01-25 08:04:03 +08:00
|
|
|
break;
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
case Stmt::ImplicitValueInitExprClass: {
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2011-06-16 07:02:42 +08:00
|
|
|
QualType ty = cast<ImplicitValueInitExpr>(S)->getType();
|
|
|
|
SVal val = svalBuilder.makeZeroVal(ty);
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(S, Pred, state->BindExpr(S, Pred->getLocationContext(),
|
|
|
|
val));
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
case Stmt::ExprWithCleanupsClass:
|
|
|
|
Bldr.takeNodes(Pred);
|
2011-06-16 07:02:42 +08:00
|
|
|
Visit(cast<ExprWithCleanups>(S)->getSubExpr(), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
|
|
|
|
2010-04-16 01:33:31 +08:00
|
|
|
// Cases not handled yet; but will handle some day.
|
|
|
|
case Stmt::DesignatedInitExprClass:
|
|
|
|
case Stmt::ExtVectorElementExprClass:
|
|
|
|
case Stmt::ImaginaryLiteralClass:
|
|
|
|
case Stmt::ObjCAtCatchStmtClass:
|
|
|
|
case Stmt::ObjCAtFinallyStmtClass:
|
|
|
|
case Stmt::ObjCAtTryStmtClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Stmt::ObjCAutoreleasePoolStmtClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
case Stmt::ObjCEncodeExprClass:
|
|
|
|
case Stmt::ObjCIsaExprClass:
|
|
|
|
case Stmt::ObjCProtocolExprClass:
|
|
|
|
case Stmt::ObjCSelectorExprClass:
|
|
|
|
case Stmt::ParenListExprClass:
|
|
|
|
case Stmt::PredefinedExprClass:
|
|
|
|
case Stmt::ShuffleVectorExprClass:
|
|
|
|
case Stmt::VAArgExprClass:
|
2011-02-10 05:07:24 +08:00
|
|
|
case Stmt::CUDAKernelCallExprClass:
|
2011-02-17 18:25:35 +08:00
|
|
|
case Stmt::OpaqueValueExprClass:
|
2011-06-04 08:47:47 +08:00
|
|
|
case Stmt::AsTypeExprClass:
|
2011-10-11 10:20:01 +08:00
|
|
|
case Stmt::AtomicExprClass:
|
2010-04-16 01:33:31 +08:00
|
|
|
// Fall through.
|
|
|
|
|
|
|
|
// Cases we intentionally don't evaluate, since they don't need
|
|
|
|
// to be explicitly evaluated.
|
2010-04-13 21:15:19 +08:00
|
|
|
case Stmt::AddrLabelExprClass:
|
|
|
|
case Stmt::IntegerLiteralClass:
|
|
|
|
case Stmt::CharacterLiteralClass:
|
2010-04-14 14:29:29 +08:00
|
|
|
case Stmt::CXXBoolLiteralExprClass:
|
2010-04-13 21:15:19 +08:00
|
|
|
case Stmt::FloatingLiteralClass:
|
2011-01-05 02:46:34 +08:00
|
|
|
case Stmt::SizeOfPackExprClass:
|
2012-02-28 07:34:19 +08:00
|
|
|
case Stmt::StringLiteralClass:
|
|
|
|
case Stmt::ObjCStringLiteralClass:
|
2012-03-02 07:06:04 +08:00
|
|
|
case Stmt::CXXBindTemporaryExprClass:
|
2012-02-17 04:56:01 +08:00
|
|
|
case Stmt::CXXNullPtrLiteralExprClass: {
|
|
|
|
Bldr.takeNodes(Pred);
|
|
|
|
ExplodedNodeSet preVisit;
|
|
|
|
getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);
|
|
|
|
getCheckerManager().runCheckersForPostStmt(Dst, preVisit, S, *this);
|
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2012-02-17 04:56:01 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
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
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::AsmStmtClass:
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2008-04-16 07:06:53 +08:00
|
|
|
VisitAsmStmt(cast<AsmStmt>(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
|
|
|
|
2010-12-16 15:46:53 +08:00
|
|
|
case Stmt::BlockDeclRefExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
const BlockDeclRefExpr *BE = cast<BlockDeclRefExpr>(S);
|
|
|
|
VisitCommonDeclRefExpr(BE, BE->getDecl(), Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2009-12-08 06:05:27 +08:00
|
|
|
break;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
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);
|
|
|
|
|
2010-02-16 07:02:46 +08:00
|
|
|
if (AMgr.shouldEagerlyAssume() &&
|
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);
|
2010-12-02 05:57:22 +08:00
|
|
|
evalEagerlyAssume(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
|
|
|
|
2011-03-31 01:41:19 +08:00
|
|
|
case Stmt::CallExprClass:
|
|
|
|
case Stmt::CXXOperatorCallExprClass:
|
|
|
|
case Stmt::CXXMemberCallExprClass: {
|
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
|
|
|
}
|
2008-11-15 03:47:18 +08:00
|
|
|
|
2011-10-08 06:48:13 +08:00
|
|
|
case Stmt::CXXTemporaryObjectExprClass:
|
2010-11-01 17:09:44 +08:00
|
|
|
case Stmt::CXXConstructExprClass: {
|
|
|
|
const CXXConstructExpr *C = cast<CXXConstructExpr>(S);
|
|
|
|
// For block-level CXXConstructExpr, we don't have a destination region.
|
|
|
|
// Let VisitCXXConstructExpr() create one.
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-12-16 15:46:53 +08:00
|
|
|
VisitCXXConstructExpr(C, 0, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2010-11-01 17:09:44 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-19 19:47:28 +08:00
|
|
|
case Stmt::CXXNewExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-07-20 14:22:24 +08:00
|
|
|
const CXXNewExpr *NE = cast<CXXNewExpr>(S);
|
2010-04-19 19:47:28 +08:00
|
|
|
VisitCXXNewExpr(NE, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2010-04-19 19:47:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 10:17:31 +08:00
|
|
|
case Stmt::CXXDeleteExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2010-07-20 14:22:24 +08:00
|
|
|
const CXXDeleteExpr *CDE = cast<CXXDeleteExpr>(S);
|
2010-04-21 10:17:31 +08:00
|
|
|
VisitCXXDeleteExpr(CDE, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2010-04-21 10:17:31 +08:00
|
|
|
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);
|
2011-06-22 01:03:29 +08:00
|
|
|
const MaterializeTemporaryExpr *Materialize
|
|
|
|
= cast<MaterializeTemporaryExpr>(S);
|
|
|
|
if (!Materialize->getType()->isRecordType())
|
2011-07-29 07:07:36 +08:00
|
|
|
CreateCXXTemporaryObject(Materialize, Pred, Dst);
|
2011-06-22 01:03:29 +08:00
|
|
|
else
|
|
|
|
Visit(Materialize->GetTemporaryExpr(), 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-02-19 04:53:30 +08:00
|
|
|
case Stmt::ObjCMessageExprClass: {
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2012-02-19 04:53:30 +08:00
|
|
|
// Is this a property access?
|
|
|
|
const ParentMap &PM = Pred->getLocationContext()->getParentMap();
|
|
|
|
const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(S);
|
|
|
|
bool evaluated = false;
|
|
|
|
|
|
|
|
if (const PseudoObjectExpr *PO =
|
|
|
|
dyn_cast_or_null<PseudoObjectExpr>(PM.getParent(S))) {
|
|
|
|
const Expr *syntactic = PO->getSyntacticForm();
|
|
|
|
if (const ObjCPropertyRefExpr *PR =
|
|
|
|
dyn_cast<ObjCPropertyRefExpr>(syntactic)) {
|
|
|
|
bool isSetter = ME->getNumArgs() > 0;
|
|
|
|
VisitObjCMessage(ObjCMessage(ME, PR, isSetter), Pred, Dst);
|
|
|
|
evaluated = true;
|
|
|
|
}
|
|
|
|
else if (isa<BinaryOperator>(syntactic)) {
|
|
|
|
VisitObjCMessage(ObjCMessage(ME, 0, true), Pred, Dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!evaluated)
|
|
|
|
VisitObjCMessage(ME, Pred, Dst);
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2008-04-16 07:06:53 +08:00
|
|
|
break;
|
2012-02-19 04:53:30 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-10 04:18:58 +08:00
|
|
|
case Stmt::ObjCAtThrowStmtClass: {
|
|
|
|
// FIXME: This is not complete. We basically treat @throw as
|
|
|
|
// an abort.
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(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);
|
2011-10-25 02:26:19 +08:00
|
|
|
if (AMgr.shouldEagerlyAssume() && (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);
|
2010-12-02 05:57:22 +08:00
|
|
|
evalEagerlyAssume(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
/// Block entrance. (Update counters).
|
|
|
|
void ExprEngine::processCFGBlockEntrance(NodeBuilderWithSinks &nodeBuilder) {
|
2011-01-11 14:37:47 +08:00
|
|
|
|
|
|
|
// FIXME: Refactor this into a checker.
|
2011-10-27 05:06:22 +08:00
|
|
|
ExplodedNode *pred = nodeBuilder.getContext().getPred();
|
2011-01-11 14:37:47 +08:00
|
|
|
|
2011-10-27 05:06:22 +08:00
|
|
|
if (nodeBuilder.getContext().getCurrentBlockCount() >= AMgr.getMaxVisit()) {
|
2011-08-13 07:04:46 +08:00
|
|
|
static SimpleProgramPointTag tag("ExprEngine : Block count exceeded");
|
2011-01-12 00:53:44 +08:00
|
|
|
nodeBuilder.generateNode(pred->getState(), pred, &tag, true);
|
2011-01-11 14:37:47 +08:00
|
|
|
}
|
2008-04-16 07:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch processing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef ExprEngine::MarkBranch(ProgramStateRef state,
|
2012-01-07 06:09:28 +08:00
|
|
|
const Stmt *Terminator,
|
|
|
|
const LocationContext *LCtx,
|
|
|
|
bool branchTaken) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
switch (Terminator->getStmtClass()) {
|
|
|
|
default:
|
2009-02-13 09:45:31 +08:00
|
|
|
return state;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
case Stmt::BinaryOperatorClass: { // '&&' and '||'
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
const BinaryOperator* B = cast<BinaryOperator>(Terminator);
|
2008-02-27 03:05:15 +08:00
|
|
|
BinaryOperator::Opcode Op = B->getOpcode();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-25 19:45:40 +08:00
|
|
|
assert (Op == BO_LAnd || Op == BO_LOr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
// For &&, if we take the true branch, then the value of the whole
|
|
|
|
// expression is that of the RHS expression.
|
|
|
|
//
|
|
|
|
// For ||, if we take the false branch, then the value of the whole
|
|
|
|
// expression is that of the RHS expression.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const Expr *Ex = (Op == BO_LAnd && branchTaken) ||
|
2010-08-25 19:45:40 +08:00
|
|
|
(Op == BO_LOr && !branchTaken)
|
2010-07-20 14:22:24 +08:00
|
|
|
? B->getRHS() : B->getLHS();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
return state->BindExpr(B, LCtx, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
case Stmt::BinaryConditionalOperatorClass:
|
2008-02-27 03:05:15 +08:00
|
|
|
case Stmt::ConditionalOperatorClass: { // ?:
|
2011-02-17 18:25:35 +08:00
|
|
|
const AbstractConditionalOperator* C
|
|
|
|
= cast<AbstractConditionalOperator>(Terminator);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
// For ?, if branchTaken == true then the value is either the LHS or
|
|
|
|
// the condition itself. (GNU extension).
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const Expr *Ex;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
if (branchTaken)
|
2011-02-17 18:25:35 +08:00
|
|
|
Ex = C->getTrueExpr();
|
2008-02-27 03:05:15 +08:00
|
|
|
else
|
2011-02-17 18:25:35 +08:00
|
|
|
Ex = C->getFalseExpr();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
return state->BindExpr(C, LCtx, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
case Stmt::ChooseExprClass: { // ?:
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const ChooseExpr *C = cast<ChooseExpr>(Terminator);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const Expr *Ex = branchTaken ? C->getLHS() : C->getRHS();
|
2012-01-07 06:09:28 +08:00
|
|
|
return state->BindExpr(C, LCtx, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
/// RecoverCastedSymbol - A helper function for ProcessBranch that is used
|
|
|
|
/// to try to recover some path-sensitivity for casts of symbolic
|
|
|
|
/// integers that promote their values (which are currently not tracked well).
|
|
|
|
/// This function returns the SVal bound to Condition->IgnoreCasts if all the
|
|
|
|
// cast(s) did was sign-extend the original value.
|
2011-08-20 14:00:03 +08:00
|
|
|
static SVal RecoverCastedSymbol(ProgramStateManager& StateMgr,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state,
|
2011-08-20 14:00:03 +08:00
|
|
|
const Stmt *Condition,
|
2012-01-07 06:09:28 +08:00
|
|
|
const LocationContext *LCtx,
|
2011-08-20 14:00:03 +08:00
|
|
|
ASTContext &Ctx) {
|
2009-03-14 00:32:54 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
const Expr *Ex = dyn_cast<Expr>(Condition);
|
2009-03-14 00:32:54 +08:00
|
|
|
if (!Ex)
|
|
|
|
return UnknownVal();
|
|
|
|
|
|
|
|
uint64_t bits = 0;
|
|
|
|
bool bitsInit = false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
while (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) {
|
2009-03-14 00:32:54 +08:00
|
|
|
QualType T = CE->getType();
|
|
|
|
|
|
|
|
if (!T->isIntegerType())
|
|
|
|
return UnknownVal();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
uint64_t newBits = Ctx.getTypeSize(T);
|
|
|
|
if (!bitsInit || newBits < bits) {
|
|
|
|
bitsInit = true;
|
|
|
|
bits = newBits;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-14 00:32:54 +08:00
|
|
|
Ex = CE->getSubExpr();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We reached a non-cast. Is it a symbolic value?
|
|
|
|
QualType T = Ex->getType();
|
|
|
|
|
|
|
|
if (!bitsInit || !T->isIntegerType() || Ctx.getTypeSize(T) > bits)
|
|
|
|
return UnknownVal();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
return state->getSVal(Ex, LCtx);
|
2009-03-14 00:32:54 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-10-26 03:56:54 +08:00
|
|
|
currentBuilderContext = &BldCtx;
|
|
|
|
|
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
|
|
|
|
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-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef PrevState = Pred->getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal X = PrevState->getSVal(Condition, Pred->getLocationContext());
|
2011-10-19 07:06:21 +08:00
|
|
|
|
|
|
|
if (X.isUnknownOrUndef()) {
|
|
|
|
// Give it a chance to recover from unknown.
|
|
|
|
if (const Expr *Ex = dyn_cast<Expr>(Condition)) {
|
|
|
|
if (Ex->getType()->isIntegerType()) {
|
|
|
|
// Try to recover some path-sensitivity. Right now casts of symbolic
|
|
|
|
// integers that promote their values are currently not tracked well.
|
|
|
|
// If 'Condition' is such an expression, try and recover the
|
|
|
|
// underlying value and use that instead.
|
|
|
|
SVal recovered = RecoverCastedSymbol(getStateManager(),
|
|
|
|
PrevState, Condition,
|
2012-01-07 06:09:28 +08:00
|
|
|
Pred->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
|
|
|
|
|
|
|
const LocationContext *LCtx = PredI->getLocationContext();
|
|
|
|
|
2009-11-23 11:20:54 +08:00
|
|
|
// If the condition is still unknown, give up.
|
2011-02-28 09:27:57 +08:00
|
|
|
if (X.isUnknownOrUndef()) {
|
2012-01-07 06:09:28 +08:00
|
|
|
builder.generateNode(MarkBranch(PrevState, Term, LCtx, true),
|
|
|
|
true, PredI);
|
|
|
|
builder.generateNode(MarkBranch(PrevState, Term, LCtx, false),
|
|
|
|
false, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
continue;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
DefinedSVal V = cast<DefinedSVal>(X);
|
2009-11-23 11:20:54 +08:00
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
// Process the true branch.
|
|
|
|
if (builder.isFeasible(true)) {
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef state = PrevState->assume(V, true))
|
2012-01-07 06:09:28 +08:00
|
|
|
builder.generateNode(MarkBranch(state, Term, LCtx, true),
|
|
|
|
true, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(true);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-19 07:06:21 +08:00
|
|
|
// Process the false branch.
|
|
|
|
if (builder.isFeasible(false)) {
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef state = PrevState->assume(V, false))
|
2012-01-07 06:09:28 +08:00
|
|
|
builder.generateNode(MarkBranch(state, Term, LCtx, false),
|
|
|
|
false, PredI);
|
2011-10-19 07:06:21 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(false);
|
|
|
|
}
|
|
|
|
}
|
2011-10-26 03:56:54 +08:00
|
|
|
currentBuilderContext = 0;
|
2008-02-05 08:26:40 +08:00
|
|
|
}
|
|
|
|
|
2011-01-11 10:34:45 +08:00
|
|
|
/// processIndirectGoto - Called by CoreEngine. Used to generate successor
|
2008-02-13 08:24:44 +08:00
|
|
|
/// nodes by processing the 'effects' of a computed goto jump.
|
2011-02-17 15:39:24 +08:00
|
|
|
void ExprEngine::processIndirectGoto(IndirectGotoNodeBuilder &builder) {
|
2008-02-13 08:24:44 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = builder.getState();
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal V = state->getSVal(builder.getTarget(), builder.getLocationContext());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
// Three possibilities:
|
|
|
|
//
|
|
|
|
// (1) We know the computed label.
|
2008-02-28 17:25:22 +08:00
|
|
|
// (2) The label is NULL (or some other constant), or Undefined.
|
2008-02-13 08:24:44 +08:00
|
|
|
// (3) We have no clue about the label. Dispatch to all targets.
|
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
typedef IndirectGotoNodeBuilder::iterator iterator;
|
2008-02-13 08:24:44 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (isa<loc::GotoLabel>(V)) {
|
2011-02-17 15:39:24 +08:00
|
|
|
const LabelDecl *L = cast<loc::GotoLabel>(V).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
|
|
|
}
|
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (isa<loc::ConcreteInt>(V) || isa<UndefinedVal>(V)) {
|
2008-02-13 08:24:44 +08:00
|
|
|
// Dispatch to the first target and mark it as a sink.
|
2009-11-24 15:06:39 +08:00
|
|
|
//ExplodedNode* N = builder.generateNode(builder.begin(), state, true);
|
|
|
|
// FIXME: add checker visit.
|
|
|
|
// UndefBranches.insert(N);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
// This is really a catch-all. We don't support symbolics yet.
|
2009-04-24 01:49:43 +08:00
|
|
|
// FIXME: Implement dispatch for symbolic pointers.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-13 08:24:44 +08:00
|
|
|
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I)
|
2009-02-13 09:45:31 +08:00
|
|
|
builder.generateNode(I, state);
|
2008-02-13 08:24:44 +08:00
|
|
|
}
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
/// ProcessEndPath - Called by CoreEngine. Used to generate end-of-path
|
2009-11-14 09:05:20 +08:00
|
|
|
/// nodes when the control reaches the end of a function.
|
2011-10-26 03:56:48 +08:00
|
|
|
void ExprEngine::processEndOfFunction(NodeBuilderContext& BC) {
|
|
|
|
StateMgr.EndPath(BC.Pred->getState());
|
|
|
|
ExplodedNodeSet Dst;
|
|
|
|
getCheckerManager().runCheckersForEndPath(BC, Dst, *this);
|
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;
|
|
|
|
}
|
2009-09-12 06:07:28 +08:00
|
|
|
DefinedOrUnknownSVal CondV = cast<DefinedOrUnknownSVal>(CondV_untested);
|
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.
|
2008-10-17 13:57:07 +08:00
|
|
|
if (isa<nonloc::ConcreteInt>(CondV))
|
2008-02-14 07:08:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
// Now "assume" that the case doesn't match. Add this state
|
|
|
|
// to the default state (if it is feasible).
|
2010-01-09 02:54:04 +08:00
|
|
|
if (DefaultSt) {
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef stateNew = DefaultSt->assume(Res, false)) {
|
2010-01-09 02:54:04 +08:00
|
|
|
defaultIsFeasible = true;
|
|
|
|
DefaultSt = stateNew;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
defaultIsFeasible = false;
|
|
|
|
DefaultSt = NULL;
|
|
|
|
}
|
2008-04-23 13:03:18 +08:00
|
|
|
}
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
// Concretize the next value in the range.
|
2011-10-15 04:22:00 +08:00
|
|
|
if (V1 == V2)
|
2008-03-18 06:17:56 +08:00
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-15 04:22:00 +08:00
|
|
|
++V1;
|
|
|
|
assert (V1 <= V2);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
} while (true);
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-09-09 08:40:40 +08:00
|
|
|
if (!defaultIsFeasible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we have switch(enum value), the default branch is not
|
|
|
|
// feasible if all of the enum constants not covered by 'case:' statements
|
|
|
|
// are not feasible values for the switch condition.
|
|
|
|
//
|
|
|
|
// Note that this isn't as accurate as it could be. Even if there isn't
|
|
|
|
// a case for a particular enum value as long as that enum value isn't
|
|
|
|
// feasible then it shouldn't be considered for making 'default:' reachable.
|
|
|
|
const SwitchStmt *SS = builder.getSwitch();
|
|
|
|
const Expr *CondExpr = SS->getCond()->IgnoreParenImpCasts();
|
|
|
|
if (CondExpr->getType()->getAs<EnumType>()) {
|
|
|
|
if (SS->isAllEnumCasesCovered())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.generateDefaultCaseNode(DefaultSt);
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-04-17 02:39:06 +08:00
|
|
|
// Transfer functions: Loads and stores.
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-01-16 07:55:06 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, const NamedDecl *D,
|
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currentBuilderContext);
|
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)) {
|
2010-12-16 15:46:53 +08:00
|
|
|
assert(Ex->isLValue());
|
2009-08-22 06:28:32 +08:00
|
|
|
SVal V = state->getLValue(VD, Pred->getLocationContext());
|
2008-10-17 10:20:14 +08:00
|
|
|
|
2010-12-16 15:46:53 +08:00
|
|
|
// For references, the 'lvalue' is the pointer address stored in the
|
|
|
|
// reference region.
|
|
|
|
if (VD->getType()->isReferenceType()) {
|
|
|
|
if (const MemRegion *R = V.getAsRegion())
|
|
|
|
V = state->getSVal(R);
|
|
|
|
else
|
|
|
|
V = UnknownVal();
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
}
|
2008-10-16 14:09:51 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), false, 0,
|
2011-10-25 02:26:19 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
return;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) {
|
2010-12-16 15:46:53 +08:00
|
|
|
assert(!Ex->isLValue());
|
2010-12-02 15:49:45 +08:00
|
|
|
SVal V = svalBuilder.makeIntVal(ED->getInitVal());
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V));
|
2008-10-16 14:09:51 +08:00
|
|
|
return;
|
2010-12-16 15:46:53 +08:00
|
|
|
}
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
2010-12-02 15:49:45 +08:00
|
|
|
SVal V = svalBuilder.getFunctionPointer(FD);
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), false, 0,
|
2011-10-25 02:26:19 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
2008-10-16 14:09:51 +08:00
|
|
|
return;
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
2008-10-16 14:09:51 +08:00
|
|
|
assert (false &&
|
|
|
|
"ValueDecl support for this ValueDecl 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);
|
|
|
|
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(checkerPreStmt, Dst, *currentBuilderContext);
|
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));
|
2011-07-30 05:18:17 +08:00
|
|
|
assert(A->isLValue());
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(A, *it, state->BindExpr(A, LCtx, V),
|
2011-10-25 02:26:19 +08:00
|
|
|
false, 0, ProgramPoint::PostLValueKind);
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
2008-04-22 12:56:29 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
/// VisitMemberExpr - Transfer function for member expressions.
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
|
2011-11-02 06:41:09 +08:00
|
|
|
ExplodedNodeSet &TopDst) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-02 06:41:09 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, TopDst, *currentBuilderContext);
|
|
|
|
ExplodedNodeSet Dst;
|
2011-08-17 05:37:52 +08:00
|
|
|
Decl *member = M->getMemberDecl();
|
|
|
|
if (VarDecl *VD = dyn_cast<VarDecl>(member)) {
|
|
|
|
assert(M->isLValue());
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.takeNodes(Pred);
|
2011-08-17 05:37:52 +08:00
|
|
|
VisitCommonDeclRefExpr(M, VD, Pred, Dst);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
2011-08-17 05:37:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldDecl *field = dyn_cast<FieldDecl>(member);
|
2010-12-16 15:46:53 +08:00
|
|
|
if (!field) // FIXME: skipping member expressions for non-fields
|
2008-12-21 07:49:58 +08:00
|
|
|
return;
|
|
|
|
|
2011-07-30 05:18:19 +08:00
|
|
|
Expr *baseExpr = M->getBase()->IgnoreParens();
|
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();
|
|
|
|
SVal baseExprVal = state->getSVal(baseExpr, Pred->getLocationContext());
|
2011-07-30 05:18:19 +08:00
|
|
|
if (isa<nonloc::LazyCompoundVal>(baseExprVal) ||
|
|
|
|
isa<nonloc::CompoundVal>(baseExprVal) ||
|
|
|
|
// FIXME: This can originate by conjuring a symbol for an unknown
|
|
|
|
// temporary struct object, see test/Analysis/fields.c:
|
|
|
|
// (p = getit()).x
|
|
|
|
isa<nonloc::SymbolVal>(baseExprVal)) {
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(M, Pred, state->BindExpr(M, LCtx, UnknownVal()));
|
2011-07-30 05:18:19 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-12-16 15:46:53 +08:00
|
|
|
|
2011-07-30 05:18:19 +08:00
|
|
|
// FIXME: Should we insert some assumption logic in here to determine
|
|
|
|
// if "Base" is a valid piece of memory? Before we put this assumption
|
|
|
|
// later when using FieldOffset lvals (which we no longer have).
|
2008-10-17 08:51:01 +08:00
|
|
|
|
2011-07-30 05:18:19 +08:00
|
|
|
// For all other cases, compute an lvalue.
|
|
|
|
SVal L = state->getLValue(field, baseExprVal);
|
|
|
|
if (M->isLValue())
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(M, Pred, state->BindExpr(M, LCtx, L), false, 0,
|
2011-10-25 02:26:19 +08:00
|
|
|
ProgramPoint::PostLValueKind);
|
|
|
|
else {
|
|
|
|
Bldr.takeNodes(Pred);
|
2011-07-30 05:18:19 +08:00
|
|
|
evalLoad(Dst, M, Pred, state, L);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.addNodes(Dst);
|
|
|
|
}
|
2008-04-22 07:43:38 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2011-10-25 02:26:19 +08:00
|
|
|
SVal location, SVal Val, bool atDeclInit,
|
|
|
|
ProgramPoint::Kind PointKind) {
|
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,
|
2011-10-25 02:26:19 +08:00
|
|
|
StoreE, *this, PointKind);
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2011-10-25 02:26:12 +08:00
|
|
|
// TODO:AZ Remove TmpDst after NB refactoring is done.
|
2011-10-25 02:26:08 +08:00
|
|
|
ExplodedNodeSet TmpDst;
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(CheckedSet, TmpDst, *currentBuilderContext);
|
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-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = (*I)->getState();
|
2009-02-13 09:45:31 +08:00
|
|
|
|
2009-11-04 12:24:16 +08:00
|
|
|
if (atDeclInit) {
|
|
|
|
const VarRegion *VR =
|
|
|
|
cast<VarRegion>(cast<loc::MemRegionVal>(location).getRegion());
|
2009-11-04 08:09:15 +08:00
|
|
|
|
2011-08-28 13:54:23 +08:00
|
|
|
state = state->bindDecl(VR, Val);
|
|
|
|
} else {
|
|
|
|
state = state->bindLoc(location, Val);
|
2009-11-04 08:09:15 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(StoreE, *I, state, false, 0, PointKind);
|
2009-11-04 12:24:16 +08:00
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
|
2011-10-25 02:26:08 +08:00
|
|
|
Dst.insert(TmpDst);
|
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
|
2010-09-02 09:56:39 +08:00
|
|
|
/// @param AssignE The assignment expression if the store happens in an
|
|
|
|
/// assignment.
|
|
|
|
/// @param LocatioinE 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;
|
|
|
|
|
|
|
|
if (isa<loc::ObjCPropRef>(location)) {
|
2012-02-19 04:53:30 +08:00
|
|
|
assert(false);
|
2011-01-25 08:04:03 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2010-12-02 05:57:22 +08:00
|
|
|
evalLocation(Tmp, 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)
|
2011-10-25 02:26:19 +08:00
|
|
|
evalBind(Dst, StoreE, *NI, location, Val, false,
|
|
|
|
ProgramPoint::PostStoreKind);
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::evalLoad(ExplodedNodeSet &Dst, const Expr *Ex,
|
|
|
|
ExplodedNode *Pred,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state, SVal location,
|
2011-08-13 07:04:46 +08:00
|
|
|
const ProgramPointTag *tag, QualType LoadTy) {
|
2010-11-24 09:47:11 +08:00
|
|
|
assert(!isa<NonLoc>(location) && "location cannot be a NonLoc.");
|
2008-04-30 05:04:26 +08:00
|
|
|
|
2011-01-25 08:04:03 +08:00
|
|
|
if (isa<loc::ObjCPropRef>(location)) {
|
2012-02-19 04:53:30 +08:00
|
|
|
assert(false);
|
2011-01-25 08:04:03 +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
|
|
|
// Are we loading from a region? This actually results in two loads; one
|
|
|
|
// to fetch the address of the referenced value and one to fetch the
|
|
|
|
// referenced value.
|
2011-08-13 04:02:48 +08:00
|
|
|
if (const TypedValueRegion *TR =
|
|
|
|
dyn_cast_or_null<TypedValueRegion>(location.getAsRegion())) {
|
2010-02-16 07:02:46 +08:00
|
|
|
|
2010-08-11 14:10:55 +08:00
|
|
|
QualType ValTy = TR->getValueType();
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
if (const ReferenceType *RT = ValTy->getAs<ReferenceType>()) {
|
2011-08-13 07:04:46 +08:00
|
|
|
static SimpleProgramPointTag
|
|
|
|
loadReferenceTag("ExprEngine : Load Reference");
|
Add (initial?) static analyzer support for handling C++ references.
This change was a lot bigger than I originally anticipated; among
other things it requires us storing more information in the CFG to
record what block-level expressions need to be evaluated as lvalues.
The big change is that CFGBlocks no longer contain Stmt*'s by
CFGElements. Currently CFGElements just wrap Stmt*, but they also
store a bit indicating whether the block-level expression should be
evalauted as an lvalue. DeclStmts involving the initialization of a
reference require us treating the initialization expression as an
lvalue, even though that information isn't recorded in the AST.
Conceptually this change isn't that complicated, but it required
bubbling up the data through the CFGBuilder, to GRCoreEngine, and
eventually to GRExprEngine.
The addition of CFGElement is also useful for when we want to handle
more control-flow constructs or other data we want to keep in the CFG
that isn't represented well with just a block of statements.
In GRExprEngine, this patch introduces logic for evaluating the
lvalues of references, which currently retrieves the internal "pointer
value" that the reference represents. EvalLoad does a two stage load
to catch null dereferences involving an invalid reference (although
this could possibly be caught earlier during the initialization of a
reference).
Symbols are currently symbolicated using the reference type, instead
of a pointer type, and special handling is required creating
ElementRegions that layer on SymbolicRegions (see the changes to
RegionStoreManager).
Along the way, the DeadStoresChecker also silences warnings involving
dead stores to references. This was the original change I introduced
(which I wrote test cases for) that I realized caused GRExprEngine to
crash.
llvm-svn: 91501
2009-12-16 11:18:58 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2010-12-02 05:57:22 +08:00
|
|
|
evalLoadCommon(Tmp, Ex, 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-01-07 06:09:28 +08:00
|
|
|
location = state->getSVal(Ex, (*I)->getLocationContext());
|
2010-12-02 05:57:22 +08:00
|
|
|
evalLoadCommon(Dst, Ex, *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
|
|
|
|
2010-12-02 05:57:22 +08:00
|
|
|
evalLoadCommon(Dst, Ex, 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
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::evalLoadCommon(ExplodedNodeSet &Dst, const Expr *Ex,
|
|
|
|
ExplodedNode *Pred,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state, SVal location,
|
2011-08-13 07:04:46 +08:00
|
|
|
const ProgramPointTag *tag, QualType LoadTy) {
|
2010-02-16 07:02:46 +08:00
|
|
|
|
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;
|
2010-12-02 05:57:22 +08:00
|
|
|
evalLocation(Tmp, Ex, 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
|
|
|
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Tmp, Dst, *currentBuilderContext);
|
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
|
|
|
|
2009-11-11 11:26:34 +08:00
|
|
|
if (location.isUnknown()) {
|
|
|
|
// This is important. We must nuke the old binding.
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, *NI, state->BindExpr(Ex, LCtx, UnknownVal()),
|
2011-10-25 02:26:19 +08:00
|
|
|
false, tag, ProgramPoint::PostLoadKind);
|
2009-11-11 11:26:34 +08:00
|
|
|
}
|
|
|
|
else {
|
2010-09-09 15:13:00 +08:00
|
|
|
if (LoadTy.isNull())
|
|
|
|
LoadTy = Ex->getType();
|
|
|
|
SVal V = state->getSVal(cast<Loc>(location), LoadTy);
|
2012-01-07 06:09:28 +08:00
|
|
|
Bldr.generateNode(Ex, *NI, state->bindExprAndLocation(Ex, LCtx,
|
|
|
|
location, V),
|
2011-10-25 02:26:19 +08:00
|
|
|
false, tag, ProgramPoint::PostLoadKind);
|
2009-11-11 11:26:34 +08:00
|
|
|
}
|
2008-11-28 16:34:30 +08:00
|
|
|
}
|
2008-04-30 05:04:26 +08:00
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::evalLocation(ExplodedNodeSet &Dst, const Stmt *S,
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *Pred,
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state, SVal location,
|
2011-08-13 07:04:46 +08:00
|
|
|
const ProgramPointTag *tag, bool isLoad) {
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder BldrTop(Pred, Dst, *currentBuilderContext);
|
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);
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Src, *currentBuilderContext);
|
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
|
|
|
|
|
|
|
// FIXME: why is 'tag' not used instead of etag?
|
|
|
|
static SimpleProgramPointTag etag("ExprEngine: Location");
|
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(S, Pred, state, false, &etag);
|
2009-11-03 07:19:29 +08:00
|
|
|
}
|
2011-10-25 02:26:19 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
|
|
|
getCheckerManager().runCheckersForLocation(Tmp, Src, location, isLoad, S,
|
2011-03-01 09:16:03 +08:00
|
|
|
*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*>
|
|
|
|
ExprEngine::getEagerlyAssumeTags() {
|
|
|
|
static SimpleProgramPointTag
|
|
|
|
EagerlyAssumeTrue("ExprEngine : Eagerly Assume True"),
|
|
|
|
EagerlyAssumeFalse("ExprEngine : Eagerly Assume False");
|
|
|
|
return std::make_pair(&EagerlyAssumeTrue, &EagerlyAssumeFalse);
|
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::evalEagerlyAssume(ExplodedNodeSet &Dst, ExplodedNodeSet &Src,
|
2011-11-02 06:41:19 +08:00
|
|
|
const Expr *Ex) {
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Src, Dst, *currentBuilderContext);
|
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();
|
2009-02-26 07:32:10 +08:00
|
|
|
if (!isa<PostStmt>(P) || cast<PostStmt>(P).getStmt() != Ex) {
|
|
|
|
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());
|
2011-12-06 02:58:30 +08:00
|
|
|
nonloc::SymbolVal *SEV = dyn_cast<nonloc::SymbolVal>(&V);
|
|
|
|
if (SEV && SEV->isExpression()) {
|
2011-08-16 09:53:39 +08:00
|
|
|
const std::pair<const ProgramPointTag *, const ProgramPointTag*> &tags =
|
|
|
|
getEagerlyAssumeTags();
|
|
|
|
|
2009-02-26 06:32:02 +08:00
|
|
|
// First assume that the condition is true.
|
2012-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef StateTrue = state->assume(*SEV, true)) {
|
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);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, StateTrue, false, 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-01-27 05:29:00 +08:00
|
|
|
if (ProgramStateRef StateFalse = state->assume(*SEV, false)) {
|
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);
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(Ex, Pred, StateFalse, false, tags.second);
|
2009-02-26 06:32:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitAsmStmt(const AsmStmt *A, ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2008-03-18 05:11:24 +08:00
|
|
|
VisitAsmStmtHelperOutputs(A, A->begin_outputs(), A->end_outputs(), Pred, Dst);
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2008-03-18 05:11:24 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitAsmStmtHelperOutputs(const AsmStmt *A,
|
2010-07-20 14:22:24 +08:00
|
|
|
AsmStmt::const_outputs_iterator I,
|
|
|
|
AsmStmt::const_outputs_iterator E,
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *Pred, ExplodedNodeSet &Dst) {
|
2008-03-18 05:11:24 +08:00
|
|
|
if (I == E) {
|
|
|
|
VisitAsmStmtHelperInputs(A, A->begin_inputs(), A->end_inputs(), Pred, Dst);
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2010-12-16 15:46:53 +08:00
|
|
|
Visit(*I, Pred, Tmp);
|
2008-03-18 05:11:24 +08:00
|
|
|
++I;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-16 19:27:52 +08:00
|
|
|
for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end();NI != NE;++NI)
|
2008-03-18 05:11:24 +08:00
|
|
|
VisitAsmStmtHelperOutputs(A, I, E, *NI, Dst);
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void ExprEngine::VisitAsmStmtHelperInputs(const AsmStmt *A,
|
2010-07-20 14:22:24 +08:00
|
|
|
AsmStmt::const_inputs_iterator I,
|
|
|
|
AsmStmt::const_inputs_iterator E,
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *Pred,
|
|
|
|
ExplodedNodeSet &Dst) {
|
2008-03-18 05:11:24 +08:00
|
|
|
if (I == E) {
|
2011-10-25 05:19:59 +08:00
|
|
|
StmtNodeBuilder Bldr(Pred, Dst, *currentBuilderContext);
|
2008-03-18 05:11:24 +08:00
|
|
|
// We have processed both the inputs and the outputs. All of the outputs
|
2008-10-17 13:57:07 +08:00
|
|
|
// should evaluate to Locs. Nuke all of their values.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-18 05:11:24 +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-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = Pred->getState();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-20 14:22:24 +08:00
|
|
|
for (AsmStmt::const_outputs_iterator OI = A->begin_outputs(),
|
2008-03-18 05:11:24 +08:00
|
|
|
OE = A->end_outputs(); OI != OE; ++OI) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-07 06:09:28 +08:00
|
|
|
SVal X = state->getSVal(*OI, Pred->getLocationContext());
|
2008-10-17 13:57:07 +08:00
|
|
|
assert (!isa<NonLoc>(X)); // Should be an Lval, or unknown, undef.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-10-17 13:57:07 +08:00
|
|
|
if (isa<Loc>(X))
|
2009-06-20 01:10:32 +08:00
|
|
|
state = state->bindLoc(cast<Loc>(X), UnknownVal());
|
2008-03-18 05:11:24 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-25 02:26:19 +08:00
|
|
|
Bldr.generateNode(A, Pred, state);
|
2008-03-18 05:11:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
ExplodedNodeSet Tmp;
|
2008-03-18 05:11:24 +08:00
|
|
|
Visit(*I, Pred, Tmp);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-18 05:11:24 +08:00
|
|
|
++I;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-03 11:02:58 +08:00
|
|
|
for (ExplodedNodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI!=NE; ++NI)
|
2008-03-18 05:11:24 +08:00
|
|
|
VisitAsmStmtHelperInputs(A, I, E, *NI, Dst);
|
|
|
|
}
|
|
|
|
|
2009-10-31 01:47:32 +08:00
|
|
|
|
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
|
|
|
|
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()) {
|
|
|
|
case ProgramPoint::BlockEntranceKind:
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "Block Entrance: B"
|
2008-01-17 05:46:15 +08:00
|
|
|
<< cast<BlockEntrance>(Loc).getBlock()->getBlockID();
|
|
|
|
break;
|
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;
|
|
|
|
|
|
|
|
case ProgramPoint::CallExitKind:
|
|
|
|
Out << "CallExit";
|
|
|
|
break;
|
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
default: {
|
2009-07-23 06:35:28 +08:00
|
|
|
if (StmtPoint *L = dyn_cast<StmtPoint>(&Loc)) {
|
2011-08-13 07:37:29 +08:00
|
|
|
const Stmt *S = L->getStmt();
|
2008-12-17 06:02:27 +08:00
|
|
|
SourceLocation SLoc = S->getLocStart();
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << S->getStmtClassName() << ' ' << (void*) S << ' ';
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
S->printPretty(Out, 0, PrintingPolicy(LO));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
if (SLoc.isFileID()) {
|
2008-12-17 06:02:27 +08:00
|
|
|
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)
|
2009-02-04 08:55:58 +08:00
|
|
|
<< "\\l";
|
2008-12-17 06:02:27 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-23 06:35:28 +08:00
|
|
|
if (isa<PreStmt>(Loc))
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "\\lPreStmt\\l;";
|
2009-07-23 06:35:28 +08:00
|
|
|
else if (isa<PostLoad>(Loc))
|
2009-05-08 02:27:16 +08:00
|
|
|
Out << "\\lPostLoad\\l;";
|
|
|
|
else if (isa<PostStore>(Loc))
|
|
|
|
Out << "\\lPostStore\\l";
|
|
|
|
else if (isa<PostLValue>(Loc))
|
|
|
|
Out << "\\lPostLValue\\l";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 04:16:36 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to determine
|
|
|
|
// the name of the check.
|
2008-12-17 06:02:27 +08:00
|
|
|
if (GraphPrintCheckerState->isImplicitNullDeref(N))
|
|
|
|
Out << "\\|Implicit-Null Dereference.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isExplicitNullDeref(N))
|
|
|
|
Out << "\\|Explicit-Null Dereference.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isUndefDeref(N))
|
|
|
|
Out << "\\|Dereference of undefialied value.\\l";
|
|
|
|
else if (GraphPrintCheckerState->isUndefStore(N))
|
|
|
|
Out << "\\|Store to Undefined Loc.";
|
|
|
|
else if (GraphPrintCheckerState->isUndefResult(N))
|
|
|
|
Out << "\\|Result of operation is undefined.";
|
|
|
|
else if (GraphPrintCheckerState->isNoReturnCall(N))
|
|
|
|
Out << "\\|Call to function marked \"noreturn\".";
|
|
|
|
else if (GraphPrintCheckerState->isBadCall(N))
|
|
|
|
Out << "\\|Call to NULL/Undefined.";
|
|
|
|
else if (GraphPrintCheckerState->isUndefArg(N))
|
|
|
|
Out << "\\|Argument in call is undefined";
|
2009-11-12 04:16:36 +08:00
|
|
|
#endif
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-17 06:02:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
const BlockEdge &E = cast<BlockEdge>(Loc);
|
2008-01-17 05:46:15 +08:00
|
|
|
Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B"
|
|
|
|
<< E.getDst()->getBlockID() << ')';
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const Stmt *T = E.getSrc()->getTerminator()) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-08 04:57:30 +08:00
|
|
|
SourceLocation SLoc = T->getLocStart();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
Out << "\\|Terminator: ";
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
E.getSrc()->printTerminator(Out, LO);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 11:30:59 +08:00
|
|
|
if (SLoc.isFileID()) {
|
|
|
|
Out << "\\lline="
|
2011-07-26 05:09:52 +08:00
|
|
|
<< GraphPrintSourceManager->getExpansionLineNumber(SLoc)
|
2009-02-04 08:55:58 +08:00
|
|
|
<< " col="
|
2011-07-26 04:57:57 +08:00
|
|
|
<< GraphPrintSourceManager->getExpansionColumnNumber(SLoc);
|
2008-03-09 11:30:59 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
if (isa<SwitchStmt>(T)) {
|
2011-08-13 07:37:29 +08:00
|
|
|
const Stmt *Label = E.getDst()->getLabel();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
if (Label) {
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const CaseStmt *C = dyn_cast<CaseStmt>(Label)) {
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << "\\lcase ";
|
2009-06-30 09:26:17 +08:00
|
|
|
LangOptions LO; // FIXME.
|
|
|
|
C->getLHS()->printPretty(Out, 0, PrintingPolicy(LO));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
if (const Stmt *RHS = C->getRHS()) {
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << " .. ";
|
2009-06-30 09:26:17 +08:00
|
|
|
RHS->printPretty(Out, 0, PrintingPolicy(LO));
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << ":";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (isa<DefaultStmt>(Label));
|
|
|
|
Out << "\\ldefault:";
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
else
|
2008-02-14 07:08:21 +08:00
|
|
|
Out << "\\l(implicit) default:";
|
|
|
|
}
|
|
|
|
else if (isa<IndirectGotoStmt>(T)) {
|
2008-01-31 07:03:39 +08:00
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Out << "\\lCondition: ";
|
|
|
|
if (*E.getSrc()->succ_begin() == E.getDst())
|
|
|
|
Out << "true";
|
|
|
|
else
|
2009-09-09 23:08:12 +08:00
|
|
|
Out << "false";
|
2008-01-31 07:03:39 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
Out << "\\l";
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-12 04:16:36 +08:00
|
|
|
#if 0
|
|
|
|
// FIXME: Replace with a general scheme to determine
|
|
|
|
// the name of the check.
|
2008-02-28 17:25:22 +08:00
|
|
|
if (GraphPrintCheckerState->isUndefControlFlow(N)) {
|
|
|
|
Out << "\\|Control-flow based on\\lUndefined value.\\l";
|
2008-01-31 07:24:39 +08:00
|
|
|
}
|
2009-11-12 04:16:36 +08:00
|
|
|
#endif
|
2008-01-17 05:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state = N->getState();
|
2012-01-31 10:23:28 +08:00
|
|
|
Out << "\\|StateID: " << (void*) state.getPtr()
|
2010-12-03 14:52:26 +08:00
|
|
|
<< " NodeID: " << (void*) N << "\\|";
|
2012-01-07 06:09:28 +08:00
|
|
|
state->printDOT(Out);
|
2011-08-13 07:04:46 +08:00
|
|
|
|
|
|
|
Out << "\\l";
|
|
|
|
|
|
|
|
if (const ProgramPointTag *tag = Loc.getTag()) {
|
|
|
|
Out << "\\|Tag: " << tag->getTagDescription();
|
|
|
|
Out << "\\l";
|
|
|
|
}
|
2008-01-17 05:46:15 +08:00
|
|
|
return Out.str();
|
|
|
|
}
|
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
} // end llvm namespace
|
2008-01-17 05:46:15 +08:00
|
|
|
#endif
|
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-13 01:18:20 +08:00
|
|
|
template <typename ITERATOR>
|
2011-08-13 07:37:29 +08:00
|
|
|
ExplodedNode *GetGraphNode(ITERATOR I) { return *I; }
|
2008-03-13 01:18:20 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
template <> ExplodedNode*
|
|
|
|
GetGraphNode<llvm::DenseMap<ExplodedNode*, Expr*>::iterator>
|
|
|
|
(llvm::DenseMap<ExplodedNode*, Expr*>::iterator I) {
|
2008-03-13 01:18:20 +08:00
|
|
|
return I->first;
|
|
|
|
}
|
2008-03-08 06:58:01 +08:00
|
|
|
#endif
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ViewGraph(bool trim) {
|
2009-09-09 23:08:12 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-08 06:58:01 +08:00
|
|
|
if (trim) {
|
2009-08-06 20:48:26 +08:00
|
|
|
std::vector<ExplodedNode*> Src;
|
2009-03-11 09:41:22 +08:00
|
|
|
|
|
|
|
// Flush any outstanding reports to make sure we cover all the nodes.
|
|
|
|
// This does not cause them to get displayed.
|
|
|
|
for (BugReporter::iterator I=BR.begin(), E=BR.end(); I!=E; ++I)
|
|
|
|
const_cast<BugType*>(*I)->FlushReports(BR);
|
|
|
|
|
|
|
|
// Iterate through the reports and get their nodes.
|
2011-02-23 08:16:01 +08:00
|
|
|
for (BugReporter::EQClasses_iterator
|
|
|
|
EI = BR.EQClasses_begin(), EE = BR.EQClasses_end(); EI != EE; ++EI) {
|
|
|
|
BugReportEquivClass& EQ = *EI;
|
|
|
|
const BugReport &R = **EQ.begin();
|
|
|
|
ExplodedNode *N = const_cast<ExplodedNode*>(R.getErrorNode());
|
|
|
|
if (N) Src.push_back(N);
|
2009-03-11 09:41:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-13 01:18:20 +08:00
|
|
|
ViewGraph(&Src[0], &Src[0]+Src.size());
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
2008-03-12 02:25:33 +08:00
|
|
|
else {
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2008-08-14 05:24:49 +08:00
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
llvm::ViewGraph(*G.roots_begin(), "ExprEngine");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-12 02:25:33 +08:00
|
|
|
GraphPrintCheckerState = NULL;
|
|
|
|
GraphPrintSourceManager = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-12-23 02:53:44 +08:00
|
|
|
void ExprEngine::ViewGraph(ExplodedNode** Beg, ExplodedNode** End) {
|
2008-03-12 02:25:33 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-06 20:48:26 +08:00
|
|
|
std::auto_ptr<ExplodedGraph> TrimmedG(G.Trim(Beg, End).first);
|
2008-03-12 02:25:33 +08:00
|
|
|
|
2009-02-05 07:49:09 +08:00
|
|
|
if (!TrimmedG.get())
|
2009-08-23 20:08:50 +08:00
|
|
|
llvm::errs() << "warning: Trimmed ExplodedGraph is empty.\n";
|
2009-02-05 07:49:09 +08:00
|
|
|
else
|
2010-12-23 02:53:44 +08:00
|
|
|
llvm::ViewGraph(*TrimmedG->roots_begin(), "TrimmedExprEngine");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-01-31 07:24:39 +08:00
|
|
|
GraphPrintCheckerState = NULL;
|
2008-03-08 04:57:30 +08:00
|
|
|
GraphPrintSourceManager = NULL;
|
2008-02-15 06:36:46 +08:00
|
|
|
#endif
|
2008-01-17 02:18:48 +08:00
|
|
|
}
|