Skip to content

Commit

Permalink
Remove recursive visitation in ExprEngine for UO_Not, UO_Minus, UO_LNot.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150509 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Feb 14, 2012
1 parent 224c489 commit a91ac5b
Showing 1 changed file with 39 additions and 50 deletions.
89 changes: 39 additions & 50 deletions lib/StaticAnalyzer/Core/ExprEngineC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,60 +626,49 @@ void ExprEngine::VisitUnaryOperator(const UnaryOperator* U,
case UO_Not: {
assert (!U->isLValue());
const Expr *Ex = U->getSubExpr()->IgnoreParens();
ExplodedNodeSet Tmp;
Visit(Ex, Pred, Tmp);

for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {
ProgramStateRef state = (*I)->getState();
const LocationContext *LCtx = (*I)->getLocationContext();
ProgramStateRef state = Pred->getState();
const LocationContext *LCtx = Pred->getLocationContext();

// Get the value of the subexpression.
SVal V = state->getSVal(Ex, LCtx);
// Get the value of the subexpression.
SVal V = state->getSVal(Ex, LCtx);

if (V.isUnknownOrUndef()) {
Bldr.generateNode(U, *I, state->BindExpr(U, LCtx, V));
continue;
}
if (V.isUnknownOrUndef()) {
Bldr.generateNode(U, Pred, state->BindExpr(U, LCtx, V));
break;
}

switch (U->getOpcode()) {
default:
llvm_unreachable("Invalid Opcode.");

case UO_Not:
// FIXME: Do we need to handle promotions?
state = state->BindExpr(U, LCtx, evalComplement(cast<NonLoc>(V)));
break;

case UO_Minus:
// FIXME: Do we need to handle promotions?
state = state->BindExpr(U, LCtx, evalMinus(cast<NonLoc>(V)));
break;

case UO_LNot:

// 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".
SVal Result;

if (isa<Loc>(V)) {
Loc X = svalBuilder.makeNull();
Result = evalBinOp(state, BO_EQ, cast<Loc>(V), X,
U->getType());
}
else {
nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
Result = evalBinOp(state, BO_EQ, cast<NonLoc>(V), X,
U->getType());
}

state = state->BindExpr(U, LCtx, Result);

break;
}
Bldr.generateNode(U, *I, state);
switch (U->getOpcode()) {
default:
llvm_unreachable("Invalid Opcode.");
case UO_Not:
// FIXME: Do we need to handle promotions?
state = state->BindExpr(U, LCtx, evalComplement(cast<NonLoc>(V)));
break;
case UO_Minus:
// FIXME: Do we need to handle promotions?
state = state->BindExpr(U, LCtx, evalMinus(cast<NonLoc>(V)));
break;
case UO_LNot:
// 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".
SVal Result;
if (isa<Loc>(V)) {
Loc X = svalBuilder.makeNull();
Result = evalBinOp(state, BO_EQ, cast<Loc>(V), X,
U->getType());
}
else {
nonloc::ConcreteInt X(getBasicVals().getValue(0, Ex->getType()));
Result = evalBinOp(state, BO_EQ, cast<NonLoc>(V), X,
U->getType());
}

state = state->BindExpr(U, LCtx, Result);
break;
}
Bldr.generateNode(U, Pred, state);
break;
}
}
Expand Down

0 comments on commit a91ac5b

Please sign in to comment.