@@ -1270,9 +1270,11 @@ void Executor::branch(ExecutionState &state,
1270
1270
}
1271
1271
}
1272
1272
1273
- std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1274
- seedMap->find (&state);
1275
- if (it != seedMap->end ()) {
1273
+ if (state.isSeeded ) {
1274
+ std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1275
+ seedMap->find (&state);
1276
+ assert (it != seedMap->end ());
1277
+ assert (!it->second .empty ());
1276
1278
std::vector<ExecutingSeed> seeds = it->second ;
1277
1279
seedMap->erase (it);
1278
1280
objectManager->unseed (it->first );
@@ -1410,11 +1412,8 @@ Executor::StatePair Executor::fork(ExecutionState ¤t, ref<Expr> condition,
1410
1412
KBlock *ifTrueBlock, KBlock *ifFalseBlock,
1411
1413
BranchType reason) {
1412
1414
bool isInternal = ifTrueBlock == ifFalseBlock;
1413
- std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1414
- seedMap->find (¤t);
1415
- bool isSeeding = it != seedMap->end ();
1416
1415
PartialValidity res = PartialValidity::None;
1417
-
1416
+ bool isSeeding = current. isSeeded ;
1418
1417
std::vector<ExecutingSeed> trueSeeds;
1419
1418
std::vector<ExecutingSeed> falseSeeds;
1420
1419
time::Span timeout = coreSolverTimeout;
@@ -1438,7 +1437,11 @@ Executor::StatePair Executor::fork(ExecutionState ¤t, ref<Expr> condition,
1438
1437
addConstraint (current, Expr::createIsZero (condition));
1439
1438
}
1440
1439
}
1441
- } else if (!it->second .empty ()) {
1440
+ } else {
1441
+ std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1442
+ seedMap->find (¤t);
1443
+ assert (it != seedMap->end ());
1444
+ assert (!it->second .empty ());
1442
1445
timeout *= static_cast <unsigned >(it->second .size ());
1443
1446
for (std::vector<ExecutingSeed>::iterator siit = it->second .begin (),
1444
1447
siie = it->second .end ();
@@ -1646,9 +1649,11 @@ void Executor::addConstraint(ExecutionState &state, ref<Expr> condition) {
1646
1649
}
1647
1650
1648
1651
// Check to see if this constraint violates seeds.
1649
- std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1650
- seedMap->find (&state);
1651
- if (PatchSeeds && it != seedMap->end ()) {
1652
+ if (PatchSeeds && state.isSeeded ) {
1653
+ std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1654
+ seedMap->find (&state);
1655
+ assert (it != seedMap->end ());
1656
+ assert (!it->second .empty ());
1652
1657
bool warn = false ;
1653
1658
for (std::vector<ExecutingSeed>::iterator siit = it->second .begin (),
1654
1659
siie = it->second .end ();
@@ -1796,10 +1801,7 @@ Executor::toConstantPointer(ExecutionState &state, ref<PointerExpr> e,
1796
1801
void Executor::executeGetValue (ExecutionState &state, ref<Expr> e,
1797
1802
KInstruction *target) {
1798
1803
e = Simplificator::simplifyExpr (state.constraints .cs (), e).simplified ;
1799
- std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1800
- seedMap->find (&state);
1801
- if (it == seedMap->end () || isa<ConstantExpr>(e) ||
1802
- isa<ConstantPointerExpr>(e)) {
1804
+ if (!state.isSeeded || isa<ConstantExpr>(e) || isa<ConstantPointerExpr>(e)) {
1803
1805
ref<Expr> value;
1804
1806
e = optimizer.optimizeExpr (e, true );
1805
1807
bool success =
@@ -1808,6 +1810,10 @@ void Executor::executeGetValue(ExecutionState &state, ref<Expr> e,
1808
1810
(void )success;
1809
1811
bindLocal (target, state, value);
1810
1812
} else {
1813
+ std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
1814
+ seedMap->find (&state);
1815
+ assert (it != seedMap->end ());
1816
+ assert (!it->second .empty ());
1811
1817
std::set<ref<Expr>> values;
1812
1818
for (std::vector<ExecutingSeed>::iterator siit = it->second .begin (),
1813
1819
siie = it->second .end ();
@@ -4497,7 +4503,8 @@ Executor::MemoryUsage Executor::checkMemoryUsage() {
4497
4503
arr.push_back (state);
4498
4504
}
4499
4505
}
4500
- auto toKill = std::min (arr.size (), numStates - numStates * MaxMemory / totalUsage);
4506
+ auto toKill =
4507
+ std::min (arr.size (), numStates - numStates * MaxMemory / totalUsage);
4501
4508
4502
4509
if (toKill != 0 ) {
4503
4510
klee_warning (" killing %lu states (over memory cap: %luMB)" , toKill,
@@ -4670,16 +4677,22 @@ void Executor::initialSeed(ExecutionState &initialState,
4670
4677
objectManager->updateSubscribers ();
4671
4678
}
4672
4679
4673
- ExecutingSeed Executor::storeState (const ExecutionState &state,
4674
- bool isCompleted) {
4675
- KTest *ktest = 0 ;
4676
- ktest = (KTest *)calloc (1 , sizeof (*ktest));
4677
- bool success = getSymbolicSolution (state, ktest);
4678
- if (!success)
4680
+ bool Executor::storeState (const ExecutionState &state, bool isCompleted,
4681
+ ExecutingSeed &res) {
4682
+ solver->setTimeout (coreSolverTimeout);
4683
+ auto arrays = state.constraints .cs ().gatherArrays ();
4684
+ std::vector<SparseStorageImpl<unsigned char >> values;
4685
+ bool success = solver->getInitialValues (state.constraints .cs (), arrays,
4686
+ values, state.queryMetaData );
4687
+ if (!success) {
4679
4688
klee_warning (" unable to get symbolic solution, losing test case" );
4680
- ExecutingSeed seed (ktest, state.steppedInstructions , isCompleted,
4689
+ return false ;
4690
+ }
4691
+ Assignment assignment (arrays, values);
4692
+ ExecutingSeed seed (assignment, state.steppedInstructions , isCompleted,
4681
4693
state.coveredNew , state.coveredNewError );
4682
- return seed;
4694
+ res = seed;
4695
+ return true ;
4683
4696
}
4684
4697
4685
4698
void Executor::reportProgressTowardsTargets (std::string prefix,
@@ -5063,8 +5076,11 @@ void Executor::terminateStateEarly(ExecutionState &state, const Twine &message,
5063
5076
(AlwaysOutputSeeds && seedMap->count (&state))) {
5064
5077
state.clearCoveredNew ();
5065
5078
if (StoreSeedsLocally) {
5066
- storedSeeds->push_back (
5067
- storeState (state, !(reason <= StateTerminationType::EARLY)));
5079
+ ExecutingSeed seed;
5080
+ bool success = storeState (state, !(reason <= StateTerminationType::EARLY), seed);
5081
+ if (success) {
5082
+ storedSeeds->push_back (seed);
5083
+ }
5068
5084
} else {
5069
5085
interpreterHandler->processTestCase (
5070
5086
state, (message + " \n " ).str ().c_str (),
@@ -6899,17 +6915,22 @@ void Executor::executeMakeSymbolic(ExecutionState &state,
6899
6915
}
6900
6916
state.addSymbolic (mo, array, type);
6901
6917
6902
- std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
6903
- seedMap->find (&state);
6904
- if (it != seedMap->end ()) { // In seed mode we need to add this as a
6905
- // binding.
6918
+ if (state.isSeeded ) { // In seed mode we need to add this as a
6919
+ // binding.
6920
+ std::map<ExecutionState *, std::vector<ExecutingSeed>>::iterator it =
6921
+ seedMap->find (&state);
6922
+ assert (it != seedMap->end ());
6923
+ assert (!it->second .empty ());
6906
6924
for (std::vector<ExecutingSeed>::iterator siit = it->second .begin (),
6907
6925
siie = it->second .end ();
6908
6926
siit != siie; ++siit) {
6909
6927
ExecutingSeed &si = *siit;
6910
6928
KTestObject *obj = si.getNextInput (mo, NamedSeedMatching);
6911
6929
6912
6930
if (!obj) {
6931
+ if (si.assignment .bindings .count (array) != 0 ) {
6932
+ continue ;
6933
+ }
6913
6934
if (ZeroSeedExtension) {
6914
6935
si.assignment .bindings .replace (
6915
6936
{array, SparseStorageImpl<unsigned char >(0 )});
0 commit comments