Fix range check in V3SplitVar to be consistent with #2507 (#2511)

* test:Add more tests for checking split_var for unpacked array.

* Fix range calculation of SliceSel and change to UASSERT_OBJ because the range check is done in V3Width beforehand.
This commit is contained in:
Yutetsu TAKATSUKASA
2020-08-24 19:11:20 -04:00
committed by GitHub
parent 16547077a1
commit 6acd5847e7
5 changed files with 1960 additions and 1857 deletions
+10 -14
View File
@@ -275,10 +275,6 @@ public:
return m_index;
}
AstNode* context() const { return m_contextp; }
std::pair<int, int> range() const {
UASSERT_OBJ(VN_IS(m_nodep, SliceSel), m_nodep, "not slice sel");
return std::make_pair(m_msb, m_lsb);
}
bool lvalue() const { return m_lvalue; }
bool ftask() const { return m_ftask; }
bool operator<(const UnpackRef& other) const {
@@ -584,16 +580,16 @@ class SplitUnpackedVarVisitor : public AstNVisitor, public SplitVarImpl {
if (AstVarRef* refp = isTargetVref(nodep->fromp())) {
AstUnpackArrayDType* dtypep
= VN_CAST(refp->varp()->dtypep()->skipRefp(), UnpackArrayDType);
if (dtypep->lsb() <= nodep->declRange().lo()
&& nodep->declRange().hi() <= dtypep->msb()) { // Range is ok
UINFO(4, "add " << nodep << " for " << refp->varp()->prettyName() << "\n");
m_refs.tryAdd(m_contextp, refp, nodep, nodep->declRange().hi(),
nodep->declRange().lo(), m_inFTask);
} else {
nodep->v3warn(SPLITVAR, refp->prettyNameQ()
<< notSplitMsg << "index if out of range.\n");
m_refs.remove(refp->varp());
}
// declRange() of AstSliceSel is shifted by dtypep->declRange().lo() in V3WidthSel.cpp
// restore the original decl range here.
const VNumRange selRange{nodep->declRange().hi() + dtypep->declRange().lo(),
nodep->declRange().lo() + dtypep->declRange().lo(),
nodep->declRange().littleEndian()};
UASSERT_OBJ(dtypep->lsb() <= selRange.lo() && selRange.hi() <= dtypep->msb(), nodep,
"Range check for AstSliceSel must have been finished in V3Width.cpp");
UINFO(4, "add " << nodep << " for " << refp->varp()->prettyName() << "\n");
m_refs.tryAdd(m_contextp, refp, nodep, nodep->declRange().hi(),
nodep->declRange().lo(), m_inFTask);
} else {
iterateChildren(nodep);
}