From 516fb5585a776bde6277eeb3c46f09620dd20a5f Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 5 Sep 2017 14:23:48 -0700 Subject: [PATCH 1/1] Found bug... Don't update parent's list until we know we aren't going to be freed --- src/AST/boolean.cc | 14 ++++++++------ src/AST/boolean.h | 7 ++++++- src/AST/element.cc | 6 ++++-- src/AST/element.h | 4 +++- src/AST/function.cc | 12 ++++++++++-- src/csolver.cc | 3 +++ src/mymemory.h | 2 +- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/AST/boolean.cc b/src/AST/boolean.cc index 4ca9c40..9786644 100644 --- a/src/AST/boolean.cc +++ b/src/AST/boolean.cc @@ -37,9 +37,6 @@ BooleanPredicate::BooleanPredicate(Predicate *_predicate, Element **_inputs, uin encoding(this), inputs(_inputs, _numInputs), undefStatus(_undefinedStatus) { - for (uint i = 0; i < _numInputs; i++) { - _inputs[i]->parents.push(this); - } } BooleanLogic::BooleanLogic(CSolver *solver, LogicOp _op, BooleanEdge *array, uint asize) : @@ -47,9 +44,6 @@ BooleanLogic::BooleanLogic(CSolver *solver, LogicOp _op, BooleanEdge *array, uin op(_op), replaced(false), inputs(array, asize) { - for (uint i = 0; i < asize; i++) { - array[i]->parents.push(this); - } } BooleanEdge cloneEdge(CSolver *solver, CloneMap *map, BooleanEdge e) { @@ -96,3 +90,11 @@ Boolean *BooleanPredicate::clone(CSolver *solver, CloneMap *map) { return solver->applyPredicateTable(pred, array, inputs.getSize(), defstatus).getRaw(); } + +void BooleanPredicate::updateParents() { + for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this); +} + +void BooleanLogic::updateParents() { + for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this); +} diff --git a/src/AST/boolean.h b/src/AST/boolean.h index ecaebaf..8be1d30 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -21,7 +21,8 @@ public: Polarity polarity; BooleanValue boolVal; Vector parents; - + virtual void updateParents() {} + CMEMALLOC; }; @@ -66,6 +67,8 @@ public: Array inputs; BooleanEdge undefStatus; FunctionEncoding *getFunctionEncoding() {return &encoding;} + void updateParents(); + CMEMALLOC; }; @@ -77,6 +80,8 @@ public: LogicOp op; bool replaced; Array inputs; + void updateParents(); + CMEMALLOC; }; BooleanEdge cloneEdge(CSolver *solver, CloneMap *map, BooleanEdge e); diff --git a/src/AST/element.cc b/src/AST/element.cc index 3fe8cef..fd30812 100644 --- a/src/AST/element.cc +++ b/src/AST/element.cc @@ -22,8 +22,6 @@ ElementFunction::ElementFunction(Function *_function, Element **array, uint numA inputs(array, numArrays), overflowstatus(_overflowstatus), functionencoding(this) { - for (uint i = 0; i < numArrays; i++) - array[i]->parents.push(this); } ElementConst::ElementConst(uint64_t _value, VarType _type, Set *_set) : @@ -77,3 +75,7 @@ Element *ElementFunction::clone(CSolver *solver, CloneMap *map) { Element *e = solver->applyFunction(function->clone(solver, map), array, inputs.getSize(), overflowstatus->clone(solver, map)); return e; } + +void ElementFunction::updateParents() { + for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this); +} diff --git a/src/AST/element.h b/src/AST/element.h index c3a3ed9..5447256 100644 --- a/src/AST/element.h +++ b/src/AST/element.h @@ -15,7 +15,8 @@ public: Vector parents; ElementEncoding encoding; virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;}; - + virtual void updateParents() {} + CMEMALLOC; }; @@ -44,6 +45,7 @@ public: BooleanEdge overflowstatus; FunctionEncoding functionencoding; Element *clone(CSolver *solver, CloneMap *map); + void updateParents(); CMEMALLOC; }; diff --git a/src/AST/function.cc b/src/AST/function.cc index 6715e79..d6b2d3a 100644 --- a/src/AST/function.cc +++ b/src/AST/function.cc @@ -3,10 +3,18 @@ #include "set.h" #include "csolver.h" -FunctionOperator::FunctionOperator(ArithOp _op, Set **domain, uint numDomain, Set *_range, OverFlowBehavior _overflowbehavior) : Function(OPERATORFUNC), op(_op), domains(domain, numDomain), range(_range), overflowbehavior(_overflowbehavior) { +FunctionOperator::FunctionOperator(ArithOp _op, Set **domain, uint numDomain, Set *_range, OverFlowBehavior _overflowbehavior) : + Function(OPERATORFUNC), + op(_op), + domains(domain, numDomain), + range(_range), + overflowbehavior(_overflowbehavior) { } -FunctionTable::FunctionTable (Table *_table, UndefinedBehavior _undefBehavior) : Function(TABLEFUNC), table(_table), undefBehavior(_undefBehavior) { +FunctionTable::FunctionTable (Table *_table, UndefinedBehavior _undefBehavior) : + Function(TABLEFUNC), + table(_table), + undefBehavior(_undefBehavior) { } uint64_t FunctionOperator::applyFunctionOperator(uint numVals, uint64_t *values) { diff --git a/src/csolver.cc b/src/csolver.cc index d94ddfc..d8e0872 100644 --- a/src/csolver.cc +++ b/src/csolver.cc @@ -143,6 +143,7 @@ Element *CSolver::applyFunction(Function *function, Element **array, uint numArr Element *element = new ElementFunction(function,array,numArrays,overflowstatus); Element *e = elemMap.get(element); if (e == NULL) { + element->updateParents(); allElements.push(element); elemMap.put(element, element); return element; @@ -212,6 +213,7 @@ BooleanEdge CSolver::applyPredicateTable(Predicate *predicate, Element **inputs, BooleanPredicate *boolean = new BooleanPredicate(predicate, inputs, numInputs, undefinedStatus); Boolean *b = boolMap.get(boolean); if (b == NULL) { + boolean->updateParents(); boolMap.put(boolean, boolean); allBooleans.push(boolean); return BooleanEdge(boolean); @@ -336,6 +338,7 @@ BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint Boolean *boolean = new BooleanLogic(this, op, array, asize); Boolean *b = boolMap.get(boolean); if (b == NULL) { + boolean->updateParents(); boolMap.put(boolean, boolean); allBooleans.push(boolean); return BooleanEdge(boolean); diff --git a/src/mymemory.h b/src/mymemory.h index 7c63aa1..e0a60bd 100644 --- a/src/mymemory.h +++ b/src/mymemory.h @@ -26,7 +26,7 @@ void * ourrealloc(void *ptr, size_t size); */ -#if 0 +#if 1 void * model_malloc(size_t size); void model_free(void *ptr); void * model_calloc(size_t count, size_t size); -- 2.34.1