[cfe-dev] Analyzer: SVal-building idioms

Jordy Rose jediknil at belkadan.com
Tue Jul 6 14:21:22 PDT 2010


In trying to excise the remnants of getSizeInElements() from the code, I
realized we don't have a great place for SVal-building idioms. There's
SValuator::EvalEQ, but nothing else. In looking through the code, I see two
more useful idioms that it might be good to box up into methods:

// perhaps with LengthTy defaulting to SizeTy or ArrayIndexTy
SVal ConvertToCharUnits(const GRState *state, SVal Length,
                        QualType EleTy, QualType LengthTy) {
  // return Length * (LengthTy) sizeof(EleTy)
}

// To replace the rather useless AssumeInBound,
// since this could be used to change the state
SVal BuildBoundCheck(const GRState *state, SVal Index, SVal Limit,
                     QualType IndexTy = ArrayIndexTy) {
  // 0 <= Index < Limit
  // is the same as
  // Index+MIN < Limit+MIN
  // which the constraint manager can handle now
  // as long as either Index or Limit is constant
  // and Limit is positive.
  // return (Index + getMinValue(IndexTy)) < (Limit +
getMinValue(IndexTy))
}

It's not that these are so complex that they can't be used on their own,
but it would reduce duplicated code. But where would these methods go? On
SValuator, which Ted's already suggested is more of an SValBuilder? Or on
ValueManager, since the code makes use of its ArrayIndexTy? (Though we
could add a getIndexType() method very easily.)

Or are these not things that need to be packaged up? I feel like the
bounds-checking would be useful, at least, since that /is/ something used
in multiple places.

Jordy



More information about the cfe-dev mailing list