aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/Core
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-06-04 08:08:21 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-06-04 08:08:21 +0000
commit44e3d58b59099f5fd0e6f88893ce431171b3fef6 (patch)
tree12d7d9af1493e650a42f570de49401776cabde3b /lib/Core
parentc4a0e57c082e567e81ad3609a32ee492d41f03f9 (diff)
downloadklee-44e3d58b59099f5fd0e6f88893ce431171b3fef6.tar.gz
Start removing uses of Expr::isConstant.
- These should use cast<>, isa<>, or dyn_cast<> as appropriate (or better yet, changed to use ref<ConstantExpr> when the type is known). git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@72857 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/AddressSpace.cpp8
-rw-r--r--lib/Core/Executor.cpp59
-rw-r--r--lib/Core/Executor.h2
-rw-r--r--lib/Core/ImpliedValue.cpp7
-rw-r--r--lib/Core/ImpliedValue.h6
-rw-r--r--lib/Core/Memory.cpp2
-rw-r--r--lib/Core/SeedInfo.cpp6
-rw-r--r--lib/Core/SpecialFunctionHandler.cpp30
8 files changed, 58 insertions, 62 deletions
diff --git a/lib/Core/AddressSpace.cpp b/lib/Core/AddressSpace.cpp
index 92d75aa8..a4a65bd9 100644
--- a/lib/Core/AddressSpace.cpp
+++ b/lib/Core/AddressSpace.cpp
@@ -72,8 +72,8 @@ bool AddressSpace::resolveOne(ExecutionState &state,
ref<Expr> address,
ObjectPair &result,
bool &success) {
- if (address->isConstant()) {
- success = resolveOne(address->getConstantValue(), result);
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(address)) {
+ success = resolveOne(CE->getConstantValue(), result);
return true;
} else {
TimerStatIncrementer timer(stats::resolveTime);
@@ -163,9 +163,9 @@ bool AddressSpace::resolve(ExecutionState &state,
ResolutionList &rl,
unsigned maxResolutions,
double timeout) {
- if (p->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(p)) {
ObjectPair res;
- if (resolveOne(p->getConstantValue(), res))
+ if (resolveOne(CE->getConstantValue(), res))
rl.push_back(res);
return false;
} else {
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index a1687f58..f567efc6 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -662,8 +662,7 @@ Executor::fork(ExecutionState &current, ref<Expr> condition, bool isInternal) {
seedMap.find(&current);
bool isSeeding = it != seedMap.end();
- if (!isSeeding &&
- !condition->isConstant() &&
+ if (!isSeeding && !isa<ConstantExpr>(condition) &&
(MaxStaticForkPct!=1. || MaxStaticSolvePct != 1. ||
MaxStaticCPForkPct!=1. || MaxStaticCPSolvePct != 1.) &&
statsTracker->elapsed() > 60.) {
@@ -753,8 +752,8 @@ Executor::fork(ExecutionState &current, ref<Expr> condition, bool isInternal) {
bool success =
solver->getValue(current, siit->assignment.evaluate(condition), res);
assert(success && "FIXME: Unhandled solver failure");
- if (res->isConstant()) {
- if (res->getConstantValue()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(res)) {
+ if (CE->getConstantValue()) {
trueSeed = true;
} else {
falseSeed = true;
@@ -874,9 +873,8 @@ Executor::fork(ExecutionState &current, ref<Expr> condition, bool isInternal) {
}
void Executor::addConstraint(ExecutionState &state, ref<Expr> condition) {
- if (condition->isConstant()) {
- assert(condition->getConstantValue() &&
- "attempt to add invalid constraint");
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(condition)) {
+ assert(CE->getConstantValue() && "attempt to add invalid constraint");
return;
}
@@ -902,7 +900,8 @@ void Executor::addConstraint(ExecutionState &state, ref<Expr> condition) {
state.addConstraint(condition);
if (ivcEnabled)
- doImpliedValueConcretization(state, condition, ConstantExpr::alloc(1, Expr::Bool));
+ doImpliedValueConcretization(state, condition,
+ ConstantExpr::alloc(1, Expr::Bool));
}
ref<Expr> Executor::evalConstant(Constant *c) {
@@ -998,7 +997,7 @@ ref<Expr> Executor::toUnique(const ExecutionState &state,
ref<Expr> &e) {
ref<Expr> result = e;
- if (!e->isConstant()) {
+ if (!isa<ConstantExpr>(e)) {
ref<Expr> value(0);
bool isTrue = false;
@@ -1020,7 +1019,7 @@ ref<Expr> Executor::toConstant(ExecutionState &state,
ref<Expr> e,
const char *reason) {
e = state.constraints.simplifyExpr(e);
- if (!e->isConstant()) {
+ if (!isa<ConstantExpr>(e)) {
ref<Expr> value;
bool success = solver->getValue(state, e, value);
assert(success && "FIXME: Unhandled solver failure");
@@ -1049,7 +1048,7 @@ void Executor::executeGetValue(ExecutionState &state,
e = state.constraints.simplifyExpr(e);
std::map< ExecutionState*, std::vector<SeedInfo> >::iterator it =
seedMap.find(&state);
- if (it==seedMap.end() || e->isConstant()) {
+ if (it==seedMap.end() || isa<ConstantExpr>(e)) {
ref<Expr> value;
bool success = solver->getValue(state, e, value);
assert(success && "FIXME: Unhandled solver failure");
@@ -1393,11 +1392,11 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
BasicBlock *bb = si->getParent();
cond = toUnique(state, cond);
- if (cond->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(cond)) {
// Somewhat gross to create these all the time, but fine till we
// switch to an internal rep.
ConstantInt *ci = ConstantInt::get(si->getCondition()->getType(),
- cond->getConstantValue());
+ CE->getConstantValue());
unsigned index = si->findCaseValue(ci);
transferToBasicBlock(si->getSuccessor(index), si->getParent(), state);
} else {
@@ -2180,8 +2179,7 @@ void Executor::bindInstructionConstants(KInstruction *KI) {
}
index++;
}
- assert(constantOffset->isConstant());
- kgepi->offset = constantOffset->getConstantValue();
+ kgepi->offset = cast<ConstantExpr>(constantOffset)->getConstantValue();
}
void Executor::bindModuleConstants() {
@@ -2346,8 +2344,8 @@ std::string Executor::getAddressInfo(ExecutionState &state,
std::ostringstream info;
info << "\taddress: " << address << "\n";
uint64_t example;
- if (address->isConstant()) {
- example = address->getConstantValue();
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(address)) {
+ example = CE->getConstantValue();
} else {
ref<Expr> value;
bool success = solver->getValue(state, address, value);
@@ -2466,7 +2464,7 @@ void Executor::terminateStateOnError(ExecutionState &state,
msg << ai->getName();
// XXX should go through function
ref<Expr> value = sf.locals[sf.kf->getArgRegister(index++)].value;
- if (value->isConstant())
+ if (isa<ConstantExpr>(value))
msg << "=" << value;
}
msg << ")";
@@ -2521,9 +2519,9 @@ void Executor::callExternalFunction(ExecutionState &state,
static_cast<ConstantExpr*>(ce.get())->toMemory((void*) &args[i]);
} else {
ref<Expr> arg = toUnique(state, *ai);
- if (arg->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(arg)) {
// XXX kick toMemory functions from here
- static_cast<ConstantExpr*>(arg.get())->toMemory((void*) &args[i]);
+ CE->toMemory((void*) &args[i]);
} else {
std::string msg = "external call with symbolic argument: " + function->getName();
terminateStateOnExecError(state, msg);
@@ -2578,7 +2576,7 @@ ref<Expr> Executor::replaceReadWithSymbolic(ExecutionState &state,
return e;
// right now, we don't replace symbolics (is there any reason too?)
- if (!e->isConstant())
+ if (!isa<ConstantExpr>(e))
return e;
if (n != 1 && random() % n)
@@ -2620,9 +2618,9 @@ void Executor::executeAlloc(ExecutionState &state,
bool zeroMemory,
const ObjectState *reallocFrom) {
size = toUnique(state, size);
- if (size->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(size)) {
MemoryObject *mo =
- memory->allocate(size->getConstantValue(), isLocal, false,
+ memory->allocate(CE->getConstantValue(), isLocal, false,
state.prevPC->inst);
if (!mo) {
bindLocal(target, state, ConstantExpr::alloc(0, kMachinePointerType));
@@ -2793,9 +2791,9 @@ void Executor::executeMemoryOperation(ExecutionState &state,
unsigned bytes = Expr::getMinBytesForWidth(type);
if (SimplifySymIndices) {
- if (!address->isConstant())
+ if (!isa<ConstantExpr>(address))
address = state.constraints.simplifyExpr(address);
- if (isWrite && !value->isConstant())
+ if (isWrite && !isa<ConstantExpr>(value))
value = state.constraints.simplifyExpr(value);
}
@@ -3174,9 +3172,7 @@ void Executor::getCoveredLines(const ExecutionState &state,
void Executor::doImpliedValueConcretization(ExecutionState &state,
ref<Expr> e,
- ref<Expr> value) {
- assert(value->isConstant() && "non-constant passed in place of constant");
-
+ ref<ConstantExpr> value) {
if (DebugCheckForImpliedValues)
ImpliedValue::checkForImpliedValues(solver->solver, e, value);
@@ -3186,7 +3182,7 @@ void Executor::doImpliedValueConcretization(ExecutionState &state,
it != ie; ++it) {
ReadExpr *re = it->first.get();
- if (re->index->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(re->index)) {
// FIXME: This is the sole remaining usage of the Array object
// variable. Kill me.
const MemoryObject *mo = re->updates.root->object;
@@ -3197,9 +3193,10 @@ void Executor::doImpliedValueConcretization(ExecutionState &state,
// in other cases we would like to concretize the outstanding
// reads, but we have no facility for that yet)
} else {
- assert(!os->readOnly && "not possible? read only object with static read?");
+ assert(!os->readOnly &&
+ "not possible? read only object with static read?");
ObjectState *wos = state.addressSpace.getWriteable(mo, os);
- wos->write(re->index->getConstantValue(), it->second);
+ wos->write(CE->getConstantValue(), it->second);
}
}
}
diff --git a/lib/Core/Executor.h b/lib/Core/Executor.h
index 2619e786..ba65cf5a 100644
--- a/lib/Core/Executor.h
+++ b/lib/Core/Executor.h
@@ -362,7 +362,7 @@ private:
void doImpliedValueConcretization(ExecutionState &state,
ref<Expr> e,
- ref<Expr> value);
+ ref<ConstantExpr> value);
/// Add a timer to be executed periodically.
///
diff --git a/lib/Core/ImpliedValue.cpp b/lib/Core/ImpliedValue.cpp
index 8ebc0aef..dfb91344 100644
--- a/lib/Core/ImpliedValue.cpp
+++ b/lib/Core/ImpliedValue.cpp
@@ -195,16 +195,13 @@ static void _getImpliedValue(ref<Expr> e,
}
void ImpliedValue::getImpliedValues(ref<Expr> e,
- ref<Expr> value,
+ ref<ConstantExpr> value,
ImpliedValueList &results) {
- assert(value->isConstant() && "non-constant in place of constant");
_getImpliedValue(e, value->getConstantValue(), results);
}
void ImpliedValue::checkForImpliedValues(Solver *S, ref<Expr> e,
- ref<Expr> value) {
- assert(value->isConstant() && "non-constant in place of constant");
-
+ ref<ConstantExpr> value) {
std::vector<ref<ReadExpr> > reads;
std::map<ref<ReadExpr>, ref<Expr> > found;
ImpliedValueList results;
diff --git a/lib/Core/ImpliedValue.h b/lib/Core/ImpliedValue.h
index 51ec6e9b..cbc55dc5 100644
--- a/lib/Core/ImpliedValue.h
+++ b/lib/Core/ImpliedValue.h
@@ -29,8 +29,10 @@ namespace klee {
typedef std::vector< std::pair<ref<ReadExpr>, ref<Expr> > > ImpliedValueList;
namespace ImpliedValue {
- void getImpliedValues(ref<Expr> e, ref<Expr> cvalue, ImpliedValueList &result);
- void checkForImpliedValues(Solver *S, ref<Expr> e, ref<Expr> cvalue);
+ void getImpliedValues(ref<Expr> e, ref<ConstantExpr> cvalue,
+ ImpliedValueList &result);
+ void checkForImpliedValues(Solver *S, ref<Expr> e,
+ ref<ConstantExpr> cvalue);
}
}
diff --git a/lib/Core/Memory.cpp b/lib/Core/Memory.cpp
index de48651b..b4c433b1 100644
--- a/lib/Core/Memory.cpp
+++ b/lib/Core/Memory.cpp
@@ -339,7 +339,7 @@ void ObjectState::write8(unsigned offset, ref<Expr> value) {
}
void ObjectState::write8(ref<Expr> offset, ref<Expr> value) {
- assert(!offset->isConstant() && "constant offset passed to symbolic write8");
+ assert(!isa<ConstantExpr>(offset) && "constant offset passed to symbolic write8");
unsigned base, size;
fastRangeCheckOffset(offset, &base, &size);
flushRangeForWrite(base, size);
diff --git a/lib/Core/SeedInfo.cpp b/lib/Core/SeedInfo.cpp
index 30377ee4..62b71e87 100644
--- a/lib/Core/SeedInfo.cpp
+++ b/lib/Core/SeedInfo.cpp
@@ -77,9 +77,9 @@ void SeedInfo::patchSeed(const ExecutionState &state,
for (std::vector< ref<ReadExpr> >::iterator it = reads.begin(),
ie = reads.end(); it != ie; ++it) {
ReadExpr *re = it->get();
- if (re->index->isConstant()) {
- unsigned index = (unsigned) re->index->getConstantValue();
- directReads.insert(std::make_pair(re->updates.root, index));
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(re->index)) {
+ directReads.insert(std::make_pair(re->updates.root,
+ (unsigned) CE->getConstantValue()));
}
}
diff --git a/lib/Core/SpecialFunctionHandler.cpp b/lib/Core/SpecialFunctionHandler.cpp
index b2e5d277..e1182cf0 100644
--- a/lib/Core/SpecialFunctionHandler.cpp
+++ b/lib/Core/SpecialFunctionHandler.cpp
@@ -172,11 +172,12 @@ bool SpecialFunctionHandler::handle(ExecutionState &state,
/****/
// reads a concrete string from memory
-std::string SpecialFunctionHandler::readStringAtAddress(ExecutionState &state,
- ref<Expr> address) {
+std::string
+SpecialFunctionHandler::readStringAtAddress(ExecutionState &state,
+ ref<Expr> addressExpr) {
ObjectPair op;
- address = executor.toUnique(state, address);
- assert(address->isConstant() && "symbolic string arg to intrinsic");
+ addressExpr = executor.toUnique(state, addressExpr);
+ ref<ConstantExpr> address = cast<ConstantExpr>(addressExpr);
if (!state.addressSpace.resolveOne(address->getConstantValue(), op))
assert(0 && "XXX out of bounds / multiple resolution unhandled");
bool res;
@@ -195,9 +196,9 @@ std::string SpecialFunctionHandler::readStringAtAddress(ExecutionState &state,
for (i = 0; i < mo->size - 1; i++) {
ref<Expr> cur = os->read8(i);
cur = executor.toUnique(state, cur);
- assert(cur->isConstant() &&
+ assert(isa<ConstantExpr>(cur) &&
"hit symbolic char while reading concrete string");
- buf[i] = cur->getConstantValue();
+ buf[i] = cast<ConstantExpr>(cur)->getConstantValue();
}
buf[i] = 0;
@@ -438,12 +439,12 @@ void SpecialFunctionHandler::handleSetForking(ExecutionState &state,
"invalid number of arguments to klee_set_forking");
ref<Expr> value = executor.toUnique(state, arguments[0]);
- if (!value->isConstant()) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(value)) {
+ state.forkDisabled = !CE->getConstantValue();
+ } else {
executor.terminateStateOnError(state,
"klee_set_forking requires a constant arg",
"user.err");
- } else {
- state.forkDisabled = !value->getConstantValue();
}
}
@@ -476,7 +477,7 @@ void SpecialFunctionHandler::handlePrintRange(ExecutionState &state,
std::string msg_str = readStringAtAddress(state, arguments[0]);
llvm::cerr << msg_str << ":" << arguments[1];
- if (!arguments[1]->isConstant()) {
+ if (!isa<ConstantExpr>(arguments[1])) {
// FIXME: Pull into a unique value method?
ref<Expr> value;
bool success = executor.solver->getValue(state, arguments[1], value);
@@ -590,7 +591,7 @@ void SpecialFunctionHandler::handleCheckMemoryAccess(ExecutionState &state,
ref<Expr> address = executor.toUnique(state, arguments[0]);
ref<Expr> size = executor.toUnique(state, arguments[1]);
- if (!address->isConstant() || !size->isConstant()) {
+ if (!isa<ConstantExpr>(address) || !isa<ConstantExpr>(size)) {
executor.terminateStateOnError(state,
"check_memory_access requires constant args",
"user.err");
@@ -605,8 +606,7 @@ void SpecialFunctionHandler::handleCheckMemoryAccess(ExecutionState &state,
} else {
ref<Expr> chk = op.first->getBoundsCheckPointer(address,
size->getConstantValue());
- assert(chk->isConstant());
- if (!chk->getConstantValue()) {
+ if (!cast<ConstantExpr>(chk)->getConstantValue()) {
executor.terminateStateOnError(state,
"check_memory_access: memory error",
"ptr.err",
@@ -630,9 +630,9 @@ void SpecialFunctionHandler::handleDefineFixedObject(ExecutionState &state,
std::vector<ref<Expr> > &arguments) {
assert(arguments.size()==2 &&
"invalid number of arguments to klee_define_fixed_object");
- assert(arguments[0]->isConstant() &&
+ assert(isa<ConstantExpr>(arguments[0]) &&
"expect constant address argument to klee_define_fixed_object");
- assert(arguments[1]->isConstant() &&
+ assert(isa<ConstantExpr>(arguments[1]) &&
"expect constant size argument to klee_define_fixed_object");
uint64_t address = arguments[0]->getConstantValue();