Fix replicate of negative giving 'REPLICATE has no expected width' internal error (#6048).

This commit is contained in:
Wilson Snyder
2025-07-23 18:07:50 -04:00
parent 050e5ddb5b
commit 460bfbf181
8 changed files with 87 additions and 11 deletions
+5 -1
View File
@@ -3367,7 +3367,11 @@ public:
: ASTGEN_SUPER_Replicate(fl, lhsp, rhsp) {
if (lhsp) {
if (const AstConst* const constp = VN_CAST(rhsp, Const)) {
dtypeSetLogicSized(lhsp->width() * constp->toUInt(), VSigning::UNSIGNED);
if (constp->num().isFourState() || constp->num().isNegative()) { // V3Width warns
dtypeSetLogicSized(lhsp->width(), VSigning::UNSIGNED);
} else {
dtypeSetLogicSized(lhsp->width() * constp->toSInt(), VSigning::UNSIGNED);
}
}
}
}
+1 -5
View File
@@ -1471,11 +1471,7 @@ V3Number& V3Number::opRepl(const V3Number& lhs,
// i op repl, L(i)*value(rhs) bit return
NUM_ASSERT_OP_ARGS1(lhs);
NUM_ASSERT_LOGIC_ARGS1(lhs);
if (rhsval > (1UL << 24)) {
v3error("More than a 16 Mbit replication, perhaps the replication factor"
" was two's-complement negative: "
<< rhsval << " (" << static_cast<int32_t>(rhsval) << ")");
} else if (rhsval > 8192) {
if (rhsval > 8192) {
v3warn(WIDTHCONCAT, "More than a 8k bit replication is probably wrong: " << rhsval);
}
setZero();
+10 -2
View File
@@ -798,10 +798,18 @@ class WidthVisitor final : public VNVisitor {
iterateCheckSizedSelf(nodep, "RHS", nodep->countp(), SELF, BOTH);
V3Const::constifyParamsNoWarnEdit(nodep->countp()); // rhsp may change
uint32_t times = 1;
int32_t times = 1; // IEEE replicate value is integral
const AstConst* const constp = VN_CAST(nodep->countp(), Const);
if (constp) times = constp->toUInt();
if (constp) {
if (constp->num().isFourState() || constp->num().isNegative()) {
nodep->v3error("Replication value of < 0 or X/Z not legal"
" (IEEE 1800-2023 11.4.12.1): "
<< constp->prettyNameQ());
} else {
times = constp->toSInt();
}
}
AstNodeDType* const vdtypep = m_vup->dtypeNullSkipRefp();
if (VN_IS(vdtypep, QueueDType) || VN_IS(vdtypep, DynArrayDType)