Fix exponential ConcatN (#5488)

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
Co-authored-by: Szymon Gizler <sgizler@internships.antmicro.com>
This commit is contained in:
Arkadiusz Kozdra 2024-09-26 11:12:24 +02:00 committed by GitHub
parent 798bbe98e8
commit 91c8866ac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 843 additions and 839 deletions

View File

@ -609,13 +609,14 @@ class WidthVisitor final : public VNVisitor {
if (vdtypep && vdtypep->isString()) {
iterateCheckString(nodep, "LHS", nodep->lhsp(), BOTH);
iterateCheckString(nodep, "RHS", nodep->rhsp(), BOTH);
nodep->dtypeSetString();
} else {
iterateCheckSizedSelf(nodep, "LHS", nodep->lhsp(), SELF, BOTH);
iterateCheckSizedSelf(nodep, "RHS", nodep->rhsp(), SELF, BOTH);
nodep->dtypeSetLogicUnsized(nodep->lhsp()->width() + nodep->rhsp()->width(),
nodep->lhsp()->widthMin() + nodep->rhsp()->widthMin(),
VSigning::UNSIGNED);
}
nodep->dtypeSetLogicUnsized(nodep->lhsp()->width() + nodep->rhsp()->width(),
nodep->lhsp()->widthMin() + nodep->rhsp()->widthMin(),
VSigning::UNSIGNED);
// Cleanup zero width Verilog2001 {x,{0{foo}}} now,
// otherwise having width(0) will cause later assertions to fire
if (const AstReplicate* const repp = VN_CAST(nodep->lhsp(), Replicate)) {
@ -652,6 +653,7 @@ class WidthVisitor final : public VNVisitor {
}
}
void visit(AstConcatN* nodep) override {
if (nodep->didWidth()) return;
// String concatenate.
// Already did AstConcat simplifications
if (m_vup->prelim()) {
@ -660,6 +662,7 @@ class WidthVisitor final : public VNVisitor {
nodep->dtypeSetString();
}
if (m_vup->final()) {
nodep->didWidth(true);
if (!nodep->dtypep()->widthSized()) {
// See also error in V3Number
nodeForUnsizedWarning(nodep)->v3warn(
@ -1495,6 +1498,7 @@ class WidthVisitor final : public VNVisitor {
}
}
void visit(AstCvtPackString* nodep) override {
if (nodep->didWidthAndSet()) return;
// Opaque returns, so arbitrary
userIterateAndNext(nodep->lhsp(), WidthVP{SELF, BOTH}.p());
// Type set in constructor

View File

@ -7,10 +7,13 @@
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import signal
import vltest_bootstrap
test.scenarios('simulator')
signal.alarm(5) # 5s timeout
test.compile()
test.execute()

View File

@ -18,6 +18,13 @@ module t (/*AUTOARG*/);
s = {"abcd", e.name(), "ijkl"};
if (s != "abcdefghijkl") $stop;
// hang V3Width if complexity grows exponential (2**52 should suffice)
s = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
if (s != "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") $stop;
$write("*-* All Finished *-*\n");
$finish;
end

File diff suppressed because it is too large Load Diff

View File

@ -541,22 +541,20 @@
</begin>
<begin>
<assign loc="d,53,14,53,15" dtype_id="10">
<cvtpackstring loc="d,53,20,53,21" dtype_id="10">
<concatn loc="d,53,20,53,21" dtype_id="10">
<varref loc="d,53,17,53,20" name="t.all" dtype_id="10"/>
<cvtpackstring loc="d,53,24,53,28" dtype_id="10">
<arraysel loc="d,53,24,53,28" dtype_id="10">
<varref loc="d,17,12,17,16" name="__Venumtab_enum_name2" dtype_id="16"/>
<and loc="d,53,24,53,28" dtype_id="13">
<const loc="d,53,24,53,28" name="32&apos;h7" dtype_id="14"/>
<ccast loc="d,53,22,53,23" dtype_id="13">
<varref loc="d,53,22,53,23" name="t.unnamedblk1.e" dtype_id="13"/>
</ccast>
</and>
</arraysel>
</cvtpackstring>
</concatn>
</cvtpackstring>
<concatn loc="d,53,20,53,21" dtype_id="10">
<varref loc="d,53,17,53,20" name="t.all" dtype_id="10"/>
<cvtpackstring loc="d,53,24,53,28" dtype_id="10">
<arraysel loc="d,53,24,53,28" dtype_id="10">
<varref loc="d,17,12,17,16" name="__Venumtab_enum_name2" dtype_id="16"/>
<and loc="d,53,24,53,28" dtype_id="13">
<const loc="d,53,24,53,28" name="32&apos;h7" dtype_id="14"/>
<ccast loc="d,53,22,53,23" dtype_id="13">
<varref loc="d,53,22,53,23" name="t.unnamedblk1.e" dtype_id="13"/>
</ccast>
</and>
</arraysel>
</cvtpackstring>
</concatn>
<varref loc="d,53,10,53,13" name="t.all" dtype_id="10"/>
</assign>
</begin>
@ -580,12 +578,10 @@
<varref loc="d,55,7,55,8" name="t.e" dtype_id="11"/>
</assign>
<assign loc="d,56,11,56,12" dtype_id="10">
<cvtpackstring loc="d,56,17,56,18" dtype_id="10">
<concatn loc="d,56,17,56,18" dtype_id="10">
<varref loc="d,56,14,56,17" name="t.all" dtype_id="10"/>
<const loc="d,56,21,56,25" name="&quot;E04&quot;" dtype_id="10"/>
</concatn>
</cvtpackstring>
<concatn loc="d,56,17,56,18" dtype_id="10">
<varref loc="d,56,14,56,17" name="t.all" dtype_id="10"/>
<const loc="d,56,21,56,25" name="&quot;E04&quot;" dtype_id="10"/>
</concatn>
<varref loc="d,56,7,56,10" name="t.all" dtype_id="10"/>
</assign>
<if loc="d,57,10,57,12">