Where* WhereInvariant::Make(TypeCSU *csu, Exp *lval, Bit *bit) { Assert(bit); Bit *new_bit; if (csu) { Variable *this_var = Variable::Make(NULL, VK_This, NULL, 0, NULL); Exp *this_exp = Exp::MakeVar(this_var); Exp *this_drf = Exp::MakeDrf(this_exp); new_bit = TranslateHeapBit(lval, this_drf, false, bit); this_drf->DecRef(); } else { new_bit = TranslateHeapBit(NULL, NULL, false, bit); } Where *res = NULL; if (new_bit) { // additionally visit it to make sure we can find all lvalues. CheckInvariantVisitor visitor; new_bit->DoVisit(&visitor); if (!visitor.exclude) res = new WhereInvariant(csu, NULL, new_bit); new_bit->DecRef(); } return res; }
void WhereInvariant::AssertRecursive(CheckerFrame *frame, Exp *exp) { if (m_csu == NULL) return; Exp *read_csu = GetWriteCSU(exp); if (read_csu == NULL) return; Variable *this_var = Variable::Make(NULL, VK_This, NULL, 0, NULL); Exp *this_exp = Exp::MakeVar(this_var); Exp *this_drf = Exp::MakeDrf(this_exp); Bit *entry_bit = TranslateHeapBit(this_drf, read_csu, false, m_bit); frame->AddAssert(entry_bit); }
void WhereInvariant::GetHeapBits(CheckerFrame *write_frame, Exp *write_csu, Exp *base_csu, Bit **base_bit, GuardBitVector *res) { BlockMemory *mcfg = write_frame->Memory(); Exp *old_lval = NULL; if (m_csu) { Variable *this_var = Variable::Make(NULL, VK_This, NULL, 0, NULL); Exp *old_this = Exp::MakeVar(this_var); old_lval = Exp::MakeDrf(old_this); } Bit *exit_bit = TranslateHeapBit(old_lval, write_csu, true, m_bit); Assert(exit_bit); if (old_lval) old_lval->DecRef(); // TODO: using this to get the base bit for an invariant is fairly // hacked up, but for now we can't do this correctly as the base bit // needs to be relative to the CFG exit point, not the point where // any writes occur at. for now just get the displayable point for // the base CSU, and hope that means the same thing at exit as at // the point of the write. Bit *new_bit = BitConvertExitClobber(m_bit); if (base_csu) { *base_bit = BitReplaceExp(new_bit, old_lval, base_csu); new_bit->DecRef(); } else { *base_bit = new_bit; } GuardBitVector base_res; PPoint exit_point = mcfg->GetCFG()->GetExitPoint(); mcfg->TranslateBit(TRK_Exit, exit_point, exit_bit, &base_res); exit_bit->DecRef(); RemoveValBit(write_frame->Id(), write_frame->Memory(), base_res, res); }