Fix overlapping case item expressions (#6825) (#6886)

This commit is contained in:
Luca Colagrande
2026-01-06 15:07:25 -05:00
committed by GitHub
parent 45349990a1
commit 112e1e3752
5 changed files with 97 additions and 14 deletions
+14 -3
View File
@@ -595,6 +595,7 @@ class AssertVisitor final : public VNVisitor {
AstNodeExpr* propp = nullptr;
for (AstCaseItem* itemp = nodep->itemsp(); itemp;
itemp = VN_AS(itemp->nextp(), CaseItem)) {
AstNodeExpr* itembitp = nullptr;
for (AstNodeExpr* icondp = itemp->condsp(); icondp;
icondp = VN_AS(icondp->nextp(), NodeExpr)) {
AstNodeExpr* onep;
@@ -612,17 +613,27 @@ class AssertVisitor final : public VNVisitor {
nodep->exprp()->cloneTreePure(false),
icondp->cloneTreePure(false));
}
// OR together all conditions within the same case item
if (onep) {
if (itembitp) {
itembitp = new AstOr{icondp->fileline(), onep, itembitp};
} else {
itembitp = onep;
}
}
}
if (itembitp) {
if (propp) {
propp = new AstConcat{icondp->fileline(), onep, propp};
propp = new AstConcat{itemp->fileline(), itembitp, propp};
} else {
propp = onep;
propp = itembitp;
}
}
}
// Empty case means no property
if (!propp) propp = new AstConst{nodep->fileline(), AstConst::BitFalse{}};
const bool allow_none = has_default || nodep->unique0Pragma();
// The following assertion lools as below.
// The following assertion looks as below.
// if (!$onehot(propp)) begin
// if (propp == '0) begin if (!allow_none) $error("none match"); end
// else $error("multiple match");