Skip to content

Commit

Permalink
BUGFIX: Invalid use of iterators in ValueContainerV1 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
CharvN committed Mar 17, 2017
1 parent 2d52613 commit 6d72a2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
26 changes: 10 additions & 16 deletions src/ValueContainerV1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ along with Angie. If not, see <http://www.gnu.org/licenses/>.
#include <algorithm>
#define CHECK_FLAG(var, flag) ((var & flag) == flag)


//BinaryConstraint helper methods
//--------------------------------------------------------------
BinaryConstraint::BinaryConstraint(ValueId _first, ValueId _second, CmpFlags _relation)
Expand Down Expand Up @@ -135,10 +134,9 @@ void ValueContainer::InsertConstraint(BinaryConstraint constr)
{
case CmpFlags::Eq:
//new constraint is equal to a constant -> delete all previous
//TODO@charvin FIX: invalidates iterator you are using!, 3x in this function
//HACK for now just do not delete, see TODO
// DeleteConstraint(oldConstraintId);
DeleteConstraint(oldConstraintId);
break;

//TODO::add cases for intervals
default:
break;
Expand All @@ -161,10 +159,9 @@ void ValueContainer::InsertConstraint(BinaryConstraint constr)
{
case CmpFlags::Eq:
//new constraint is equal to a constant -> delete all previous
//TODO@charvin FIX: invalidates iterator you are using!, 3x in this function
//HACK for now just do not delete, see TODO
// DeleteConstraint(oldConstraintId);
DeleteConstraint(oldConstraintId);
break;

//TODO::add cases for intervals
default:
break;
Expand All @@ -182,9 +179,7 @@ void ValueContainer::InsertConstraint(BinaryConstraint constr)
if (constr.second == constrContainer.at(oldConstraintId).GetOther(constr.first))
{
//delete mutual constraints
//TODO@charvin FIX: invalidates iterator you are using!, 3x in this function
//HACK for now just do not delete, see TODO
// DeleteConstraint(oldConstraintId);
DeleteConstraint(oldConstraintId);
}

}
Expand Down Expand Up @@ -217,14 +212,13 @@ void ValueContainer::DeleteConstraint(ConstraintId constrId)
constrContainer.erase(constrId);
}

const std::vector<ConstraintId>& ValueContainer::GetConstraintIdVector(const ValueId id) const
const std::vector<ConstraintId> ValueContainer::GetConstraintIdVector(const ValueId id) const
{
static std::vector<ConstraintId> emptyvec;
auto lhsConstrId = constrIdContainer.find(id);

//is there a record of any constraints for the id
if (lhsConstrId == constrIdContainer.end())
return emptyvec;
return std::vector<ConstraintId>();

//return reference to the vector of constraintIds corresponding to the id

This comment has been minimized.

Copy link
@michkot

michkot Mar 17, 2017

Member

In case "the fix - see comment in issue" was to return the vector by value, edit the comment saying we return by reference...

return lhsConstrId->second;
Expand Down Expand Up @@ -560,7 +554,7 @@ ValueId ValueContainer::BinOp(ValueId first, ValueId second, Type type, BinaryOp
//check for overflow
if (CHECK_FLAG(options.flags, ArithFlags::NoUnsignedWrap))
{
if (uMax - uValueLhs < uValueRhs) //unsigned overflow
if (uMax - uValueLhs < uValueRhs) //unsigned overflow
return CreateVal(type);
}
else if (CHECK_FLAG(options.flags, ArithFlags::NoSignedWrap))
Expand All @@ -578,7 +572,6 @@ ValueId ValueContainer::BinOp(ValueId first, ValueId second, Type type, BinaryOp
}
}


uint64_t result = uValueLhs + uValueRhs;
return CreateConstIntVal(result, type);
}
Expand Down Expand Up @@ -760,6 +753,7 @@ ValueId ValueContainer::TruncateInt(ValueId first, Type sourceType, Type targetT

else
return first;

}

ValueId ValueContainer::CreateConstIntVal(uint64_t value)
Expand Down Expand Up @@ -804,4 +798,4 @@ void ValueContainer::PrintDebug() const

cout << std::endl;
}
}
}
3 changes: 2 additions & 1 deletion src/ValueContainerV1.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private:

void InsertConstraint(BinaryConstraint);
void DeleteConstraint(ConstraintId constrId);
const std::vector<ConstraintId> &GetConstraintIdVector(ValueId id) const;
const std::vector<ConstraintId> GetConstraintIdVector(ValueId id) const;
bool IsConstant(ValueId first) const { auto res = constantContainer.find(first); return res != constantContainer.end(); }
inline uint64_t RipBits(size_t numOfBits, uint64_t in) const;
inline int64_t SignExtend64(size_t numOfBits, uint64_t in) const;
Expand All @@ -96,6 +96,7 @@ public:
boost::tribool IsInternalRepEq(ValueId first, ValueId second) const override;
boost::tribool IsZero(ValueId first) const override;
bool IsUnknown(ValueId first) const override;


// Creates new boolean(1bit integer) value expressing the constraint
ValueId Cmp(ValueId first, ValueId second, Type type, CmpFlags flags) override;
Expand Down

0 comments on commit 6d72a2b

Please sign in to comment.