2008-08-29 23:09:12 +08:00
|
|
|
//== BasicConstraintManager.cpp - Manage basic constraints.------*- C++ -*--==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
// This file defines BasicConstraintManager, a class that tracks simple
|
2011-08-16 06:09:50 +08:00
|
|
|
// equality and inequality constraints on symbolic values of ProgramState.
|
2008-08-29 23:09:12 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-15 01:08:39 +08:00
|
|
|
#include "SimpleConstraintManager.h"
|
2011-08-16 06:09:50 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
|
2008-08-29 22:52:36 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-08-27 22:03:33 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2008-08-27 22:03:33 +08:00
|
|
|
|
2009-01-26 14:04:53 +08:00
|
|
|
|
2009-11-28 14:07:30 +08:00
|
|
|
namespace { class ConstNotEq {}; }
|
|
|
|
namespace { class ConstEq {}; }
|
2008-08-27 22:03:33 +08:00
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
typedef llvm::ImmutableMap<SymbolRef,ProgramState::IntSetTy> ConstNotEqTy;
|
2008-12-05 10:27:51 +08:00
|
|
|
typedef llvm::ImmutableMap<SymbolRef,const llvm::APSInt*> ConstEqTy;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-26 14:04:53 +08:00
|
|
|
static int ConstEqIndex = 0;
|
|
|
|
static int ConstNotEqIndex = 0;
|
2008-08-29 22:52:36 +08:00
|
|
|
|
2009-01-26 14:04:53 +08:00
|
|
|
namespace clang {
|
2010-12-23 15:20:52 +08:00
|
|
|
namespace ento {
|
2009-01-26 14:04:53 +08:00
|
|
|
template<>
|
2011-08-16 06:09:50 +08:00
|
|
|
struct ProgramStateTrait<ConstNotEq> :
|
|
|
|
public ProgramStatePartialTrait<ConstNotEqTy> {
|
2011-08-13 07:37:29 +08:00
|
|
|
static inline void *GDMIndex() { return &ConstNotEqIndex; }
|
2009-01-26 14:04:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2011-08-16 06:09:50 +08:00
|
|
|
struct ProgramStateTrait<ConstEq> : public ProgramStatePartialTrait<ConstEqTy> {
|
2011-08-13 07:37:29 +08:00
|
|
|
static inline void *GDMIndex() { return &ConstEqIndex; }
|
2009-01-26 14:04:53 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2010-12-23 02:53:20 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-26 14:04:53 +08:00
|
|
|
namespace {
|
2008-08-27 22:03:33 +08:00
|
|
|
// BasicConstraintManager only tracks equality and inequality constraints of
|
|
|
|
// constants and integer variables.
|
2009-11-28 14:07:30 +08:00
|
|
|
class BasicConstraintManager
|
2009-02-15 01:08:39 +08:00
|
|
|
: public SimpleConstraintManager {
|
2011-08-16 06:09:50 +08:00
|
|
|
ProgramState::IntSetTy::Factory ISetFactory;
|
2008-08-27 22:03:33 +08:00
|
|
|
public:
|
2011-08-16 06:09:50 +08:00
|
|
|
BasicConstraintManager(ProgramStateManager &statemgr, SubEngine &subengine)
|
2010-01-05 08:15:18 +08:00
|
|
|
: SimpleConstraintManager(subengine),
|
|
|
|
ISetFactory(statemgr.getAllocator()) {}
|
2008-08-27 22:03:33 +08:00
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState *assumeSymNE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *assumeSymEQ(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *assumeSymLT(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *assumeSymGT(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *assumeSymGE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *assumeSymLE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V,
|
|
|
|
const llvm::APSInt& Adjustment);
|
|
|
|
|
|
|
|
const ProgramState *AddEQ(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V);
|
|
|
|
|
|
|
|
const ProgramState *AddNE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V);
|
|
|
|
|
|
|
|
const llvm::APSInt* getSymVal(const ProgramState *state,
|
|
|
|
SymbolRef sym) const;
|
|
|
|
|
|
|
|
bool isNotEqual(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V) const;
|
|
|
|
|
|
|
|
bool isEqual(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V) const;
|
|
|
|
|
|
|
|
const ProgramState *removeDeadBindings(const ProgramState *state,
|
|
|
|
SymbolReaper& SymReaper);
|
|
|
|
|
|
|
|
void print(const ProgramState *state,
|
|
|
|
raw_ostream &Out,
|
|
|
|
const char* nl,
|
|
|
|
const char *sep);
|
2008-08-29 22:52:36 +08:00
|
|
|
};
|
2008-08-27 22:03:33 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
ConstraintManager*
|
|
|
|
ento::CreateBasicConstraintManager(ProgramStateManager& statemgr,
|
|
|
|
SubEngine &subengine) {
|
2010-01-05 08:15:18 +08:00
|
|
|
return new BasicConstraintManager(statemgr, subengine);
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymNE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
|
|
|
// First, determine if sym == X, where X+Adjustment != V.
|
|
|
|
llvm::APSInt Adjusted = V-Adjustment;
|
2009-06-19 06:57:13 +08:00
|
|
|
if (const llvm::APSInt* X = getSymVal(state, sym)) {
|
2010-06-19 06:49:11 +08:00
|
|
|
bool isFeasible = (*X != Adjusted);
|
2009-06-19 06:57:13 +08:00
|
|
|
return isFeasible ? state : NULL;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2010-06-19 06:49:11 +08:00
|
|
|
// Second, determine if sym+Adjustment != V.
|
|
|
|
if (isNotEqual(state, sym, Adjusted))
|
2009-06-19 06:57:13 +08:00
|
|
|
return state;
|
2008-08-27 22:03:33 +08:00
|
|
|
|
|
|
|
// If we reach here, sym is not a constant and we don't know if it is != V.
|
|
|
|
// Make that assumption.
|
2010-06-19 06:49:11 +08:00
|
|
|
return AddNE(state, sym, Adjusted);
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymEQ(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
|
|
|
// First, determine if sym == X, where X+Adjustment != V.
|
|
|
|
llvm::APSInt Adjusted = V-Adjustment;
|
2009-06-19 06:57:13 +08:00
|
|
|
if (const llvm::APSInt* X = getSymVal(state, sym)) {
|
2010-06-19 06:49:11 +08:00
|
|
|
bool isFeasible = (*X == Adjusted);
|
2009-06-19 06:57:13 +08:00
|
|
|
return isFeasible ? state : NULL;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2010-06-19 06:49:11 +08:00
|
|
|
// Second, determine if sym+Adjustment != V.
|
|
|
|
if (isNotEqual(state, sym, Adjusted))
|
2009-06-19 06:57:13 +08:00
|
|
|
return NULL;
|
2008-08-27 22:03:33 +08:00
|
|
|
|
|
|
|
// If we reach here, sym is not a constant and we don't know if it is == V.
|
|
|
|
// Make that assumption.
|
2010-06-19 06:49:11 +08:00
|
|
|
return AddEQ(state, sym, Adjusted);
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2010-06-19 06:49:11 +08:00
|
|
|
// The logic for these will be handled in another ConstraintManager.
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymLT(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
2008-12-04 02:56:12 +08:00
|
|
|
// Is 'V' the smallest possible value?
|
2009-01-30 09:58:33 +08:00
|
|
|
if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) {
|
2008-12-04 02:56:12 +08:00
|
|
|
// sym cannot be any value less than 'V'. This path is infeasible.
|
2009-06-19 06:57:13 +08:00
|
|
|
return NULL;
|
2008-12-04 02:56:12 +08:00
|
|
|
}
|
2008-08-27 22:03:33 +08:00
|
|
|
|
|
|
|
// FIXME: For now have assuming x < y be the same as assuming sym != V;
|
2010-12-02 06:16:56 +08:00
|
|
|
return assumeSymNE(state, sym, V, Adjustment);
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymGT(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
2008-12-04 03:06:30 +08:00
|
|
|
// Is 'V' the largest possible value?
|
2009-01-30 09:58:33 +08:00
|
|
|
if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) {
|
2008-12-04 03:06:30 +08:00
|
|
|
// sym cannot be any value greater than 'V'. This path is infeasible.
|
2009-06-19 06:57:13 +08:00
|
|
|
return NULL;
|
2008-12-04 03:06:30 +08:00
|
|
|
}
|
|
|
|
|
2008-08-27 22:03:33 +08:00
|
|
|
// FIXME: For now have assuming x > y be the same as assuming sym != V;
|
2010-12-02 06:16:56 +08:00
|
|
|
return assumeSymNE(state, sym, V, Adjustment);
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymGE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
|
|
|
// Reject a path if the value of sym is a constant X and !(X+Adj >= V).
|
2009-06-19 06:57:13 +08:00
|
|
|
if (const llvm::APSInt *X = getSymVal(state, sym)) {
|
2010-06-19 06:49:11 +08:00
|
|
|
bool isFeasible = (*X >= V-Adjustment);
|
2009-06-19 06:57:13 +08:00
|
|
|
return isFeasible ? state : NULL;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-04 03:06:30 +08:00
|
|
|
// Sym is not a constant, but it is worth looking to see if V is the
|
|
|
|
// maximum integer value.
|
2009-01-30 09:58:33 +08:00
|
|
|
if (V == llvm::APSInt::getMaxValue(V.getBitWidth(), V.isUnsigned())) {
|
2010-06-19 06:49:11 +08:00
|
|
|
llvm::APSInt Adjusted = V-Adjustment;
|
|
|
|
|
|
|
|
// If we know that sym != V (after adjustment), then this condition
|
|
|
|
// is infeasible since there is no other value greater than V.
|
|
|
|
bool isFeasible = !isNotEqual(state, sym, Adjusted);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-04 03:06:30 +08:00
|
|
|
// If the path is still feasible then as a consequence we know that
|
2010-06-19 06:49:11 +08:00
|
|
|
// 'sym+Adjustment == V' because there are no larger values.
|
2008-12-04 03:06:30 +08:00
|
|
|
// Add this constraint.
|
2010-06-19 06:49:11 +08:00
|
|
|
return isFeasible ? AddEQ(state, sym, Adjusted) : NULL;
|
2008-12-04 03:06:30 +08:00
|
|
|
}
|
2008-08-27 22:03:33 +08:00
|
|
|
|
2009-06-19 06:57:13 +08:00
|
|
|
return state;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::assumeSymLE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2010-06-19 06:49:11 +08:00
|
|
|
const llvm::APSInt &V,
|
|
|
|
const llvm::APSInt &Adjustment) {
|
|
|
|
// Reject a path if the value of sym is a constant X and !(X+Adj <= V).
|
2009-06-19 06:57:13 +08:00
|
|
|
if (const llvm::APSInt* X = getSymVal(state, sym)) {
|
2010-06-19 06:49:11 +08:00
|
|
|
bool isFeasible = (*X <= V-Adjustment);
|
2009-06-19 06:57:13 +08:00
|
|
|
return isFeasible ? state : NULL;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-04 02:56:12 +08:00
|
|
|
// Sym is not a constant, but it is worth looking to see if V is the
|
|
|
|
// minimum integer value.
|
2009-01-30 09:58:33 +08:00
|
|
|
if (V == llvm::APSInt::getMinValue(V.getBitWidth(), V.isUnsigned())) {
|
2010-06-19 06:49:11 +08:00
|
|
|
llvm::APSInt Adjusted = V-Adjustment;
|
|
|
|
|
|
|
|
// If we know that sym != V (after adjustment), then this condition
|
|
|
|
// is infeasible since there is no other value less than V.
|
|
|
|
bool isFeasible = !isNotEqual(state, sym, Adjusted);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-12-04 02:56:12 +08:00
|
|
|
// If the path is still feasible then as a consequence we know that
|
2010-06-19 06:49:11 +08:00
|
|
|
// 'sym+Adjustment == V' because there are no smaller values.
|
2008-12-04 02:56:12 +08:00
|
|
|
// Add this constraint.
|
2010-06-19 06:49:11 +08:00
|
|
|
return isFeasible ? AddEQ(state, sym, Adjusted) : NULL;
|
2008-12-04 02:56:12 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-19 06:57:13 +08:00
|
|
|
return state;
|
2008-08-27 22:03:33 +08:00
|
|
|
}
|
2008-08-29 22:52:36 +08:00
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState *BasicConstraintManager::AddEQ(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2008-08-29 22:52:36 +08:00
|
|
|
const llvm::APSInt& V) {
|
|
|
|
// Create a new state with the old binding replaced.
|
2010-06-19 06:49:11 +08:00
|
|
|
return state->set<ConstEq>(sym, &state->getBasicVals().getValue(V));
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState *BasicConstraintManager::AddNE(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
|
|
|
const llvm::APSInt& V) {
|
2008-11-27 14:08:40 +08:00
|
|
|
|
2008-08-29 22:52:36 +08:00
|
|
|
// First, retrieve the NE-set associated with the given symbol.
|
2009-06-18 06:28:13 +08:00
|
|
|
ConstNotEqTy::data_type* T = state->get<ConstNotEq>(sym);
|
2011-08-16 06:09:50 +08:00
|
|
|
ProgramState::IntSetTy S = T ? *T : ISetFactory.getEmptySet();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-29 22:52:36 +08:00
|
|
|
// Now add V to the NE set.
|
2010-11-24 08:54:37 +08:00
|
|
|
S = ISetFactory.add(S, &state->getBasicVals().getValue(V));
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-29 22:52:36 +08:00
|
|
|
// Create a new state with the old binding replaced.
|
2009-06-18 06:28:13 +08:00
|
|
|
return state->set<ConstNotEq>(sym, S);
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
const llvm::APSInt* BasicConstraintManager::getSymVal(const ProgramState *state,
|
2009-02-15 01:08:39 +08:00
|
|
|
SymbolRef sym) const {
|
2009-06-19 06:57:13 +08:00
|
|
|
const ConstEqTy::data_type* T = state->get<ConstEq>(sym);
|
2009-02-15 01:08:39 +08:00
|
|
|
return T ? *T : NULL;
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
bool BasicConstraintManager::isNotEqual(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2008-08-29 22:52:36 +08:00
|
|
|
const llvm::APSInt& V) const {
|
|
|
|
|
|
|
|
// Retrieve the NE-set associated with the given symbol.
|
2009-06-19 06:57:13 +08:00
|
|
|
const ConstNotEqTy::data_type* T = state->get<ConstNotEq>(sym);
|
2008-08-29 22:52:36 +08:00
|
|
|
|
|
|
|
// See if V is present in the NE-set.
|
2010-06-19 06:49:11 +08:00
|
|
|
return T ? T->contains(&state->getBasicVals().getValue(V)) : false;
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
bool BasicConstraintManager::isEqual(const ProgramState *state,
|
|
|
|
SymbolRef sym,
|
2008-08-29 22:52:36 +08:00
|
|
|
const llvm::APSInt& V) const {
|
|
|
|
// Retrieve the EQ-set associated with the given symbol.
|
2009-06-19 06:57:13 +08:00
|
|
|
const ConstEqTy::data_type* T = state->get<ConstEq>(sym);
|
2008-08-29 22:52:36 +08:00
|
|
|
// See if V is present in the EQ-set.
|
|
|
|
return T ? **T == V : false;
|
|
|
|
}
|
|
|
|
|
2008-11-27 10:39:34 +08:00
|
|
|
/// Scan all symbols referenced by the constraints. If the symbol is not alive
|
|
|
|
/// as marked in LSymbols, mark it as dead in DSymbols.
|
2011-08-16 06:09:50 +08:00
|
|
|
const ProgramState*
|
|
|
|
BasicConstraintManager::removeDeadBindings(const ProgramState *state,
|
2009-01-22 06:26:05 +08:00
|
|
|
SymbolReaper& SymReaper) {
|
|
|
|
|
2009-06-18 06:28:13 +08:00
|
|
|
ConstEqTy CE = state->get<ConstEq>();
|
|
|
|
ConstEqTy::Factory& CEFactory = state->get_context<ConstEq>();
|
2008-08-29 22:52:36 +08:00
|
|
|
|
|
|
|
for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) {
|
2009-01-22 06:26:05 +08:00
|
|
|
SymbolRef sym = I.getKey();
|
2010-11-24 08:54:37 +08:00
|
|
|
if (SymReaper.maybeDead(sym))
|
|
|
|
CE = CEFactory.remove(CE, sym);
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
2009-06-18 06:28:13 +08:00
|
|
|
state = state->set<ConstEq>(CE);
|
2008-08-29 22:52:36 +08:00
|
|
|
|
2009-06-18 06:28:13 +08:00
|
|
|
ConstNotEqTy CNE = state->get<ConstNotEq>();
|
|
|
|
ConstNotEqTy::Factory& CNEFactory = state->get_context<ConstNotEq>();
|
2008-08-29 22:52:36 +08:00
|
|
|
|
|
|
|
for (ConstNotEqTy::iterator I = CNE.begin(), E = CNE.end(); I != E; ++I) {
|
2009-09-09 23:08:12 +08:00
|
|
|
SymbolRef sym = I.getKey();
|
2010-11-24 08:54:37 +08:00
|
|
|
if (SymReaper.maybeDead(sym))
|
|
|
|
CNE = CNEFactory.remove(CNE, sym);
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-18 06:28:13 +08:00
|
|
|
return state->set<ConstNotEq>(CNE);
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
void BasicConstraintManager::print(const ProgramState *state,
|
|
|
|
raw_ostream &Out,
|
2008-08-29 22:52:36 +08:00
|
|
|
const char* nl, const char *sep) {
|
|
|
|
// Print equality constraints.
|
|
|
|
|
2009-06-19 06:57:13 +08:00
|
|
|
ConstEqTy CE = state->get<ConstEq>();
|
2008-08-29 22:52:36 +08:00
|
|
|
|
|
|
|
if (!CE.isEmpty()) {
|
|
|
|
Out << nl << sep << "'==' constraints:";
|
2009-06-25 07:06:47 +08:00
|
|
|
for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I)
|
|
|
|
Out << nl << " $" << I.getKey() << " : " << *I.getData();
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print != constraints.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-19 06:57:13 +08:00
|
|
|
ConstNotEqTy CNE = state->get<ConstNotEq>();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-29 22:52:36 +08:00
|
|
|
if (!CNE.isEmpty()) {
|
|
|
|
Out << nl << sep << "'!=' constraints:";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-08-29 22:52:36 +08:00
|
|
|
for (ConstNotEqTy::iterator I = CNE.begin(), EI = CNE.end(); I!=EI; ++I) {
|
|
|
|
Out << nl << " $" << I.getKey() << " : ";
|
|
|
|
bool isFirst = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
ProgramState::IntSetTy::iterator J = I.getData().begin(),
|
2009-09-09 23:08:12 +08:00
|
|
|
EJ = I.getData().end();
|
|
|
|
|
|
|
|
for ( ; J != EJ; ++J) {
|
2008-08-29 22:52:36 +08:00
|
|
|
if (isFirst) isFirst = false;
|
|
|
|
else Out << ", ";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-11-10 13:00:06 +08:00
|
|
|
Out << (*J)->getSExtValue(); // Hack: should print to raw_ostream.
|
2008-08-29 22:52:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-30 10:06:22 +08:00
|
|
|
}
|