2008-02-15 06:13:12 +08:00
|
|
|
//=-- GRExprEngine.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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-15 06:13:12 +08:00
|
|
|
#include "clang/Analysis/PathSensitive/GRExprEngine.h"
|
2008-04-10 05:41:14 +08:00
|
|
|
#include "clang/Analysis/PathSensitive/BugReporter.h"
|
2008-03-08 04:57:30 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2008-02-15 06:36:46 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2008-02-15 06:16:04 +08:00
|
|
|
|
2008-02-27 14:07:00 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include "llvm/Support/GraphWriter.h"
|
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
|
2008-02-15 06:16:04 +08:00
|
|
|
using namespace clang;
|
|
|
|
using llvm::dyn_cast;
|
|
|
|
using llvm::cast;
|
|
|
|
using llvm::APSInt;
|
2008-01-24 03:59:44 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Engine construction and deletion.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-10 02:05:48 +08:00
|
|
|
|
2008-04-10 05:41:14 +08:00
|
|
|
GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx)
|
|
|
|
: CoreEngine(cfg, CD, Ctx, *this),
|
|
|
|
G(CoreEngine.getGraph()),
|
|
|
|
Liveness(G.getCFG()),
|
|
|
|
Builder(NULL),
|
|
|
|
StateMgr(G.getContext(), G.getAllocator()),
|
|
|
|
BasicVals(StateMgr.getBasicValueFactory()),
|
|
|
|
TF(NULL), // FIXME
|
|
|
|
SymMgr(StateMgr.getSymbolManager()),
|
|
|
|
StmtEntryNode(NULL), CleanedState(NULL), CurrentStmt(NULL) {
|
|
|
|
|
|
|
|
// Compute liveness information.
|
|
|
|
Liveness.runOnCFG(G.getCFG());
|
|
|
|
Liveness.runOnAllBlocks(G.getCFG(), NULL, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
GRExprEngine::~GRExprEngine() {
|
|
|
|
for (BugTypeSet::iterator I = BugTypes.begin(), E = BugTypes.end(); I!=E; ++I)
|
|
|
|
delete *I;
|
|
|
|
|
|
|
|
for (SimpleChecksTy::iterator I = CallChecks.begin(), E = CallChecks.end();
|
|
|
|
I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
|
|
|
|
for (SimpleChecksTy::iterator I=MsgExprChecks.begin(), E=MsgExprChecks.end();
|
|
|
|
I != E; ++I)
|
|
|
|
delete *I;
|
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// SaveAndRestore - A utility class that uses RIIA to save and restore
|
|
|
|
// the value of a variable.
|
|
|
|
template<typename T>
|
|
|
|
struct VISIBILITY_HIDDEN SaveAndRestore {
|
|
|
|
SaveAndRestore(T& x) : X(x), old_value(x) {}
|
|
|
|
~SaveAndRestore() { X = old_value; }
|
|
|
|
T get() { return old_value; }
|
|
|
|
|
|
|
|
T& X;
|
|
|
|
T old_value;
|
|
|
|
};
|
|
|
|
|
2008-04-10 05:41:14 +08:00
|
|
|
void GRExprEngine::EmitWarnings(Diagnostic& Diag, PathDiagnosticClient* PD) {
|
|
|
|
for (bug_type_iterator I = bug_types_begin(), E = bug_types_end(); I!=E; ++I){
|
|
|
|
BugReporter BR(Diag, PD, getContext(), *this);
|
|
|
|
(*I)->EmitWarnings(BR);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SimpleChecksTy::iterator I = CallChecks.begin(), E = CallChecks.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
BugReporter BR(Diag, PD, getContext(), *this);
|
|
|
|
(*I)->EmitWarnings(BR);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SimpleChecksTy::iterator I=MsgExprChecks.begin(), E=MsgExprChecks.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
BugReporter BR(Diag, PD, getContext(), *this);
|
|
|
|
(*I)->EmitWarnings(BR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::setTransferFunctions(GRTransferFuncs* tf) {
|
|
|
|
TF = tf;
|
|
|
|
TF->RegisterChecks(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::AddCallCheck(GRSimpleAPICheck* A) {
|
|
|
|
CallChecks.push_back(A);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::AddObjCMessageExprCheck(GRSimpleAPICheck* A) {
|
|
|
|
MsgExprChecks.push_back(A);
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* GRExprEngine::getInitialState() {
|
2008-02-27 14:47:26 +08:00
|
|
|
|
|
|
|
// The LiveVariables information already has a compilation of all VarDecls
|
|
|
|
// used in the function. Iterate through this set, and "symbolicate"
|
|
|
|
// any VarDecl whose value originally comes from outside the function.
|
|
|
|
|
|
|
|
typedef LiveVariables::AnalysisDataTy LVDataTy;
|
|
|
|
LVDataTy& D = Liveness.getAnalysisData();
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState StateImpl = *StateMgr.getInitialState();
|
2008-02-27 14:47:26 +08:00
|
|
|
|
|
|
|
for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
|
|
|
|
|
|
|
|
VarDecl* VD = cast<VarDecl>(const_cast<ScopedDecl*>(I->first));
|
|
|
|
|
|
|
|
if (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD)) {
|
|
|
|
RVal X = RVal::GetSymbolValue(SymMgr, VD);
|
|
|
|
StateMgr.BindVar(StateImpl, VD, X);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateMgr.getPersistentState(StateImpl);
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* GRExprEngine::SetRVal(ValueState* St, Expr* Ex, RVal V) {
|
2008-02-07 12:16:04 +08:00
|
|
|
|
2008-02-05 05:59:01 +08:00
|
|
|
bool isBlkExpr = false;
|
2008-02-07 12:16:04 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
if (Ex == CurrentStmt) {
|
|
|
|
isBlkExpr = getCFG().isBlkExpr(Ex);
|
2008-02-05 05:59:01 +08:00
|
|
|
|
|
|
|
if (!isBlkExpr)
|
|
|
|
return St;
|
|
|
|
}
|
2008-02-07 12:16:04 +08:00
|
|
|
|
2008-02-27 07:37:01 +08:00
|
|
|
return StateMgr.SetRVal(St, Ex, V, isBlkExpr, false);
|
2008-02-05 05:59:01 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Top-level transfer function logic (Dispatcher).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) {
|
|
|
|
|
|
|
|
Builder = &builder;
|
|
|
|
StmtEntryNode = builder.getLastNode();
|
|
|
|
CurrentStmt = S;
|
|
|
|
NodeSet Dst;
|
|
|
|
|
|
|
|
// Set up our simple checks.
|
|
|
|
|
|
|
|
// FIXME: This can probably be installed directly in GRCoreEngine, obviating
|
|
|
|
// the need to do a copy every time we hit a block-level statement.
|
|
|
|
|
|
|
|
if (!MsgExprChecks.empty())
|
|
|
|
Builder->setObjCMsgExprAuditors((GRAuditor<ValueState>**) &MsgExprChecks[0],
|
|
|
|
(GRAuditor<ValueState>**) (&MsgExprChecks[0] + MsgExprChecks.size()));
|
|
|
|
|
|
|
|
|
|
|
|
if (!CallChecks.empty())
|
|
|
|
Builder->setCallExprAuditors((GRAuditor<ValueState>**) &CallChecks[0],
|
|
|
|
(GRAuditor<ValueState>**) (&CallChecks[0] + CallChecks.size()));
|
|
|
|
|
|
|
|
// Create the cleaned state.
|
|
|
|
|
|
|
|
CleanedState = StateMgr.RemoveDeadBindings(StmtEntryNode->getState(),
|
|
|
|
CurrentStmt, Liveness);
|
|
|
|
|
|
|
|
Builder->SetCleanedState(CleanedState);
|
|
|
|
|
|
|
|
// Visit the statement.
|
|
|
|
|
|
|
|
Visit(S, StmtEntryNode, Dst);
|
|
|
|
|
|
|
|
// If no nodes were generated, generate a new node that has all the
|
|
|
|
// dead mappings removed.
|
|
|
|
|
2008-04-19 03:34:16 +08:00
|
|
|
if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode &&
|
2008-04-19 04:35:30 +08:00
|
|
|
!Builder->HasGeneratedNode)
|
2008-04-16 07:06:53 +08:00
|
|
|
builder.generateNode(S, GetState(StmtEntryNode), StmtEntryNode);
|
|
|
|
|
|
|
|
// NULL out these variables to cleanup.
|
|
|
|
|
|
|
|
CurrentStmt = NULL;
|
|
|
|
StmtEntryNode = NULL;
|
|
|
|
Builder = NULL;
|
|
|
|
CleanedState = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
if (S != CurrentStmt && getCFG().isBlkExpr(S)) {
|
|
|
|
Dst.Add(Pred);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (S->getStmtClass()) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Cases we intentionally have "default" handle:
|
|
|
|
// AddrLabelExpr, IntegerLiteral, CharacterLiteral
|
|
|
|
|
|
|
|
Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::AsmStmtClass:
|
|
|
|
VisitAsmStmt(cast<AsmStmt>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::BinaryOperatorClass: {
|
|
|
|
BinaryOperator* B = cast<BinaryOperator>(S);
|
|
|
|
|
|
|
|
if (B->isLogicalOp()) {
|
|
|
|
VisitLogicalExpr(B, Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (B->getOpcode() == BinaryOperator::Comma) {
|
|
|
|
ValueState* St = GetState(Pred);
|
|
|
|
MakeNode(Dst, B, Pred, SetRVal(St, B, GetRVal(St, B->getRHS())));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::CallExprClass: {
|
|
|
|
CallExpr* C = cast<CallExpr>(S);
|
|
|
|
VisitCall(C, Pred, C->arg_begin(), C->arg_end(), Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::CastExprClass: {
|
|
|
|
CastExpr* C = cast<CastExpr>(S);
|
|
|
|
VisitCast(C, C->getSubExpr(), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: ChooseExpr is really a constant. We need to fix
|
|
|
|
// the CFG do not model them as explicit control-flow.
|
|
|
|
|
|
|
|
case Stmt::ChooseExprClass: { // __builtin_choose_expr
|
|
|
|
ChooseExpr* C = cast<ChooseExpr>(S);
|
|
|
|
VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::CompoundAssignOperatorClass:
|
|
|
|
VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ConditionalOperatorClass: { // '?' operator
|
|
|
|
ConditionalOperator* C = cast<ConditionalOperator>(S);
|
|
|
|
VisitGuardedExpr(C, C->getLHS(), C->getRHS(), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::DeclRefExprClass:
|
|
|
|
VisitDeclRefExpr(cast<DeclRefExpr>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::DeclStmtClass:
|
|
|
|
VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::ImplicitCastExprClass: {
|
|
|
|
ImplicitCastExpr* C = cast<ImplicitCastExpr>(S);
|
|
|
|
VisitCast(C, C->getSubExpr(), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
case Stmt::MemberExprClass: {
|
|
|
|
VisitMemberExpr(cast<MemberExpr>(S), Pred, Dst, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
case Stmt::ObjCMessageExprClass: {
|
|
|
|
VisitObjCMessageExpr(cast<ObjCMessageExpr>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::ParenExprClass:
|
|
|
|
Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::SizeOfAlignOfTypeExprClass:
|
|
|
|
VisitSizeOfAlignOfTypeExpr(cast<SizeOfAlignOfTypeExpr>(S), Pred, Dst);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::StmtExprClass: {
|
|
|
|
StmtExpr* SE = cast<StmtExpr>(S);
|
|
|
|
|
|
|
|
ValueState* St = GetState(Pred);
|
|
|
|
|
|
|
|
// FIXME: Not certain if we can have empty StmtExprs. If so, we should
|
|
|
|
// probably just remove these from the CFG.
|
|
|
|
assert (!SE->getSubStmt()->body_empty());
|
|
|
|
|
|
|
|
if (Expr* LastExpr = dyn_cast<Expr>(*SE->getSubStmt()->body_rbegin()))
|
|
|
|
MakeNode(Dst, SE, Pred, SetRVal(St, SE, GetRVal(St, LastExpr)));
|
|
|
|
else
|
|
|
|
Dst.Add(Pred);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We may wish to always bind state to ReturnStmts so
|
|
|
|
// that users can quickly query what was the state at the
|
|
|
|
// exit points of a function.
|
|
|
|
|
|
|
|
case Stmt::ReturnStmtClass:
|
|
|
|
VisitReturnStmt(cast<ReturnStmt>(S), Pred, Dst); break;
|
|
|
|
|
|
|
|
case Stmt::UnaryOperatorClass: {
|
|
|
|
UnaryOperator* U = cast<UnaryOperator>(S);
|
|
|
|
|
|
|
|
switch (U->getOpcode()) {
|
|
|
|
case UnaryOperator::Deref: VisitDeref(U, Pred, Dst); break;
|
|
|
|
case UnaryOperator::Plus: Visit(U->getSubExpr(), Pred, Dst); break;
|
|
|
|
case UnaryOperator::SizeOf: VisitSizeOfExpr(U, Pred, Dst); break;
|
|
|
|
default: VisitUnaryOperator(U, Pred, Dst); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Block entrance. (Update counters).
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool GRExprEngine::ProcessBlockEntrance(CFGBlock* B, ValueState*,
|
|
|
|
GRBlockCounter BC) {
|
|
|
|
|
|
|
|
return BC.getNumVisited(B->getBlockID()) < 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch processing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* GRExprEngine::MarkBranch(ValueState* St, Stmt* Terminator,
|
|
|
|
bool branchTaken) {
|
2008-02-27 03:05:15 +08:00
|
|
|
|
|
|
|
switch (Terminator->getStmtClass()) {
|
|
|
|
default:
|
|
|
|
return St;
|
|
|
|
|
|
|
|
case Stmt::BinaryOperatorClass: { // '&&' and '||'
|
|
|
|
|
|
|
|
BinaryOperator* B = cast<BinaryOperator>(Terminator);
|
|
|
|
BinaryOperator::Opcode Op = B->getOpcode();
|
|
|
|
|
|
|
|
assert (Op == BinaryOperator::LAnd || Op == BinaryOperator::LOr);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
Expr* Ex = (Op == BinaryOperator::LAnd && branchTaken) ||
|
|
|
|
(Op == BinaryOperator::LOr && !branchTaken)
|
|
|
|
? B->getRHS() : B->getLHS();
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
return SetBlkExprRVal(St, B, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::ConditionalOperatorClass: { // ?:
|
|
|
|
|
|
|
|
ConditionalOperator* C = cast<ConditionalOperator>(Terminator);
|
|
|
|
|
|
|
|
// For ?, if branchTaken == true then the value is either the LHS or
|
|
|
|
// the condition itself. (GNU extension).
|
|
|
|
|
|
|
|
Expr* Ex;
|
|
|
|
|
|
|
|
if (branchTaken)
|
|
|
|
Ex = C->getLHS() ? C->getLHS() : C->getCond();
|
|
|
|
else
|
|
|
|
Ex = C->getRHS();
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
return SetBlkExprRVal(St, C, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Stmt::ChooseExprClass: { // ?:
|
|
|
|
|
|
|
|
ChooseExpr* C = cast<ChooseExpr>(Terminator);
|
|
|
|
|
|
|
|
Expr* Ex = branchTaken ? C->getLHS() : C->getRHS();
|
2008-02-28 17:25:22 +08:00
|
|
|
return SetBlkExprRVal(St, C, UndefinedVal(Ex));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term,
|
2008-02-22 02:02:17 +08:00
|
|
|
BranchNodeBuilder& builder) {
|
2008-01-31 07:03:39 +08:00
|
|
|
|
2008-02-12 03:21:59 +08:00
|
|
|
// Remove old bindings for subexpressions.
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* PrevState = StateMgr.RemoveSubExprBindings(builder.getState());
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2008-02-16 06:29:00 +08:00
|
|
|
// Check for NULL conditions; e.g. "for(;;)"
|
|
|
|
if (!Condition) {
|
|
|
|
builder.markInfeasible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal V = GetRVal(PrevState, Condition);
|
2008-01-31 07:03:39 +08:00
|
|
|
|
|
|
|
switch (V.getBaseKind()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case RVal::UnknownKind:
|
2008-02-27 03:40:44 +08:00
|
|
|
builder.generateNode(MarkBranch(PrevState, Term, true), true);
|
|
|
|
builder.generateNode(MarkBranch(PrevState, Term, false), false);
|
2008-01-31 07:03:39 +08:00
|
|
|
return;
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
case RVal::UndefinedKind: {
|
2008-01-31 07:03:39 +08:00
|
|
|
NodeTy* N = builder.generateNode(PrevState, true);
|
|
|
|
|
|
|
|
if (N) {
|
|
|
|
N->markAsSink();
|
2008-02-28 17:25:22 +08:00
|
|
|
UndefBranches.insert(N);
|
2008-01-31 07:03:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.markInfeasible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-13 02:08:17 +08:00
|
|
|
|
2008-03-01 04:27:50 +08:00
|
|
|
// Process the true branch.
|
2008-02-13 02:08:17 +08:00
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
bool isFeasible = false;
|
2008-03-01 04:27:50 +08:00
|
|
|
ValueState* St = Assume(PrevState, V, true, isFeasible);
|
|
|
|
|
|
|
|
if (isFeasible)
|
|
|
|
builder.generateNode(MarkBranch(St, Term, true), true);
|
2008-02-13 02:08:17 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(true);
|
2008-03-01 04:27:50 +08:00
|
|
|
|
|
|
|
// Process the false branch.
|
2008-01-30 07:32:35 +08:00
|
|
|
|
2008-03-01 04:27:50 +08:00
|
|
|
isFeasible = false;
|
|
|
|
St = Assume(PrevState, V, false, isFeasible);
|
2008-01-30 07:32:35 +08:00
|
|
|
|
2008-03-01 04:27:50 +08:00
|
|
|
if (isFeasible)
|
|
|
|
builder.generateNode(MarkBranch(St, Term, false), false);
|
2008-02-05 08:26:40 +08:00
|
|
|
else
|
|
|
|
builder.markInfeasible(false);
|
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
/// ProcessIndirectGoto - Called by GRCoreEngine. Used to generate successor
|
2008-02-13 08:24:44 +08:00
|
|
|
/// nodes by processing the 'effects' of a computed goto jump.
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRExprEngine::ProcessIndirectGoto(IndirectGotoNodeBuilder& builder) {
|
2008-02-13 08:24:44 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* St = builder.getState();
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal V = GetRVal(St, builder.getTarget());
|
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.
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef IndirectGotoNodeBuilder::iterator iterator;
|
|
|
|
|
|
|
|
if (isa<lval::GotoLabel>(V)) {
|
|
|
|
LabelStmt* L = cast<lval::GotoLabel>(V).getLabel();
|
|
|
|
|
|
|
|
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I) {
|
2008-02-14 01:27:37 +08:00
|
|
|
if (I.getLabel() == L) {
|
|
|
|
builder.generateNode(I, St);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (false && "No block with label.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (isa<lval::ConcreteInt>(V) || isa<UndefinedVal>(V)) {
|
2008-02-13 08:24:44 +08:00
|
|
|
// Dispatch to the first target and mark it as a sink.
|
2008-02-14 01:27:37 +08:00
|
|
|
NodeTy* N = builder.generateNode(builder.begin(), St, true);
|
2008-02-28 17:25:22 +08:00
|
|
|
UndefBranches.insert(N);
|
2008-02-13 08:24:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is really a catch-all. We don't support symbolics yet.
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (V.isUnknown());
|
2008-02-13 08:24:44 +08:00
|
|
|
|
|
|
|
for (iterator I=builder.begin(), E=builder.end(); I != E; ++I)
|
2008-02-14 01:27:37 +08:00
|
|
|
builder.generateNode(I, St);
|
2008-02-13 08:24:44 +08:00
|
|
|
}
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
|
|
|
|
void GRExprEngine::VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R,
|
|
|
|
NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
|
|
|
|
assert (Ex == CurrentStmt && getCFG().isBlkExpr(Ex));
|
|
|
|
|
|
|
|
ValueState* St = GetState(Pred);
|
|
|
|
RVal X = GetBlkExprRVal(St, Ex);
|
|
|
|
|
|
|
|
assert (X.isUndef());
|
|
|
|
|
|
|
|
Expr* SE = (Expr*) cast<UndefinedVal>(X).getData();
|
|
|
|
|
|
|
|
assert (SE);
|
|
|
|
|
|
|
|
X = GetBlkExprRVal(St, SE);
|
|
|
|
|
|
|
|
// Make sure that we invalidate the previous binding.
|
|
|
|
MakeNode(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, X, true, true));
|
|
|
|
}
|
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
/// ProcessSwitch - Called by GRCoreEngine. Used to generate successor
|
|
|
|
/// nodes by processing the 'effects' of a switch statement.
|
|
|
|
void GRExprEngine::ProcessSwitch(SwitchNodeBuilder& builder) {
|
|
|
|
|
|
|
|
typedef SwitchNodeBuilder::iterator iterator;
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* St = builder.getState();
|
2008-02-19 06:57:02 +08:00
|
|
|
Expr* CondE = builder.getCondition();
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal CondV = GetRVal(St, CondE);
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (CondV.isUndef()) {
|
2008-02-14 07:08:21 +08:00
|
|
|
NodeTy* N = builder.generateDefaultCaseNode(St, true);
|
2008-02-28 17:25:22 +08:00
|
|
|
UndefBranches.insert(N);
|
2008-02-14 07:08:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* DefaultSt = St;
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
// While most of this can be assumed (such as the signedness), having it
|
|
|
|
// just computed makes sure everything makes the same assumptions end-to-end.
|
2008-02-19 06:57:02 +08:00
|
|
|
|
2008-03-06 02:54:05 +08:00
|
|
|
unsigned bits = getContext().getTypeSize(CondE->getType());
|
2008-02-19 06:57:02 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
APSInt V1(bits, false);
|
|
|
|
APSInt V2 = V1;
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (iterator I = builder.begin(), EI = builder.end(); I != EI; ++I) {
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
CaseStmt* Case = cast<CaseStmt>(I.getCase());
|
|
|
|
|
|
|
|
// Evaluate the case.
|
|
|
|
if (!Case->getLHS()->isIntegerConstantExpr(V1, getContext(), 0, true)) {
|
|
|
|
assert (false && "Case condition must evaluate to an integer constant.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the RHS of the case, if it exists.
|
|
|
|
|
|
|
|
if (Expr* E = Case->getRHS()) {
|
|
|
|
if (!E->isIntegerConstantExpr(V2, getContext(), 0, true)) {
|
|
|
|
assert (false &&
|
|
|
|
"Case condition (RHS) must evaluate to an integer constant.");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (V1 <= V2);
|
|
|
|
}
|
2008-03-18 06:17:56 +08:00
|
|
|
else
|
|
|
|
V2 = V1;
|
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.
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
do {
|
2008-03-08 04:13:31 +08:00
|
|
|
nonlval::ConcreteInt CaseVal(BasicVals.getValue(V1));
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal Res = EvalBinOp(BinaryOperator::EQ, CondV, CaseVal);
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
// Now "assume" that the case matches.
|
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
bool isFeasible = false;
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* StNew = Assume(St, Res, true, isFeasible);
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
if (isFeasible) {
|
|
|
|
builder.generateCaseStmtNode(I, StNew);
|
|
|
|
|
|
|
|
// If CondV evaluates to a constant, then we know that this
|
|
|
|
// is the *only* case that we can take, so stop evaluating the
|
|
|
|
// others.
|
|
|
|
if (isa<nonlval::ConcreteInt>(CondV))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now "assume" that the case doesn't match. Add this state
|
|
|
|
// to the default state (if it is feasible).
|
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
isFeasible = false;
|
2008-02-15 03:37:24 +08:00
|
|
|
StNew = Assume(DefaultSt, Res, false, isFeasible);
|
2008-02-14 07:08:21 +08:00
|
|
|
|
|
|
|
if (isFeasible)
|
|
|
|
DefaultSt = StNew;
|
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
// Concretize the next value in the range.
|
|
|
|
if (V1 == V2)
|
|
|
|
break;
|
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
++V1;
|
2008-03-18 06:18:22 +08:00
|
|
|
assert (V1 <= V2);
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2008-03-18 06:17:56 +08:00
|
|
|
} while (true);
|
2008-02-14 07:08:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here, than we know that the default branch is
|
|
|
|
// possible.
|
|
|
|
builder.generateDefaultCaseNode(DefaultSt);
|
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer functions: logical operations ('&&', '||').
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-14 07:08:21 +08:00
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRExprEngine::VisitLogicalExpr(BinaryOperator* B, NodeTy* Pred,
|
2008-02-22 02:02:17 +08:00
|
|
|
NodeSet& Dst) {
|
2008-02-19 08:22:37 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
assert (B->getOpcode() == BinaryOperator::LAnd ||
|
|
|
|
B->getOpcode() == BinaryOperator::LOr);
|
|
|
|
|
|
|
|
assert (B == CurrentStmt && getCFG().isBlkExpr(B));
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(Pred);
|
2008-02-27 03:05:15 +08:00
|
|
|
RVal X = GetBlkExprRVal(St, B);
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
assert (X.isUndef());
|
2008-02-27 03:05:15 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
Expr* Ex = (Expr*) cast<UndefinedVal>(X).getData();
|
2008-02-27 03:05:15 +08:00
|
|
|
|
|
|
|
assert (Ex);
|
|
|
|
|
|
|
|
if (Ex == B->getRHS()) {
|
|
|
|
|
|
|
|
X = GetBlkExprRVal(St, Ex);
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Handle undefined values.
|
2008-02-27 03:40:44 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (X.isUndef()) {
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, Pred, SetBlkExprRVal(St, B, X));
|
2008-02-27 03:40:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
// We took the RHS. Because the value of the '&&' or '||' expression must
|
|
|
|
// evaluate to 0 or 1, we must assume the value of the RHS evaluates to 0
|
|
|
|
// or 1. Alternatively, we could take a lazy approach, and calculate this
|
|
|
|
// value later when necessary. We don't have the machinery in place for
|
|
|
|
// this right now, and since most logical expressions are used for branches,
|
|
|
|
// the payoff is not likely to be large. Instead, we do eager evaluation.
|
|
|
|
|
|
|
|
bool isFeasible = false;
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* NewState = Assume(St, X, true, isFeasible);
|
2008-02-27 03:05:15 +08:00
|
|
|
|
|
|
|
if (isFeasible)
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, Pred,
|
|
|
|
SetBlkExprRVal(NewState, B, MakeConstantVal(1U, B)));
|
2008-02-27 03:05:15 +08:00
|
|
|
|
|
|
|
isFeasible = false;
|
|
|
|
NewState = Assume(St, X, false, isFeasible);
|
|
|
|
|
|
|
|
if (isFeasible)
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, Pred,
|
|
|
|
SetBlkExprRVal(NewState, B, MakeConstantVal(0U, B)));
|
2008-02-05 08:26:40 +08:00
|
|
|
}
|
|
|
|
else {
|
2008-02-27 03:05:15 +08:00
|
|
|
// We took the LHS expression. Depending on whether we are '&&' or
|
|
|
|
// '||' we know what the value of the expression is via properties of
|
|
|
|
// the short-circuiting.
|
2008-02-05 08:26:40 +08:00
|
|
|
|
2008-02-27 03:05:15 +08:00
|
|
|
X = MakeConstantVal( B->getOpcode() == BinaryOperator::LAnd ? 0U : 1U, B);
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, Pred, SetBlkExprRVal(St, B, X));
|
2008-02-27 03:05:15 +08:00
|
|
|
}
|
2008-01-30 07:32:35 +08:00
|
|
|
}
|
2008-02-27 03:05:15 +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
|
|
|
|
2008-02-14 02:06:44 +08:00
|
|
|
void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-07 12:16:04 +08:00
|
|
|
if (D != CurrentStmt) {
|
|
|
|
Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are here, we are loading the value of the decl and binding
|
|
|
|
// it to the block-level expression.
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(Pred);
|
2008-03-09 11:30:59 +08:00
|
|
|
RVal X = RVal::MakeVal(BasicVals, D);
|
|
|
|
RVal Y = isa<lval::DeclVal>(X) ? GetRVal(St, cast<lval::DeclVal>(X)) : X;
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, D, Pred, SetBlkExprRVal(St, D, Y));
|
2008-02-07 12:16:04 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
/// VisitMemberExpr - Transfer function for member expressions.
|
|
|
|
void GRExprEngine::VisitMemberExpr(MemberExpr* M, NodeTy* Pred,
|
|
|
|
NodeSet& Dst, bool asLVal) {
|
|
|
|
|
|
|
|
Expr* Base = M->getBase()->IgnoreParens();
|
|
|
|
|
|
|
|
NodeSet Tmp;
|
|
|
|
VisitLVal(Base, Pred, Tmp);
|
|
|
|
|
|
|
|
if (Base->getType()->isPointerType()) {
|
|
|
|
NodeSet Tmp2;
|
|
|
|
|
|
|
|
for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
|
|
|
|
ValueState* St = GetState(*I);
|
|
|
|
VisitDeref(Base, GetRVal(St, Base), St, *I, Tmp2, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NodeSet::iterator I=Tmp2.begin(), E=Tmp2.end(); I!=E; ++I)
|
|
|
|
VisitMemberExprField(M, Base, *I, Dst, asLVal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I)
|
|
|
|
VisitMemberExprField(M, Base, *I, Dst, asLVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitMemberExprField(MemberExpr* M, Expr* Base, NodeTy* Pred,
|
|
|
|
NodeSet& Dst, bool asLVal) {
|
|
|
|
Dst.Add(Pred);
|
|
|
|
}
|
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
void GRExprEngine::EvalStore(NodeSet& Dst, Expr* E, NodeTy* Pred,
|
|
|
|
ValueState* St, RVal TargetLV, RVal Val) {
|
2008-04-17 02:39:06 +08:00
|
|
|
|
|
|
|
assert (Builder && "GRStmtNodeBuilder must be defined.");
|
|
|
|
|
|
|
|
unsigned size = Dst.size();
|
2008-04-19 04:35:30 +08:00
|
|
|
|
|
|
|
SaveAndRestore<bool> OldSink(Builder->BuildSinks),
|
|
|
|
OldHasGen(Builder->HasGeneratedNode);
|
|
|
|
|
|
|
|
Builder->HasGeneratedNode = false;
|
2008-04-17 02:39:06 +08:00
|
|
|
|
2008-04-17 04:40:59 +08:00
|
|
|
assert (!TargetLV.isUndef());
|
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
TF->EvalStore(Dst, *this, *Builder, E, Pred, St, TargetLV, Val);
|
2008-04-17 02:39:06 +08:00
|
|
|
|
|
|
|
// Handle the case where no nodes where generated. Auto-generate that
|
|
|
|
// contains the updated state if we aren't generating sinks.
|
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
if (!Builder->BuildSinks && Dst.size() == size && !Builder->HasGeneratedNode)
|
2008-04-17 04:40:59 +08:00
|
|
|
TF->GRTransferFuncs::EvalStore(Dst, *this, *Builder, E, Pred, St,
|
|
|
|
TargetLV, Val);
|
2008-04-17 02:39:06 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer function: Function calls.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-19 09:44:53 +08:00
|
|
|
void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred,
|
2008-02-22 02:02:17 +08:00
|
|
|
CallExpr::arg_iterator AI,
|
|
|
|
CallExpr::arg_iterator AE,
|
2008-02-19 09:44:53 +08:00
|
|
|
NodeSet& Dst) {
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
// Process the arguments.
|
|
|
|
|
|
|
|
if (AI != AE) {
|
|
|
|
|
2008-03-04 08:56:45 +08:00
|
|
|
NodeSet DstTmp;
|
2008-03-05 06:01:56 +08:00
|
|
|
Visit(*AI, Pred, DstTmp);
|
2008-02-22 02:02:17 +08:00
|
|
|
++AI;
|
2008-02-19 09:44:53 +08:00
|
|
|
|
2008-03-05 06:01:56 +08:00
|
|
|
for (NodeSet::iterator DI=DstTmp.begin(), DE=DstTmp.end(); DI != DE; ++DI)
|
2008-02-22 02:02:17 +08:00
|
|
|
VisitCall(CE, *DI, AI, AE, Dst);
|
2008-02-19 09:44:53 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here we have processed all of the arguments. Evaluate
|
|
|
|
// the callee expression.
|
2008-03-04 00:47:31 +08:00
|
|
|
|
2008-02-26 05:16:03 +08:00
|
|
|
NodeSet DstTmp;
|
|
|
|
Expr* Callee = CE->getCallee()->IgnoreParenCasts();
|
2008-03-04 00:47:31 +08:00
|
|
|
|
2008-02-26 05:16:03 +08:00
|
|
|
VisitLVal(Callee, Pred, DstTmp);
|
2008-03-04 00:47:31 +08:00
|
|
|
|
|
|
|
if (DstTmp.empty())
|
|
|
|
DstTmp.Add(Pred);
|
2008-02-19 09:44:53 +08:00
|
|
|
|
|
|
|
// Finally, evaluate the function call.
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator DI = DstTmp.begin(), DE = DstTmp.end(); DI!=DE; ++DI) {
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(*DI);
|
2008-02-26 05:16:03 +08:00
|
|
|
RVal L = GetLVal(St, Callee);
|
2008-02-19 09:44:53 +08:00
|
|
|
|
2008-03-04 00:47:31 +08:00
|
|
|
// FIXME: Add support for symbolic function calls (calls involving
|
|
|
|
// function pointer values that are symbolic).
|
|
|
|
|
|
|
|
// Check for undefined control-flow or calls to NULL.
|
|
|
|
|
2008-03-01 07:14:48 +08:00
|
|
|
if (L.isUndef() || isa<lval::ConcreteInt>(L)) {
|
2008-02-19 09:44:53 +08:00
|
|
|
NodeTy* N = Builder->generateNode(CE, St, *DI);
|
2008-03-05 06:01:56 +08:00
|
|
|
|
2008-03-01 07:53:11 +08:00
|
|
|
if (N) {
|
|
|
|
N->markAsSink();
|
|
|
|
BadCalls.insert(N);
|
|
|
|
}
|
2008-03-05 06:01:56 +08:00
|
|
|
|
2008-02-19 09:44:53 +08:00
|
|
|
continue;
|
2008-03-06 05:15:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the "noreturn" attribute.
|
|
|
|
|
|
|
|
SaveAndRestore<bool> OldSink(Builder->BuildSinks);
|
|
|
|
|
2008-03-15 05:58:42 +08:00
|
|
|
if (isa<lval::FuncVal>(L)) {
|
|
|
|
|
|
|
|
FunctionDecl* FD = cast<lval::FuncVal>(L).getDecl();
|
|
|
|
|
|
|
|
if (FD->getAttr<NoReturnAttr>())
|
2008-03-06 05:15:02 +08:00
|
|
|
Builder->BuildSinks = true;
|
2008-03-15 05:58:42 +08:00
|
|
|
else {
|
|
|
|
// HACK: Some functions are not marked noreturn, and don't return.
|
|
|
|
// Here are a few hardwired ones. If this takes too long, we can
|
|
|
|
// potentially cache these results.
|
|
|
|
const char* s = FD->getIdentifier()->getName();
|
|
|
|
unsigned n = strlen(s);
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
default:
|
|
|
|
break;
|
2008-03-15 07:25:49 +08:00
|
|
|
|
2008-03-15 05:58:42 +08:00
|
|
|
case 4:
|
2008-03-15 07:25:49 +08:00
|
|
|
if (!memcmp(s, "exit", 4)) Builder->BuildSinks = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (!memcmp(s, "panic", 5)) Builder->BuildSinks = true;
|
|
|
|
break;
|
2008-03-15 05:58:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-06 05:15:02 +08:00
|
|
|
|
|
|
|
// Evaluate the call.
|
|
|
|
|
2008-03-04 00:47:31 +08:00
|
|
|
|
2008-03-05 06:01:56 +08:00
|
|
|
bool invalidateArgs = false;
|
2008-02-19 09:44:53 +08:00
|
|
|
|
2008-02-22 03:46:04 +08:00
|
|
|
if (L.isUnknown()) {
|
2008-03-05 06:01:56 +08:00
|
|
|
// Check for an "unknown" callee.
|
|
|
|
invalidateArgs = true;
|
|
|
|
}
|
|
|
|
else if (isa<lval::FuncVal>(L)) {
|
|
|
|
|
|
|
|
IdentifierInfo* Info = cast<lval::FuncVal>(L).getDecl()->getIdentifier();
|
|
|
|
|
2008-03-06 06:59:42 +08:00
|
|
|
if (unsigned id = Info->getBuiltinID()) {
|
|
|
|
switch (id) {
|
|
|
|
case Builtin::BI__builtin_expect: {
|
|
|
|
// For __builtin_expect, just return the value of the subexpression.
|
|
|
|
assert (CE->arg_begin() != CE->arg_end());
|
|
|
|
RVal X = GetRVal(St, *(CE->arg_begin()));
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, CE, *DI, SetRVal(St, CE, X));
|
2008-03-06 06:59:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
invalidateArgs = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 06:01:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (invalidateArgs) {
|
2008-02-22 03:46:04 +08:00
|
|
|
// Invalidate all arguments passed in by reference (LVals).
|
|
|
|
for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
RVal V = GetRVal(St, *I);
|
|
|
|
|
|
|
|
if (isa<LVal>(V))
|
|
|
|
St = SetRVal(St, cast<LVal>(V), UnknownVal());
|
2008-03-06 05:15:02 +08:00
|
|
|
}
|
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, CE, *DI, St);
|
2008-02-22 03:46:04 +08:00
|
|
|
}
|
2008-03-05 06:01:56 +08:00
|
|
|
else {
|
|
|
|
|
|
|
|
// Check any arguments passed-by-value against being undefined.
|
|
|
|
|
|
|
|
bool badArg = false;
|
|
|
|
|
|
|
|
for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
if (GetRVal(GetState(*DI), *I).isUndef()) {
|
|
|
|
NodeTy* N = Builder->generateNode(CE, GetState(*DI), *DI);
|
2008-03-05 06:01:56 +08:00
|
|
|
|
|
|
|
if (N) {
|
|
|
|
N->markAsSink();
|
|
|
|
UndefArgs[N] = *I;
|
|
|
|
}
|
|
|
|
|
|
|
|
badArg = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (badArg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Dispatch to the plug-in transfer function.
|
2008-03-05 08:33:14 +08:00
|
|
|
|
|
|
|
unsigned size = Dst.size();
|
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
SaveAndRestore<bool> OldSink(Builder->BuildSinks),
|
|
|
|
OldHasGen(Builder->HasGeneratedNode);
|
2008-04-11 07:44:06 +08:00
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
Builder->HasGeneratedNode = false;
|
|
|
|
|
2008-03-05 08:33:14 +08:00
|
|
|
EvalCall(Dst, CE, cast<LVal>(L), *DI);
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
// Handle the case where no nodes where generated. Auto-generate that
|
|
|
|
// contains the updated state if we aren't generating sinks.
|
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
if (!Builder->BuildSinks && Dst.size() == size &&
|
|
|
|
!Builder->HasGeneratedNode)
|
2008-04-16 07:06:53 +08:00
|
|
|
MakeNode(Dst, CE, *DI, St);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer function: Objective-C message expressions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void GRExprEngine::VisitObjCMessageExpr(ObjCMessageExpr* ME, NodeTy* Pred,
|
|
|
|
NodeSet& Dst){
|
|
|
|
|
|
|
|
VisitObjCMessageExprArgHelper(ME, ME->arg_begin(), ME->arg_end(),
|
|
|
|
Pred, Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitObjCMessageExprArgHelper(ObjCMessageExpr* ME,
|
|
|
|
ObjCMessageExpr::arg_iterator AI,
|
|
|
|
ObjCMessageExpr::arg_iterator AE,
|
|
|
|
NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
if (AI == AE) {
|
|
|
|
|
|
|
|
// Process the receiver.
|
|
|
|
|
|
|
|
if (Expr* Receiver = ME->getReceiver()) {
|
|
|
|
NodeSet Tmp;
|
|
|
|
Visit(Receiver, Pred, Tmp);
|
|
|
|
|
|
|
|
for (NodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
|
|
|
|
VisitObjCMessageExprDispatchHelper(ME, *NI, Dst);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitObjCMessageExprDispatchHelper(ME, Pred, Dst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeSet Tmp;
|
|
|
|
Visit(*AI, Pred, Tmp);
|
|
|
|
|
|
|
|
++AI;
|
|
|
|
|
|
|
|
for (NodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
|
|
|
|
VisitObjCMessageExprArgHelper(ME, AI, AE, *NI, Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitObjCMessageExprDispatchHelper(ObjCMessageExpr* ME,
|
|
|
|
NodeTy* Pred,
|
|
|
|
NodeSet& Dst) {
|
|
|
|
|
|
|
|
// FIXME: More logic for the processing the method call.
|
|
|
|
|
|
|
|
ValueState* St = GetState(Pred);
|
|
|
|
|
|
|
|
if (Expr* Receiver = ME->getReceiver()) {
|
|
|
|
|
|
|
|
RVal L = GetRVal(St, Receiver);
|
|
|
|
|
|
|
|
// Check for undefined control-flow or calls to NULL.
|
|
|
|
|
|
|
|
if (L.isUndef()) {
|
|
|
|
NodeTy* N = Builder->generateNode(ME, St, Pred);
|
|
|
|
|
|
|
|
if (N) {
|
|
|
|
N->markAsSink();
|
|
|
|
UndefReceivers.insert(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for any arguments that are uninitialized/undefined.
|
|
|
|
|
|
|
|
for (ObjCMessageExpr::arg_iterator I = ME->arg_begin(), E = ME->arg_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
|
|
|
|
if (GetRVal(St, *I).isUndef()) {
|
|
|
|
|
|
|
|
// Generate an error node for passing an uninitialized/undefined value
|
|
|
|
// as an argument to a message expression. This node is a sink.
|
|
|
|
NodeTy* N = Builder->generateNode(ME, St, Pred);
|
|
|
|
|
|
|
|
if (N) {
|
|
|
|
N->markAsSink();
|
|
|
|
MsgExprUndefArgs[N] = *I;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Dispatch to plug-in transfer function.
|
|
|
|
|
|
|
|
unsigned size = Dst.size();
|
2008-04-19 04:35:30 +08:00
|
|
|
|
|
|
|
SaveAndRestore<bool> OldSink(Builder->BuildSinks),
|
|
|
|
OldHasGen(Builder->HasGeneratedNode);
|
2008-04-16 07:06:53 +08:00
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
Builder->HasGeneratedNode = false;
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
EvalObjCMessageExpr(Dst, ME, Pred);
|
|
|
|
|
|
|
|
// Handle the case where no nodes where generated. Auto-generate that
|
|
|
|
// contains the updated state if we aren't generating sinks.
|
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
if (!Builder->BuildSinks && Dst.size() == size && !Builder->HasGeneratedNode)
|
2008-04-16 07:06:53 +08:00
|
|
|
MakeNode(Dst, ME, Pred, St);
|
2008-02-19 09:44:53 +08:00
|
|
|
}
|
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer functions: Miscellaneous statements.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){
|
2008-01-24 10:02:54 +08:00
|
|
|
|
2008-02-20 02:52:54 +08:00
|
|
|
NodeSet S1;
|
|
|
|
QualType T = CastE->getType();
|
|
|
|
|
2008-03-05 06:16:08 +08:00
|
|
|
if (T->isReferenceType())
|
|
|
|
VisitLVal(Ex, Pred, S1);
|
|
|
|
else
|
|
|
|
Visit(Ex, Pred, S1);
|
|
|
|
|
2008-02-20 02:47:04 +08:00
|
|
|
// Check for redundant casts or casting to "void"
|
|
|
|
if (T->isVoidType() ||
|
2008-02-22 02:02:17 +08:00
|
|
|
Ex->getType() == T ||
|
|
|
|
(T->isPointerType() && Ex->getType()->isFunctionType())) {
|
2008-02-20 02:52:54 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1)
|
2008-02-20 02:52:54 +08:00
|
|
|
Dst.Add(*I1);
|
|
|
|
|
2008-01-24 10:02:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) {
|
2008-01-24 10:02:54 +08:00
|
|
|
NodeTy* N = *I1;
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(N);
|
2008-03-05 06:16:08 +08:00
|
|
|
|
|
|
|
RVal V = T->isReferenceType() ? GetLVal(St, Ex) : GetRVal(St, Ex);
|
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, CastE, N, SetRVal(St, CastE, EvalCast(V, CastE->getType())));
|
2008-01-24 10:02:54 +08:00
|
|
|
}
|
2008-01-25 04:55:43 +08:00
|
|
|
}
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRExprEngine::VisitDeclStmt(DeclStmt* DS, GRExprEngine::NodeTy* Pred,
|
2008-02-22 02:02:17 +08:00
|
|
|
GRExprEngine::NodeSet& Dst) {
|
2008-01-25 04:55:43 +08:00
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(Pred);
|
2008-01-25 04:55:43 +08:00
|
|
|
|
|
|
|
for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator())
|
2008-01-29 06:51:57 +08:00
|
|
|
if (const VarDecl* VD = dyn_cast<VarDecl>(D)) {
|
2008-02-19 08:29:51 +08:00
|
|
|
|
|
|
|
// FIXME: Add support for local arrays.
|
|
|
|
if (VD->getType()->isArrayType())
|
|
|
|
continue;
|
|
|
|
|
2008-02-28 03:21:33 +08:00
|
|
|
const Expr* Ex = VD->getInit();
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-28 03:21:33 +08:00
|
|
|
if (!VD->hasGlobalStorage() || VD->getStorageClass() == VarDecl::Static) {
|
|
|
|
|
|
|
|
// In this context, Static => Local variable.
|
|
|
|
|
|
|
|
assert (!VD->getStorageClass() == VarDecl::Static ||
|
2008-04-16 06:42:06 +08:00
|
|
|
!VD->isFileVarDecl());
|
2008-02-28 03:21:33 +08:00
|
|
|
|
|
|
|
// If there is no initializer, set the value of the
|
2008-02-28 17:25:22 +08:00
|
|
|
// variable to "Undefined".
|
2008-02-28 03:21:33 +08:00
|
|
|
//
|
|
|
|
// FIXME: static variables may have an initializer, but the second
|
|
|
|
// time a function is called those values may not be current.
|
2008-03-05 04:40:11 +08:00
|
|
|
|
|
|
|
QualType T = VD->getType();
|
2008-02-28 03:21:33 +08:00
|
|
|
|
2008-03-04 12:18:04 +08:00
|
|
|
if ( VD->getStorageClass() == VarDecl::Static) {
|
|
|
|
|
|
|
|
// C99: 6.7.8 Initialization
|
|
|
|
// If an object that has static storage duration is not initialized
|
|
|
|
// explicitly, then:
|
|
|
|
// —if it has pointer type, it is initialized to a null pointer;
|
|
|
|
// —if it has arithmetic type, it is initialized to (positive or
|
|
|
|
// unsigned) zero;
|
|
|
|
|
2008-03-05 04:40:11 +08:00
|
|
|
// FIXME: Handle structs. Now we treat their values as unknown.
|
|
|
|
|
2008-03-04 12:18:04 +08:00
|
|
|
if (T->isPointerType()) {
|
|
|
|
|
|
|
|
St = SetRVal(St, lval::DeclVal(VD),
|
2008-03-08 04:13:31 +08:00
|
|
|
lval::ConcreteInt(BasicVals.getValue(0, T)));
|
2008-03-04 12:18:04 +08:00
|
|
|
}
|
|
|
|
else if (T->isIntegerType()) {
|
|
|
|
|
|
|
|
St = SetRVal(St, lval::DeclVal(VD),
|
2008-03-08 04:13:31 +08:00
|
|
|
nonlval::ConcreteInt(BasicVals.getValue(0, T)));
|
2008-03-04 12:18:04 +08:00
|
|
|
}
|
|
|
|
|
2008-03-05 04:40:11 +08:00
|
|
|
|
2008-03-04 12:18:04 +08:00
|
|
|
}
|
2008-03-05 04:40:11 +08:00
|
|
|
else {
|
|
|
|
|
|
|
|
// FIXME: Handle structs. Now we treat them as unknown. What
|
|
|
|
// we need to do is treat their members as unknown.
|
2008-03-04 12:18:04 +08:00
|
|
|
|
2008-03-05 04:40:11 +08:00
|
|
|
if (T->isPointerType() || T->isIntegerType())
|
|
|
|
St = SetRVal(St, lval::DeclVal(VD),
|
|
|
|
Ex ? GetRVal(St, Ex) : UndefinedVal());
|
|
|
|
}
|
2008-02-28 03:21:33 +08:00
|
|
|
}
|
2008-01-29 06:51:57 +08:00
|
|
|
}
|
2008-01-25 04:55:43 +08:00
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, DS, Pred, St);
|
2008-01-25 04:55:43 +08:00
|
|
|
}
|
2008-01-24 10:02:54 +08:00
|
|
|
|
2008-02-05 08:26:40 +08:00
|
|
|
|
|
|
|
|
2008-02-13 03:49:57 +08:00
|
|
|
/// VisitSizeOfAlignOfTypeExpr - Transfer function for sizeof(type).
|
2008-02-22 02:02:17 +08:00
|
|
|
void GRExprEngine::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr* Ex,
|
|
|
|
NodeTy* Pred,
|
|
|
|
NodeSet& Dst) {
|
2008-02-22 02:43:30 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
QualType T = Ex->getArgumentType();
|
2008-03-15 11:13:20 +08:00
|
|
|
uint64_t amt;
|
2008-02-22 02:15:29 +08:00
|
|
|
|
2008-03-15 11:13:20 +08:00
|
|
|
if (Ex->isSizeOf()) {
|
|
|
|
|
|
|
|
// FIXME: Add support for VLAs.
|
|
|
|
if (!T.getTypePtr()->isConstantSizeType())
|
|
|
|
return;
|
|
|
|
|
|
|
|
amt = 1; // Handle sizeof(void)
|
|
|
|
|
|
|
|
if (T != getContext().VoidTy)
|
|
|
|
amt = getContext().getTypeSize(T) / 8;
|
|
|
|
|
|
|
|
}
|
|
|
|
else // Get alignment of the type.
|
2008-03-15 11:13:55 +08:00
|
|
|
amt = getContext().getTypeAlign(T) / 8;
|
2008-02-13 03:49:57 +08:00
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, Ex, Pred,
|
2008-03-10 12:11:42 +08:00
|
|
|
SetRVal(GetState(Pred), Ex,
|
2008-03-15 11:13:20 +08:00
|
|
|
NonLVal::MakeVal(BasicVals, amt, Ex->getType())));
|
2008-02-13 03:49:57 +08:00
|
|
|
}
|
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
void GRExprEngine::VisitDeref(UnaryOperator* U, NodeTy* Pred,
|
|
|
|
NodeSet& Dst, bool GetLVal) {
|
2008-04-22 07:43:38 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
Expr* Ex = U->getSubExpr()->IgnoreParens();
|
2008-04-22 07:43:38 +08:00
|
|
|
|
2008-02-20 12:02:35 +08:00
|
|
|
NodeSet DstTmp;
|
2008-02-07 12:16:04 +08:00
|
|
|
|
2008-02-26 11:44:25 +08:00
|
|
|
if (isa<DeclRefExpr>(Ex))
|
2008-02-20 12:02:35 +08:00
|
|
|
DstTmp.Add(Pred);
|
2008-02-07 12:16:04 +08:00
|
|
|
else
|
2008-02-22 02:02:17 +08:00
|
|
|
Visit(Ex, Pred, DstTmp);
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator I = DstTmp.begin(), DE = DstTmp.end(); I != DE; ++I) {
|
2008-04-22 07:43:38 +08:00
|
|
|
ValueState* St = GetState(Pred);
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal V = GetRVal(St, Ex);
|
2008-04-22 07:43:38 +08:00
|
|
|
VisitDeref(U, V, St, Pred, Dst, GetLVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitDeref(Expr* Ex, RVal V, ValueState* St, NodeTy* Pred,
|
|
|
|
NodeSet& Dst, bool GetLVal) {
|
|
|
|
|
|
|
|
// Check for dereferences of undefined values.
|
|
|
|
|
|
|
|
if (V.isUndef()) {
|
|
|
|
if (NodeTy* Succ = Builder->generateNode(Ex, St, Pred)) {
|
|
|
|
Succ->markAsSink();
|
|
|
|
UndefDeref.insert(Succ);
|
2008-02-20 12:02:35 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for dereferences of unknown values. Treat as No-Ops.
|
|
|
|
|
|
|
|
if (V.isUnknown()) {
|
|
|
|
Dst.Add(Pred);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After a dereference, one of two possible situations arise:
|
|
|
|
// (1) A crash, because the pointer was NULL.
|
|
|
|
// (2) The pointer is not NULL, and the dereference works.
|
|
|
|
//
|
|
|
|
// We add these assumptions.
|
|
|
|
|
|
|
|
LVal LV = cast<LVal>(V);
|
|
|
|
bool isFeasibleNotNull;
|
|
|
|
|
|
|
|
// "Assume" that the pointer is Not-NULL.
|
|
|
|
|
|
|
|
ValueState* StNotNull = Assume(St, LV, true, isFeasibleNotNull);
|
|
|
|
|
|
|
|
if (isFeasibleNotNull) {
|
2008-01-24 10:28:56 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
if (GetLVal)
|
|
|
|
MakeNode(Dst, Ex, Pred, SetRVal(StNotNull, Ex, LV));
|
|
|
|
else {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
// FIXME: Currently symbolic analysis "generates" new symbols
|
|
|
|
// for the contents of values. We need a better approach.
|
|
|
|
|
|
|
|
MakeNode(Dst, Ex, Pred,
|
|
|
|
SetRVal(StNotNull, Ex, GetRVal(StNotNull, LV, Ex->getType())));
|
2008-02-20 12:02:35 +08:00
|
|
|
}
|
2008-04-22 07:43:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isFeasibleNull;
|
|
|
|
|
|
|
|
// Now "assume" that the pointer is NULL.
|
|
|
|
|
|
|
|
ValueState* StNull = Assume(St, LV, false, isFeasibleNull);
|
|
|
|
|
|
|
|
if (isFeasibleNull) {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
// We don't use "MakeNode" here because the node will be a sink
|
|
|
|
// and we have no intention of processing it later.
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
NodeTy* NullNode = Builder->generateNode(Ex, StNull, Pred);
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
if (NullNode) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
NullNode->markAsSink();
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
if (isFeasibleNotNull) ImplicitNullDeref.insert(NullNode);
|
|
|
|
else ExplicitNullDeref.insert(NullNode);
|
|
|
|
}
|
2008-02-20 12:02:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, NodeTy* Pred,
|
|
|
|
NodeSet& Dst) {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
|
|
|
NodeSet S1;
|
|
|
|
|
|
|
|
assert (U->getOpcode() != UnaryOperator::Deref);
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (U->getOpcode() != UnaryOperator::SizeOf);
|
|
|
|
assert (U->getOpcode() != UnaryOperator::AlignOf);
|
|
|
|
|
|
|
|
bool use_GetLVal = false;
|
2008-02-20 12:02:35 +08:00
|
|
|
|
|
|
|
switch (U->getOpcode()) {
|
|
|
|
case UnaryOperator::PostInc:
|
|
|
|
case UnaryOperator::PostDec:
|
|
|
|
case UnaryOperator::PreInc:
|
|
|
|
case UnaryOperator::PreDec:
|
|
|
|
case UnaryOperator::AddrOf:
|
2008-02-22 02:02:17 +08:00
|
|
|
// Evalue subexpression as an LVal.
|
|
|
|
use_GetLVal = true;
|
|
|
|
VisitLVal(U->getSubExpr(), Pred, S1);
|
2008-02-20 12:02:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Visit(U->getSubExpr(), Pred, S1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator I1 = S1.begin(), E1 = S1.end(); I1 != E1; ++I1) {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-01-24 10:28:56 +08:00
|
|
|
NodeTy* N1 = *I1;
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(N1);
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
RVal SubV = use_GetLVal ? GetLVal(St, U->getSubExpr()) :
|
|
|
|
GetRVal(St, U->getSubExpr());
|
|
|
|
|
|
|
|
if (SubV.isUnknown()) {
|
|
|
|
Dst.Add(N1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (SubV.isUndef()) {
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, U, N1, SetRVal(St, U, SubV));
|
2008-02-22 02:02:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-01-24 10:28:56 +08:00
|
|
|
|
2008-02-16 06:09:30 +08:00
|
|
|
if (U->isIncrementDecrementOp()) {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
|
|
|
// Handle ++ and -- (both pre- and post-increment).
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
LVal SubLV = cast<LVal>(SubV);
|
|
|
|
RVal V = GetRVal(St, SubLV, U->getType());
|
|
|
|
|
2008-02-22 03:15:37 +08:00
|
|
|
if (V.isUnknown()) {
|
|
|
|
Dst.Add(N1);
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Propagate undefined values.
|
|
|
|
if (V.isUndef()) {
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, U, N1, SetRVal(St, U, V));
|
2008-02-22 02:02:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-22 03:29:23 +08:00
|
|
|
// Handle all other values.
|
2008-02-16 06:09:30 +08:00
|
|
|
|
|
|
|
BinaryOperator::Opcode Op = U->isIncrementOp() ? BinaryOperator::Add
|
|
|
|
: BinaryOperator::Sub;
|
|
|
|
|
2008-02-22 03:29:23 +08:00
|
|
|
RVal Result = EvalBinOp(Op, V, MakeConstantVal(1U, U));
|
2008-02-16 06:09:30 +08:00
|
|
|
|
|
|
|
if (U->isPostfix())
|
2008-02-22 02:02:17 +08:00
|
|
|
St = SetRVal(SetRVal(St, U, V), SubLV, Result);
|
2008-02-16 06:09:30 +08:00
|
|
|
else
|
2008-02-22 02:02:17 +08:00
|
|
|
St = SetRVal(SetRVal(St, U, Result), SubLV, Result);
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, U, N1, St);
|
2008-02-16 06:09:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle all other unary operators.
|
|
|
|
|
|
|
|
switch (U->getOpcode()) {
|
2008-03-15 11:05:30 +08:00
|
|
|
|
|
|
|
case UnaryOperator::Extension:
|
|
|
|
St = SetRVal(St, U, SubV);
|
|
|
|
break;
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case UnaryOperator::Minus:
|
|
|
|
St = SetRVal(St, U, EvalMinus(U, cast<NonLVal>(SubV)));
|
2008-01-24 16:20:02 +08:00
|
|
|
break;
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case UnaryOperator::Not:
|
|
|
|
St = SetRVal(St, U, EvalComplement(cast<NonLVal>(SubV)));
|
2008-02-20 12:12:31 +08:00
|
|
|
break;
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
case UnaryOperator::LNot:
|
2008-02-05 00:58:30 +08:00
|
|
|
|
2008-02-07 01:56:00 +08:00
|
|
|
// C99 6.5.3.3: "The expression !E is equivalent to (0==E)."
|
|
|
|
//
|
|
|
|
// Note: technically we do "E == 0", but this is the same in the
|
|
|
|
// transfer functions as "0 == E".
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
if (isa<LVal>(SubV)) {
|
2008-03-08 04:13:31 +08:00
|
|
|
lval::ConcreteInt V(BasicVals.getZeroWithPtrWidth());
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal Result = EvalBinOp(BinaryOperator::EQ, cast<LVal>(SubV), V);
|
|
|
|
St = SetRVal(St, U, Result);
|
2008-02-07 01:56:00 +08:00
|
|
|
}
|
|
|
|
else {
|
2008-02-22 08:42:36 +08:00
|
|
|
Expr* Ex = U->getSubExpr();
|
2008-03-08 04:13:31 +08:00
|
|
|
nonlval::ConcreteInt V(BasicVals.getValue(0, Ex->getType()));
|
2008-02-22 02:02:17 +08:00
|
|
|
RVal Result = EvalBinOp(BinaryOperator::EQ, cast<NonLVal>(SubV), V);
|
|
|
|
St = SetRVal(St, U, Result);
|
2008-02-07 01:56:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2008-01-31 10:35:41 +08:00
|
|
|
case UnaryOperator::AddrOf: {
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (isa<LVal>(SubV));
|
|
|
|
St = SetRVal(St, U, SubV);
|
2008-01-31 10:35:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-02-07 13:48:01 +08:00
|
|
|
|
2008-01-24 10:28:56 +08:00
|
|
|
default: ;
|
|
|
|
assert (false && "Not implemented.");
|
2008-02-22 02:02:17 +08:00
|
|
|
}
|
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, U, N1, St);
|
2008-01-24 10:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
void GRExprEngine::VisitSizeOfExpr(UnaryOperator* U, NodeTy* Pred,
|
|
|
|
NodeSet& Dst) {
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
QualType T = U->getSubExpr()->getType();
|
|
|
|
|
|
|
|
// FIXME: Add support for VLAs.
|
|
|
|
if (!T.getTypePtr()->isConstantSizeType())
|
|
|
|
return;
|
2008-02-20 12:02:35 +08:00
|
|
|
|
2008-03-06 02:54:05 +08:00
|
|
|
uint64_t size = getContext().getTypeSize(T) / 8;
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(Pred);
|
2008-03-08 04:13:31 +08:00
|
|
|
St = SetRVal(St, U, NonLVal::MakeVal(BasicVals, size, U->getType()));
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, U, Pred, St);
|
2008-02-22 02:02:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitLVal(Expr* Ex, NodeTy* Pred, NodeSet& Dst) {
|
2008-02-27 15:04:16 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
Ex = Ex->IgnoreParens();
|
2008-04-22 07:43:38 +08:00
|
|
|
|
|
|
|
if (Ex != CurrentStmt && getCFG().isBlkExpr(Ex)) {
|
2008-02-07 12:16:04 +08:00
|
|
|
Dst.Add(Pred);
|
2008-02-07 09:08:27 +08:00
|
|
|
return;
|
2008-02-07 12:16:04 +08:00
|
|
|
}
|
2008-02-07 09:08:27 +08:00
|
|
|
|
2008-04-22 07:43:38 +08:00
|
|
|
switch (Ex->getStmtClass()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Stmt::DeclRefExprClass:
|
|
|
|
Dst.Add(Pred);
|
2008-02-07 09:08:27 +08:00
|
|
|
return;
|
2008-04-22 07:43:38 +08:00
|
|
|
|
|
|
|
case Stmt::UnaryOperatorClass: {
|
|
|
|
UnaryOperator* U = cast<UnaryOperator>(Ex);
|
|
|
|
|
|
|
|
if (U->getOpcode() == UnaryOperator::Deref) {
|
|
|
|
VisitDeref(U, Pred, Dst, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-02-07 09:08:27 +08:00
|
|
|
}
|
2008-04-22 07:43:38 +08:00
|
|
|
|
|
|
|
case Stmt::MemberExprClass:
|
|
|
|
VisitMemberExpr(cast<MemberExpr>(Ex), Pred, Dst, true);
|
|
|
|
return;
|
|
|
|
}
|
2008-02-07 09:08:27 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
Visit(Ex, Pred, Dst);
|
2008-02-07 09:08:27 +08:00
|
|
|
}
|
|
|
|
|
2008-03-18 05:11:24 +08:00
|
|
|
void GRExprEngine::VisitAsmStmt(AsmStmt* A, NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
VisitAsmStmtHelperOutputs(A, A->begin_outputs(), A->end_outputs(), Pred, Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitAsmStmtHelperOutputs(AsmStmt* A,
|
|
|
|
AsmStmt::outputs_iterator I,
|
|
|
|
AsmStmt::outputs_iterator E,
|
|
|
|
NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
if (I == E) {
|
|
|
|
VisitAsmStmtHelperInputs(A, A->begin_inputs(), A->end_inputs(), Pred, Dst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeSet Tmp;
|
|
|
|
VisitLVal(*I, Pred, Tmp);
|
|
|
|
|
|
|
|
++I;
|
|
|
|
|
|
|
|
for (NodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
|
|
|
|
VisitAsmStmtHelperOutputs(A, I, E, *NI, Dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::VisitAsmStmtHelperInputs(AsmStmt* A,
|
|
|
|
AsmStmt::inputs_iterator I,
|
|
|
|
AsmStmt::inputs_iterator E,
|
|
|
|
NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
if (I == E) {
|
|
|
|
|
|
|
|
// We have processed both the inputs and the outputs. All of the outputs
|
|
|
|
// should evaluate to LVals. Nuke all of their values.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
ValueState* St = GetState(Pred);
|
|
|
|
|
|
|
|
for (AsmStmt::outputs_iterator OI = A->begin_outputs(),
|
|
|
|
OE = A->end_outputs(); OI != OE; ++OI) {
|
|
|
|
|
|
|
|
RVal X = GetLVal(St, *OI);
|
|
|
|
|
|
|
|
assert (!isa<NonLVal>(X));
|
|
|
|
|
|
|
|
if (isa<LVal>(X))
|
|
|
|
St = SetRVal(St, cast<LVal>(X), UnknownVal());
|
|
|
|
}
|
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, A, Pred, St);
|
2008-03-18 05:11:24 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeSet Tmp;
|
|
|
|
Visit(*I, Pred, Tmp);
|
|
|
|
|
|
|
|
++I;
|
|
|
|
|
|
|
|
for (NodeSet::iterator NI = Tmp.begin(), NE = Tmp.end(); NI != NE; ++NI)
|
|
|
|
VisitAsmStmtHelperInputs(A, I, E, *NI, Dst);
|
|
|
|
}
|
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
void GRExprEngine::EvalReturn(NodeSet& Dst, ReturnStmt* S, NodeTy* Pred) {
|
|
|
|
assert (Builder && "GRStmtNodeBuilder must be defined.");
|
|
|
|
|
|
|
|
unsigned size = Dst.size();
|
2008-04-19 04:35:30 +08:00
|
|
|
|
|
|
|
SaveAndRestore<bool> OldSink(Builder->BuildSinks),
|
|
|
|
OldHasGen(Builder->HasGeneratedNode);
|
2008-04-17 07:05:51 +08:00
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
Builder->HasGeneratedNode = false;
|
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
TF->EvalReturn(Dst, *this, *Builder, S, Pred);
|
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
// Handle the case where no nodes where generated.
|
2008-04-17 07:05:51 +08:00
|
|
|
|
2008-04-19 04:35:30 +08:00
|
|
|
if (!Builder->BuildSinks && Dst.size() == size && !Builder->HasGeneratedNode)
|
2008-04-17 07:05:51 +08:00
|
|
|
MakeNode(Dst, S, Pred, GetState(Pred));
|
|
|
|
}
|
|
|
|
|
2008-03-31 23:02:58 +08:00
|
|
|
void GRExprEngine::VisitReturnStmt(ReturnStmt* S, NodeTy* Pred, NodeSet& Dst) {
|
|
|
|
|
|
|
|
Expr* R = S->getRetValue();
|
|
|
|
|
|
|
|
if (!R) {
|
2008-04-17 07:05:51 +08:00
|
|
|
EvalReturn(Dst, S, Pred);
|
2008-03-31 23:02:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-04-17 07:05:51 +08:00
|
|
|
|
|
|
|
NodeSet DstRet;
|
2008-03-31 23:02:58 +08:00
|
|
|
QualType T = R->getType();
|
|
|
|
|
2008-04-03 01:45:06 +08:00
|
|
|
if (T->isPointerLikeType()) {
|
2008-03-31 23:02:58 +08:00
|
|
|
|
|
|
|
// Check if any of the return values return the address of a stack variable.
|
|
|
|
|
|
|
|
NodeSet Tmp;
|
|
|
|
Visit(R, Pred, Tmp);
|
|
|
|
|
|
|
|
for (NodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
|
|
|
|
RVal X = GetRVal((*I)->getState(), R);
|
|
|
|
|
|
|
|
if (isa<lval::DeclVal>(X)) {
|
|
|
|
|
|
|
|
if (cast<lval::DeclVal>(X).getDecl()->hasLocalStorage()) {
|
|
|
|
|
|
|
|
// Create a special node representing the v
|
|
|
|
|
|
|
|
NodeTy* RetStackNode = Builder->generateNode(S, GetState(*I), *I);
|
|
|
|
|
|
|
|
if (RetStackNode) {
|
|
|
|
RetStackNode->markAsSink();
|
|
|
|
RetsStackAddr.insert(RetStackNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
DstRet.Add(*I);
|
2008-03-31 23:02:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-04-17 07:05:51 +08:00
|
|
|
Visit(R, Pred, DstRet);
|
|
|
|
|
|
|
|
for (NodeSet::iterator I=DstRet.begin(), E=DstRet.end(); I!=E; ++I)
|
|
|
|
EvalReturn(Dst, S, *I);
|
2008-03-31 23:02:58 +08:00
|
|
|
}
|
2008-03-25 08:34:37 +08:00
|
|
|
|
2008-04-16 07:06:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transfer functions: Binary operators.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
|
2008-02-14 07:08:21 +08:00
|
|
|
GRExprEngine::NodeTy* Pred,
|
|
|
|
GRExprEngine::NodeSet& Dst) {
|
2008-01-24 03:59:44 +08:00
|
|
|
NodeSet S1;
|
2008-02-07 09:08:27 +08:00
|
|
|
|
|
|
|
if (B->isAssignmentOp())
|
2008-02-22 02:02:17 +08:00
|
|
|
VisitLVal(B->getLHS(), Pred, S1);
|
2008-02-07 09:08:27 +08:00
|
|
|
else
|
|
|
|
Visit(B->getLHS(), Pred, S1);
|
2008-01-16 08:53:15 +08:00
|
|
|
|
2008-01-24 03:59:44 +08:00
|
|
|
for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-01-24 03:59:44 +08:00
|
|
|
NodeTy* N1 = *I1;
|
2008-01-16 08:53:15 +08:00
|
|
|
|
2008-01-24 03:59:44 +08:00
|
|
|
// When getting the value for the LHS, check if we are in an assignment.
|
2008-02-22 02:02:17 +08:00
|
|
|
// In such cases, we want to (initially) treat the LHS as an LVal,
|
|
|
|
// so we use GetLVal instead of GetRVal so that DeclRefExpr's are
|
|
|
|
// evaluated to LValDecl's instead of to an NonLVal.
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
RVal LeftV = B->isAssignmentOp() ? GetLVal(GetState(N1), B->getLHS())
|
|
|
|
: GetRVal(GetState(N1), B->getLHS());
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
// Visit the RHS...
|
|
|
|
|
|
|
|
NodeSet S2;
|
2008-01-24 03:59:44 +08:00
|
|
|
Visit(B->getRHS(), N1, S2);
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
// Process the binary operator.
|
2008-01-24 03:59:44 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (NodeSet::iterator I2 = S2.begin(), E2 = S2.end(); I2 != E2; ++I2) {
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-01-24 03:59:44 +08:00
|
|
|
NodeTy* N2 = *I2;
|
2008-03-10 12:11:42 +08:00
|
|
|
ValueState* St = GetState(N2);
|
2008-02-26 02:42:54 +08:00
|
|
|
Expr* RHS = B->getRHS();
|
|
|
|
RVal RightV = GetRVal(St, RHS);
|
2008-01-24 03:59:44 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
BinaryOperator::Opcode Op = B->getOpcode();
|
|
|
|
|
2008-02-26 02:42:54 +08:00
|
|
|
if ((Op == BinaryOperator::Div || Op == BinaryOperator::Rem)
|
|
|
|
&& RHS->getType()->isIntegerType()) {
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Check if the denominator is undefined.
|
2008-02-26 02:42:54 +08:00
|
|
|
|
2008-02-27 06:27:51 +08:00
|
|
|
if (!RightV.isUnknown()) {
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (RightV.isUndef()) {
|
|
|
|
NodeTy* DivUndef = Builder->generateNode(B, St, N2);
|
2008-02-27 06:27:51 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (DivUndef) {
|
|
|
|
DivUndef->markAsSink();
|
2008-03-08 03:04:53 +08:00
|
|
|
ExplicitBadDivides.insert(DivUndef);
|
2008-02-27 06:27:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for divide/remainder-by-zero.
|
|
|
|
//
|
2008-02-28 17:25:22 +08:00
|
|
|
// First, "assume" that the denominator is 0 or undefined.
|
2008-02-27 06:27:51 +08:00
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
bool isFeasibleZero = false;
|
|
|
|
ValueState* ZeroSt = Assume(St, RightV, false, isFeasibleZero);
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
// Second, "assume" that the denominator cannot be 0.
|
|
|
|
|
|
|
|
bool isFeasibleNotZero = false;
|
|
|
|
St = Assume(St, RightV, true, isFeasibleNotZero);
|
|
|
|
|
|
|
|
// Create the node for the divide-by-zero (if it occurred).
|
|
|
|
|
|
|
|
if (isFeasibleZero)
|
2008-02-29 04:32:03 +08:00
|
|
|
if (NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2)) {
|
2008-02-27 06:27:51 +08:00
|
|
|
DivZeroNode->markAsSink();
|
2008-03-08 03:04:53 +08:00
|
|
|
|
|
|
|
if (isFeasibleNotZero)
|
|
|
|
ImplicitBadDivides.insert(DivZeroNode);
|
|
|
|
else
|
|
|
|
ExplicitBadDivides.insert(DivZeroNode);
|
|
|
|
|
2008-02-27 06:27:51 +08:00
|
|
|
}
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
if (!isFeasibleNotZero)
|
2008-02-27 06:27:51 +08:00
|
|
|
continue;
|
2008-02-26 01:51:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fall-through. The logic below processes the divide.
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:32:03 +08:00
|
|
|
|
2008-02-07 06:50:25 +08:00
|
|
|
if (Op <= BinaryOperator::Or) {
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
// Process non-assignements except commas or short-circuited
|
|
|
|
// logical expressions (LAnd and LOr).
|
|
|
|
|
|
|
|
RVal Result = EvalBinOp(Op, LeftV, RightV);
|
|
|
|
|
|
|
|
if (Result.isUnknown()) {
|
|
|
|
Dst.Add(N2);
|
2008-02-07 09:08:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-29 04:32:03 +08:00
|
|
|
if (Result.isUndef() && !LeftV.isUndef() && !RightV.isUndef()) {
|
|
|
|
|
|
|
|
// The operands were not undefined, but the result is undefined.
|
|
|
|
|
|
|
|
if (NodeTy* UndefNode = Builder->generateNode(B, St, N2)) {
|
|
|
|
UndefNode->markAsSink();
|
|
|
|
UndefResults.insert(UndefNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, N2, SetRVal(St, B, Result));
|
2008-02-07 06:50:25 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
// Process assignments.
|
|
|
|
|
|
|
|
switch (Op) {
|
|
|
|
|
2008-01-24 03:59:44 +08:00
|
|
|
case BinaryOperator::Assign: {
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
// Simple assignments.
|
2008-02-19 08:22:37 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (LeftV.isUndef()) {
|
|
|
|
HandleUndefinedStore(B, N2);
|
2008-02-22 02:02:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-03-13 05:45:47 +08:00
|
|
|
// EXPERIMENTAL: "Conjured" symbols.
|
|
|
|
|
|
|
|
if (RightV.isUnknown()) {
|
|
|
|
unsigned Count = Builder->getCurrentBlockCount();
|
|
|
|
SymbolID Sym = SymMgr.getConjuredSymbol(B->getRHS(), Count);
|
|
|
|
|
|
|
|
RightV = B->getRHS()->getType()->isPointerType()
|
|
|
|
? cast<RVal>(lval::SymbolVal(Sym))
|
|
|
|
: cast<RVal>(nonlval::SymbolVal(Sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate the effects of a "store": bind the value of the RHS
|
|
|
|
// to the L-Value represented by the LHS.
|
2008-02-19 08:22:37 +08:00
|
|
|
|
2008-04-17 07:05:51 +08:00
|
|
|
EvalStore(Dst, B, N2, SetRVal(St, B, RightV),
|
2008-04-17 04:40:59 +08:00
|
|
|
LeftV, RightV);
|
2008-04-17 02:21:25 +08:00
|
|
|
|
|
|
|
continue;
|
2008-01-24 03:59:44 +08:00
|
|
|
}
|
2008-02-07 06:50:25 +08:00
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
// Compound assignment operators.
|
|
|
|
|
|
|
|
default: {
|
2008-01-24 07:38:00 +08:00
|
|
|
|
2008-02-27 06:27:51 +08:00
|
|
|
assert (B->isCompoundAssignmentOp());
|
|
|
|
|
|
|
|
if (Op >= BinaryOperator::AndAssign)
|
|
|
|
((int&) Op) -= (BinaryOperator::AndAssign - BinaryOperator::And);
|
|
|
|
else
|
|
|
|
((int&) Op) -= BinaryOperator::MulAssign;
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Check if the LHS is undefined.
|
2008-02-19 08:22:37 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (LeftV.isUndef()) {
|
|
|
|
HandleUndefinedStore(B, N2);
|
2008-02-22 02:02:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LeftV.isUnknown()) {
|
2008-03-09 16:12:37 +08:00
|
|
|
assert (isa<UnknownVal>(GetRVal(St, B)));
|
|
|
|
Dst.Add(N2);
|
|
|
|
continue;
|
2008-02-19 08:22:37 +08:00
|
|
|
}
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
// At this pointer we know that the LHS evaluates to an LVal
|
2008-03-09 16:12:37 +08:00
|
|
|
// that is neither "Unknown" or "Undefined."
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
LVal LeftLV = cast<LVal>(LeftV);
|
|
|
|
|
|
|
|
// Fetch the value of the LHS (the value of the variable, etc.).
|
|
|
|
|
2008-03-10 12:11:42 +08:00
|
|
|
RVal V = GetRVal(GetState(N1), LeftLV, B->getLHS()->getType());
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Propagate undefined value (left-side). We
|
|
|
|
// propogate undefined values for the RHS below when
|
2008-02-27 06:27:51 +08:00
|
|
|
// we also check for divide-by-zero.
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (V.isUndef()) {
|
2008-02-22 02:02:17 +08:00
|
|
|
St = SetRVal(St, B, V);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Propagate unknown values.
|
|
|
|
|
2008-02-22 03:15:37 +08:00
|
|
|
if (V.isUnknown()) {
|
2008-03-09 16:12:37 +08:00
|
|
|
// The value bound to LeftV is unknown. Thus we just
|
|
|
|
// propagate the current node (as "B" is already bound to nothing).
|
|
|
|
assert (isa<UnknownVal>(GetRVal(St, B)));
|
2008-02-22 03:15:37 +08:00
|
|
|
Dst.Add(N2);
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
|
|
|
|
if (RightV.isUnknown()) {
|
2008-03-09 16:12:37 +08:00
|
|
|
assert (isa<UnknownVal>(GetRVal(St, B)));
|
|
|
|
St = SetRVal(St, LeftLV, UnknownVal());
|
2008-02-22 02:02:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-27 06:27:51 +08:00
|
|
|
// At this point:
|
|
|
|
//
|
2008-02-28 17:25:22 +08:00
|
|
|
// The LHS is not Undef/Unknown.
|
2008-02-27 06:27:51 +08:00
|
|
|
// The RHS is not Unknown.
|
2008-01-30 03:43:15 +08:00
|
|
|
|
2008-02-22 02:43:30 +08:00
|
|
|
// Get the computation type.
|
|
|
|
QualType CTy = cast<CompoundAssignOperator>(B)->getComputationType();
|
|
|
|
|
|
|
|
// Perform promotions.
|
|
|
|
V = EvalCast(V, CTy);
|
2008-02-22 02:46:24 +08:00
|
|
|
RightV = EvalCast(RightV, CTy);
|
2008-02-22 02:43:30 +08:00
|
|
|
|
|
|
|
// Evaluate operands and promote to result type.
|
2008-02-26 01:51:31 +08:00
|
|
|
|
2008-02-26 02:42:54 +08:00
|
|
|
if ((Op == BinaryOperator::Div || Op == BinaryOperator::Rem)
|
|
|
|
&& RHS->getType()->isIntegerType()) {
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Check if the denominator is undefined.
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (RightV.isUndef()) {
|
|
|
|
NodeTy* DivUndef = Builder->generateNode(B, St, N2);
|
2008-02-26 10:15:56 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (DivUndef) {
|
|
|
|
DivUndef->markAsSink();
|
2008-03-08 03:04:53 +08:00
|
|
|
ExplicitBadDivides.insert(DivUndef);
|
2008-02-26 10:15:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-27 06:27:51 +08:00
|
|
|
|
2008-02-26 01:51:31 +08:00
|
|
|
// First, "assume" that the denominator is 0.
|
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
bool isFeasibleZero = false;
|
|
|
|
ValueState* ZeroSt = Assume(St, RightV, false, isFeasibleZero);
|
2008-02-26 01:51:31 +08:00
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
// Second, "assume" that the denominator cannot be 0.
|
|
|
|
|
|
|
|
bool isFeasibleNotZero = false;
|
|
|
|
St = Assume(St, RightV, true, isFeasibleNotZero);
|
|
|
|
|
|
|
|
// Create the node for the divide-by-zero error (if it occurred).
|
|
|
|
|
|
|
|
if (isFeasibleZero) {
|
2008-02-26 01:51:31 +08:00
|
|
|
NodeTy* DivZeroNode = Builder->generateNode(B, ZeroSt, N2);
|
|
|
|
|
|
|
|
if (DivZeroNode) {
|
|
|
|
DivZeroNode->markAsSink();
|
2008-03-08 03:04:53 +08:00
|
|
|
|
|
|
|
if (isFeasibleNotZero)
|
|
|
|
ImplicitBadDivides.insert(DivZeroNode);
|
|
|
|
else
|
|
|
|
ExplicitBadDivides.insert(DivZeroNode);
|
2008-02-26 01:51:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-08 03:04:53 +08:00
|
|
|
if (!isFeasibleNotZero)
|
2008-02-26 01:51:31 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Fall-through. The logic below processes the divide.
|
|
|
|
}
|
2008-02-27 06:27:51 +08:00
|
|
|
else {
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
// Propagate undefined values (right-side).
|
2008-02-27 06:27:51 +08:00
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
if (RightV.isUndef()) {
|
2008-02-27 06:27:51 +08:00
|
|
|
St = SetRVal(SetRVal(St, B, RightV), LeftLV, RightV);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-02-26 01:51:31 +08:00
|
|
|
|
2008-02-22 02:43:30 +08:00
|
|
|
RVal Result = EvalCast(EvalBinOp(Op, V, RightV), B->getType());
|
2008-02-29 04:32:03 +08:00
|
|
|
|
|
|
|
if (Result.isUndef()) {
|
|
|
|
|
|
|
|
// The operands were not undefined, but the result is undefined.
|
|
|
|
|
|
|
|
if (NodeTy* UndefNode = Builder->generateNode(B, St, N2)) {
|
|
|
|
UndefNode->markAsSink();
|
|
|
|
UndefResults.insert(UndefNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-04-17 02:21:25 +08:00
|
|
|
// St = SetRVal(SetRVal(St, B, Result), LeftLV, Result);
|
2008-04-17 07:05:51 +08:00
|
|
|
EvalStore(Dst, B, N2, SetRVal(St, B, Result), LeftLV, Result);
|
2008-04-17 02:21:25 +08:00
|
|
|
continue;
|
2008-02-07 06:50:25 +08:00
|
|
|
}
|
2008-01-24 03:59:44 +08:00
|
|
|
}
|
2008-02-22 02:02:17 +08:00
|
|
|
|
2008-03-22 05:30:14 +08:00
|
|
|
MakeNode(Dst, B, N2, St);
|
2008-01-16 08:53:15 +08:00
|
|
|
}
|
2008-01-16 07:55:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 17:25:22 +08:00
|
|
|
void GRExprEngine::HandleUndefinedStore(Stmt* S, NodeTy* Pred) {
|
2008-03-10 12:11:42 +08:00
|
|
|
NodeTy* N = Builder->generateNode(S, GetState(Pred), Pred);
|
2008-02-19 08:22:37 +08:00
|
|
|
N->markAsSink();
|
2008-02-28 17:25:22 +08:00
|
|
|
UndefStores.insert(N);
|
2008-02-19 08:22:37 +08:00
|
|
|
}
|
2008-01-16 07:55:06 +08:00
|
|
|
|
2008-01-17 03:42:59 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// "Assume" logic.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* GRExprEngine::Assume(ValueState* St, LVal Cond,
|
2008-04-19 01:20:23 +08:00
|
|
|
bool Assumption, bool& isFeasible) {
|
|
|
|
|
|
|
|
St = AssumeAux(St, Cond, Assumption, isFeasible);
|
2008-04-19 03:23:43 +08:00
|
|
|
|
|
|
|
return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible)
|
|
|
|
: St;
|
2008-04-19 01:20:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueState* GRExprEngine::AssumeAux(ValueState* St, LVal Cond,
|
|
|
|
bool Assumption, bool& isFeasible) {
|
|
|
|
|
2008-02-01 14:36:40 +08:00
|
|
|
switch (Cond.getSubKind()) {
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (false && "'Assume' not implemented for this LVal.");
|
2008-02-01 14:36:40 +08:00
|
|
|
return St;
|
2008-04-19 01:20:23 +08:00
|
|
|
|
2008-02-06 08:54:14 +08:00
|
|
|
case lval::SymbolValKind:
|
|
|
|
if (Assumption)
|
|
|
|
return AssumeSymNE(St, cast<lval::SymbolVal>(Cond).getSymbol(),
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getZeroWithPtrWidth(), isFeasible);
|
2008-02-06 08:54:14 +08:00
|
|
|
else
|
|
|
|
return AssumeSymEQ(St, cast<lval::SymbolVal>(Cond).getSymbol(),
|
2008-03-08 04:13:31 +08:00
|
|
|
BasicVals.getZeroWithPtrWidth(), isFeasible);
|
2008-04-19 01:20:23 +08:00
|
|
|
|
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::DeclValKind:
|
2008-02-22 08:54:56 +08:00
|
|
|
case lval::FuncValKind:
|
|
|
|
case lval::GotoLabelKind:
|
2008-02-01 14:36:40 +08:00
|
|
|
isFeasible = Assumption;
|
|
|
|
return St;
|
2008-02-06 08:54:14 +08:00
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case lval::ConcreteIntKind: {
|
|
|
|
bool b = cast<lval::ConcreteInt>(Cond).getValue() != 0;
|
2008-02-01 14:36:40 +08:00
|
|
|
isFeasible = b ? Assumption : !Assumption;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
}
|
2008-01-31 07:03:39 +08:00
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState* GRExprEngine::Assume(ValueState* St, NonLVal Cond,
|
2008-04-19 01:20:23 +08:00
|
|
|
bool Assumption, bool& isFeasible) {
|
|
|
|
|
|
|
|
St = AssumeAux(St, Cond, Assumption, isFeasible);
|
2008-04-19 03:23:43 +08:00
|
|
|
|
|
|
|
return isFeasible ? TF->EvalAssume(*this, St, Cond, Assumption, isFeasible)
|
|
|
|
: St;
|
2008-04-19 01:20:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueState* GRExprEngine::AssumeAux(ValueState* St, NonLVal Cond,
|
|
|
|
bool Assumption, bool& isFeasible) {
|
2008-01-31 07:03:39 +08:00
|
|
|
switch (Cond.getSubKind()) {
|
|
|
|
default:
|
2008-02-22 02:02:17 +08:00
|
|
|
assert (false && "'Assume' not implemented for this NonLVal.");
|
2008-01-31 07:03:39 +08:00
|
|
|
return St;
|
|
|
|
|
2008-02-07 01:32:17 +08:00
|
|
|
|
|
|
|
case nonlval::SymbolValKind: {
|
2008-02-13 05:37:25 +08:00
|
|
|
nonlval::SymbolVal& SV = cast<nonlval::SymbolVal>(Cond);
|
2008-02-07 01:32:17 +08:00
|
|
|
SymbolID sym = SV.getSymbol();
|
|
|
|
|
|
|
|
if (Assumption)
|
2008-03-08 04:13:31 +08:00
|
|
|
return AssumeSymNE(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)),
|
2008-02-07 01:32:17 +08:00
|
|
|
isFeasible);
|
|
|
|
else
|
2008-03-08 04:13:31 +08:00
|
|
|
return AssumeSymEQ(St, sym, BasicVals.getValue(0, SymMgr.getType(sym)),
|
2008-02-07 01:32:17 +08:00
|
|
|
isFeasible);
|
|
|
|
}
|
|
|
|
|
2008-02-06 12:31:33 +08:00
|
|
|
case nonlval::SymIntConstraintValKind:
|
|
|
|
return
|
|
|
|
AssumeSymInt(St, Assumption,
|
|
|
|
cast<nonlval::SymIntConstraintVal>(Cond).getConstraint(),
|
|
|
|
isFeasible);
|
|
|
|
|
2008-02-06 05:52:21 +08:00
|
|
|
case nonlval::ConcreteIntKind: {
|
|
|
|
bool b = cast<nonlval::ConcreteInt>(Cond).getValue() != 0;
|
2008-01-31 07:03:39 +08:00
|
|
|
isFeasible = b ? Assumption : !Assumption;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState*
|
|
|
|
GRExprEngine::AssumeSymNE(ValueState* St, SymbolID sym,
|
2008-02-06 08:54:14 +08:00
|
|
|
const llvm::APSInt& V, bool& isFeasible) {
|
2008-02-19 06:57:02 +08:00
|
|
|
|
2008-02-06 08:54:14 +08:00
|
|
|
// First, determine if sym == X, where X != V.
|
2008-02-28 18:21:43 +08:00
|
|
|
if (const llvm::APSInt* X = St->getSymVal(sym)) {
|
2008-02-06 08:54:14 +08:00
|
|
|
isFeasible = *X != V;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second, determine if sym != V.
|
2008-02-28 18:21:43 +08:00
|
|
|
if (St->isNotEqual(sym, V)) {
|
2008-02-06 08:54:14 +08:00
|
|
|
isFeasible = true;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here, sym is not a constant and we don't know if it is != V.
|
|
|
|
// Make that assumption.
|
|
|
|
|
|
|
|
isFeasible = true;
|
|
|
|
return StateMgr.AddNE(St, sym, V);
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState*
|
|
|
|
GRExprEngine::AssumeSymEQ(ValueState* St, SymbolID sym,
|
2008-02-06 08:54:14 +08:00
|
|
|
const llvm::APSInt& V, bool& isFeasible) {
|
|
|
|
|
|
|
|
// First, determine if sym == X, where X != V.
|
2008-02-28 18:21:43 +08:00
|
|
|
if (const llvm::APSInt* X = St->getSymVal(sym)) {
|
2008-02-06 08:54:14 +08:00
|
|
|
isFeasible = *X == V;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second, determine if sym != V.
|
2008-02-28 18:21:43 +08:00
|
|
|
if (St->isNotEqual(sym, V)) {
|
2008-02-06 08:54:14 +08:00
|
|
|
isFeasible = false;
|
|
|
|
return St;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here, sym is not a constant and we don't know if it is == V.
|
|
|
|
// Make that assumption.
|
|
|
|
|
|
|
|
isFeasible = true;
|
|
|
|
return StateMgr.AddEQ(St, sym, V);
|
|
|
|
}
|
2008-01-31 07:03:39 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
ValueState*
|
|
|
|
GRExprEngine::AssumeSymInt(ValueState* St, bool Assumption,
|
2008-02-06 12:31:33 +08:00
|
|
|
const SymIntConstraint& C, bool& isFeasible) {
|
|
|
|
|
|
|
|
switch (C.getOpcode()) {
|
|
|
|
default:
|
|
|
|
// No logic yet for other operators.
|
2008-03-13 05:45:47 +08:00
|
|
|
isFeasible = true;
|
2008-02-06 12:31:33 +08:00
|
|
|
return St;
|
|
|
|
|
|
|
|
case BinaryOperator::EQ:
|
|
|
|
if (Assumption)
|
|
|
|
return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible);
|
|
|
|
else
|
|
|
|
return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible);
|
|
|
|
|
|
|
|
case BinaryOperator::NE:
|
|
|
|
if (Assumption)
|
|
|
|
return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible);
|
|
|
|
else
|
|
|
|
return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 02:18:48 +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
|
2008-02-14 01:41:41 +08:00
|
|
|
static GRExprEngine* GraphPrintCheckerState;
|
2008-03-08 04:57:30 +08:00
|
|
|
static SourceManager* GraphPrintSourceManager;
|
2008-03-12 03:02:40 +08:00
|
|
|
static ValueState::CheckerStatePrinter* GraphCheckerStatePrinter;
|
2008-01-31 07:24:39 +08:00
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
namespace llvm {
|
|
|
|
template<>
|
2008-02-14 01:41:41 +08:00
|
|
|
struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
|
2008-01-17 05:46:15 +08:00
|
|
|
public DefaultDOTGraphTraits {
|
2008-02-09 05:10:02 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
static void PrintVarBindings(std::ostream& Out, ValueState* St) {
|
2008-02-09 05:10:02 +08:00
|
|
|
|
|
|
|
Out << "Variables:\\l";
|
|
|
|
|
2008-01-25 06:27:20 +08:00
|
|
|
bool isFirst = true;
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
for (ValueState::vb_iterator I=St->vb_begin(), E=St->vb_end(); I!=E;++I) {
|
2008-02-09 05:10:02 +08:00
|
|
|
|
|
|
|
if (isFirst)
|
|
|
|
isFirst = false;
|
|
|
|
else
|
|
|
|
Out << "\\l";
|
|
|
|
|
|
|
|
Out << ' ' << I.getKey()->getName() << " : ";
|
|
|
|
I.getData().print(Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-02-12 03:21:59 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
static void PrintSubExprBindings(std::ostream& Out, ValueState* St){
|
2008-02-12 03:21:59 +08:00
|
|
|
|
2008-02-09 05:10:02 +08:00
|
|
|
bool isFirst = true;
|
2008-02-12 03:21:59 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
for (ValueState::seb_iterator I=St->seb_begin(), E=St->seb_end();I!=E;++I) {
|
2008-02-09 05:10:02 +08:00
|
|
|
|
2008-02-12 03:21:59 +08:00
|
|
|
if (isFirst) {
|
|
|
|
Out << "\\l\\lSub-Expressions:\\l";
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Out << "\\l";
|
|
|
|
|
|
|
|
Out << " (" << (void*) I.getKey() << ") ";
|
|
|
|
I.getKey()->printPretty(Out);
|
|
|
|
Out << " : ";
|
|
|
|
I.getData().print(Out);
|
|
|
|
}
|
|
|
|
}
|
2008-01-25 06:27:20 +08:00
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
static void PrintBlkExprBindings(std::ostream& Out, ValueState* St){
|
2008-02-12 03:21:59 +08:00
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
for (ValueState::beb_iterator I=St->beb_begin(), E=St->beb_end(); I!=E;++I){
|
2008-01-25 06:27:20 +08:00
|
|
|
if (isFirst) {
|
2008-02-12 03:21:59 +08:00
|
|
|
Out << "\\l\\lBlock-level Expressions:\\l";
|
2008-01-25 06:27:20 +08:00
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Out << "\\l";
|
2008-02-09 05:10:02 +08:00
|
|
|
|
2008-02-12 03:21:59 +08:00
|
|
|
Out << " (" << (void*) I.getKey() << ") ";
|
|
|
|
I.getKey()->printPretty(Out);
|
2008-01-25 06:27:20 +08:00
|
|
|
Out << " : ";
|
|
|
|
I.getData().print(Out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
static void PrintEQ(std::ostream& Out, ValueState* St) {
|
|
|
|
ValueState::ConstEqTy CE = St->ConstEq;
|
2008-02-06 11:56:15 +08:00
|
|
|
|
|
|
|
if (CE.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Out << "\\l\\|'==' constraints:";
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (ValueState::ConstEqTy::iterator I=CE.begin(), E=CE.end(); I!=E;++I)
|
2008-02-06 11:56:15 +08:00
|
|
|
Out << "\\l $" << I.getKey() << " : " << I.getData()->toString();
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
static void PrintNE(std::ostream& Out, ValueState* St) {
|
|
|
|
ValueState::ConstNotEqTy NE = St->ConstNotEq;
|
2008-02-06 11:56:15 +08:00
|
|
|
|
|
|
|
if (NE.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Out << "\\l\\|'!=' constraints:";
|
|
|
|
|
2008-02-22 02:02:17 +08:00
|
|
|
for (ValueState::ConstNotEqTy::iterator I=NE.begin(), EI=NE.end();
|
2008-02-06 11:56:15 +08:00
|
|
|
I != EI; ++I){
|
|
|
|
|
|
|
|
Out << "\\l $" << I.getKey() << " : ";
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
ValueState::IntSetTy::iterator J=I.getData().begin(),
|
|
|
|
EJ=I.getData().end();
|
|
|
|
for ( ; J != EJ; ++J) {
|
|
|
|
if (isFirst) isFirst = false;
|
|
|
|
else Out << ", ";
|
|
|
|
|
|
|
|
Out << (*J)->toString();
|
|
|
|
}
|
|
|
|
}
|
2008-02-15 06:54:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getNodeAttributes(const GRExprEngine::NodeTy* N, void*) {
|
|
|
|
|
|
|
|
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-08 03:04:53 +08:00
|
|
|
GraphPrintCheckerState->isExplicitBadDivide(N) ||
|
|
|
|
GraphPrintCheckerState->isImplicitBadDivide(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\"";
|
|
|
|
|
2008-02-29 04:32:03 +08:00
|
|
|
if (GraphPrintCheckerState->isNoReturnCall(N))
|
|
|
|
return "color=\"blue\",style=\"filled\"";
|
|
|
|
|
2008-02-15 06:54:53 +08:00
|
|
|
return "";
|
|
|
|
}
|
2008-02-06 11:56:15 +08:00
|
|
|
|
2008-02-14 01:41:41 +08:00
|
|
|
static std::string getNodeLabel(const GRExprEngine::NodeTy* N, void*) {
|
2008-01-17 05:46:15 +08:00
|
|
|
std::ostringstream Out;
|
2008-01-24 06:30:44 +08:00
|
|
|
|
|
|
|
// Program Location.
|
2008-01-17 05:46:15 +08:00
|
|
|
ProgramPoint Loc = N->getLocation();
|
|
|
|
|
|
|
|
switch (Loc.getKind()) {
|
|
|
|
case ProgramPoint::BlockEntranceKind:
|
|
|
|
Out << "Block Entrance: B"
|
|
|
|
<< cast<BlockEntrance>(Loc).getBlock()->getBlockID();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::BlockExitKind:
|
|
|
|
assert (false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ProgramPoint::PostStmtKind: {
|
2008-03-08 04:57:30 +08:00
|
|
|
const PostStmt& L = cast<PostStmt>(Loc);
|
|
|
|
Stmt* S = L.getStmt();
|
|
|
|
SourceLocation SLoc = S->getLocStart();
|
|
|
|
|
|
|
|
Out << S->getStmtClassName() << ' ' << (void*) S << ' ';
|
|
|
|
S->printPretty(Out);
|
2008-01-25 06:27:20 +08:00
|
|
|
|
2008-03-09 11:30:59 +08:00
|
|
|
if (SLoc.isFileID()) {
|
|
|
|
Out << "\\lline="
|
|
|
|
<< GraphPrintSourceManager->getLineNumber(SLoc) << " col="
|
|
|
|
<< GraphPrintSourceManager->getColumnNumber(SLoc) << "\\l";
|
|
|
|
}
|
2008-02-07 13:48:01 +08:00
|
|
|
|
2008-03-01 07:14:48 +08:00
|
|
|
if (GraphPrintCheckerState->isImplicitNullDeref(N))
|
2008-02-07 13:48:01 +08:00
|
|
|
Out << "\\|Implicit-Null Dereference.\\l";
|
2008-03-01 07:14:48 +08:00
|
|
|
else if (GraphPrintCheckerState->isExplicitNullDeref(N))
|
2008-02-07 14:04:18 +08:00
|
|
|
Out << "\\|Explicit-Null Dereference.\\l";
|
2008-03-01 07:14:48 +08:00
|
|
|
else if (GraphPrintCheckerState->isUndefDeref(N))
|
2008-02-28 17:25:22 +08:00
|
|
|
Out << "\\|Dereference of undefialied value.\\l";
|
2008-03-01 07:14:48 +08:00
|
|
|
else if (GraphPrintCheckerState->isUndefStore(N))
|
2008-02-28 17:25:22 +08:00
|
|
|
Out << "\\|Store to Undefined LVal.";
|
2008-03-08 03:04:53 +08:00
|
|
|
else if (GraphPrintCheckerState->isExplicitBadDivide(N))
|
|
|
|
Out << "\\|Explicit divide-by zero or undefined value.";
|
|
|
|
else if (GraphPrintCheckerState->isImplicitBadDivide(N))
|
|
|
|
Out << "\\|Implicit divide-by zero or undefined value.";
|
2008-03-01 07:14:48 +08:00
|
|
|
else if (GraphPrintCheckerState->isUndefResult(N))
|
2008-02-29 04:32:03 +08:00
|
|
|
Out << "\\|Result of operation is undefined.";
|
|
|
|
else if (GraphPrintCheckerState->isNoReturnCall(N))
|
|
|
|
Out << "\\|Call to function marked \"noreturn\".";
|
2008-03-01 07:14:48 +08:00
|
|
|
else if (GraphPrintCheckerState->isBadCall(N))
|
|
|
|
Out << "\\|Call to NULL/Undefined.";
|
2008-03-01 07:53:11 +08:00
|
|
|
else if (GraphPrintCheckerState->isUndefArg(N))
|
|
|
|
Out << "\\|Argument in call is undefined";
|
2008-02-07 13:48:01 +08:00
|
|
|
|
2008-01-17 05:46:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
const BlockEdge& E = cast<BlockEdge>(Loc);
|
|
|
|
Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B"
|
|
|
|
<< E.getDst()->getBlockID() << ')';
|
2008-01-31 07:03:39 +08:00
|
|
|
|
|
|
|
if (Stmt* T = E.getSrc()->getTerminator()) {
|
2008-03-08 04:57:30 +08:00
|
|
|
|
|
|
|
SourceLocation SLoc = T->getLocStart();
|
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
Out << "\\|Terminator: ";
|
2008-03-08 04:57:30 +08:00
|
|
|
|
2008-01-31 07:03:39 +08:00
|
|
|
E.getSrc()->printTerminator(Out);
|
|
|
|
|
2008-03-09 11:30:59 +08:00
|
|
|
if (SLoc.isFileID()) {
|
|
|
|
Out << "\\lline="
|
|
|
|
<< GraphPrintSourceManager->getLineNumber(SLoc) << " col="
|
|
|
|
<< GraphPrintSourceManager->getColumnNumber(SLoc);
|
|
|
|
}
|
2008-03-08 04:57:30 +08:00
|
|
|
|
2008-02-14 07:08:21 +08:00
|
|
|
if (isa<SwitchStmt>(T)) {
|
|
|
|
Stmt* Label = E.getDst()->getLabel();
|
|
|
|
|
|
|
|
if (Label) {
|
|
|
|
if (CaseStmt* C = dyn_cast<CaseStmt>(Label)) {
|
|
|
|
Out << "\\lcase ";
|
|
|
|
C->getLHS()->printPretty(Out);
|
|
|
|
|
|
|
|
if (Stmt* RHS = C->getRHS()) {
|
|
|
|
Out << " .. ";
|
|
|
|
RHS->printPretty(Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
Out << ":";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (isa<DefaultStmt>(Label));
|
|
|
|
Out << "\\ldefault:";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
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
|
|
|
|
Out << "false";
|
|
|
|
}
|
|
|
|
|
|
|
|
Out << "\\l";
|
|
|
|
}
|
2008-01-31 07:24:39 +08:00
|
|
|
|
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
|
|
|
}
|
2008-01-17 05:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 18:21:43 +08:00
|
|
|
Out << "\\|StateID: " << (void*) N->getState() << "\\|";
|
2008-02-09 05:10:02 +08:00
|
|
|
|
2008-03-12 03:02:40 +08:00
|
|
|
N->getState()->printDOT(Out, GraphCheckerStatePrinter);
|
2008-01-17 05:46:15 +08:00
|
|
|
|
2008-01-24 06:30:44 +08:00
|
|
|
Out << "\\l";
|
2008-01-17 05:46:15 +08:00
|
|
|
return Out.str();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end llvm namespace
|
|
|
|
#endif
|
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-13 01:18:20 +08:00
|
|
|
|
|
|
|
template <typename ITERATOR>
|
|
|
|
GRExprEngine::NodeTy* GetGraphNode(ITERATOR I) { return *I; }
|
|
|
|
|
|
|
|
template <>
|
|
|
|
GRExprEngine::NodeTy*
|
|
|
|
GetGraphNode<llvm::DenseMap<GRExprEngine::NodeTy*, Expr*>::iterator>
|
|
|
|
(llvm::DenseMap<GRExprEngine::NodeTy*, Expr*>::iterator I) {
|
|
|
|
return I->first;
|
|
|
|
}
|
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
template <typename ITERATOR>
|
2008-04-19 03:23:43 +08:00
|
|
|
static void AddSources(std::vector<GRExprEngine::NodeTy*>& Sources,
|
2008-03-13 01:18:20 +08:00
|
|
|
ITERATOR I, ITERATOR E) {
|
|
|
|
|
|
|
|
llvm::SmallPtrSet<void*,10> CachedSources;
|
2008-03-08 06:58:01 +08:00
|
|
|
|
2008-03-13 01:18:20 +08:00
|
|
|
for ( ; I != E; ++I ) {
|
|
|
|
GRExprEngine::NodeTy* N = GetGraphNode(I);
|
|
|
|
void* p = N->getLocation().getRawData();
|
|
|
|
|
|
|
|
if (CachedSources.count(p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CachedSources.insert(p);
|
|
|
|
|
|
|
|
Sources.push_back(N);
|
|
|
|
}
|
2008-03-08 06:58:01 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void GRExprEngine::ViewGraph(bool trim) {
|
2008-03-12 02:25:33 +08:00
|
|
|
#ifndef NDEBUG
|
2008-03-08 06:58:01 +08:00
|
|
|
if (trim) {
|
2008-04-19 03:23:43 +08:00
|
|
|
std::vector<NodeTy*> Src;
|
|
|
|
|
|
|
|
// Fixme: Migrate over to the new way of adding nodes.
|
2008-03-13 01:18:20 +08:00
|
|
|
AddSources(Src, null_derefs_begin(), null_derefs_end());
|
|
|
|
AddSources(Src, undef_derefs_begin(), undef_derefs_end());
|
|
|
|
AddSources(Src, explicit_bad_divides_begin(), explicit_bad_divides_end());
|
|
|
|
AddSources(Src, undef_results_begin(), undef_results_end());
|
|
|
|
AddSources(Src, bad_calls_begin(), bad_calls_end());
|
|
|
|
AddSources(Src, undef_arg_begin(), undef_arg_end());
|
2008-03-15 02:14:50 +08:00
|
|
|
AddSources(Src, undef_branches_begin(), undef_branches_end());
|
2008-03-13 01:18:20 +08:00
|
|
|
|
2008-04-19 03:23:43 +08:00
|
|
|
// The new way.
|
|
|
|
for (BugTypeSet::iterator I=BugTypes.begin(), E=BugTypes.end(); I!=E; ++I)
|
|
|
|
(*I)->GetErrorNodes(Src);
|
|
|
|
|
|
|
|
|
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-03-12 03:02:40 +08:00
|
|
|
GraphCheckerStatePrinter = TF->getCheckerStatePrinter();
|
2008-03-12 02:25:33 +08:00
|
|
|
|
2008-03-08 06:58:01 +08:00
|
|
|
llvm::ViewGraph(*G.roots_begin(), "GRExprEngine");
|
2008-03-12 02:25:33 +08:00
|
|
|
|
|
|
|
GraphPrintCheckerState = NULL;
|
|
|
|
GraphPrintSourceManager = NULL;
|
2008-03-12 03:02:40 +08:00
|
|
|
GraphCheckerStatePrinter = NULL;
|
2008-03-12 02:25:33 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GRExprEngine::ViewGraph(NodeTy** Beg, NodeTy** End) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
GraphPrintCheckerState = this;
|
|
|
|
GraphPrintSourceManager = &getContext().getSourceManager();
|
2008-03-12 03:02:40 +08:00
|
|
|
GraphCheckerStatePrinter = TF->getCheckerStatePrinter();
|
2008-03-08 06:58:01 +08:00
|
|
|
|
2008-03-12 02:25:33 +08:00
|
|
|
GRExprEngine::GraphTy* TrimmedG = G.Trim(Beg, End);
|
|
|
|
|
|
|
|
if (!TrimmedG)
|
|
|
|
llvm::cerr << "warning: Trimmed ExplodedGraph is empty.\n";
|
|
|
|
else {
|
|
|
|
llvm::ViewGraph(*TrimmedG->roots_begin(), "TrimmedGRExprEngine");
|
|
|
|
delete TrimmedG;
|
|
|
|
}
|
2008-03-08 06:58:01 +08:00
|
|
|
|
2008-01-31 07:24:39 +08:00
|
|
|
GraphPrintCheckerState = NULL;
|
2008-03-08 04:57:30 +08:00
|
|
|
GraphPrintSourceManager = NULL;
|
2008-03-12 03:02:40 +08:00
|
|
|
GraphCheckerStatePrinter = NULL;
|
2008-02-15 06:36:46 +08:00
|
|
|
#endif
|
2008-01-17 02:18:48 +08:00
|
|
|
}
|