Fix false CMPCONST/UNSIGNED warnings on inside, bug1581.

This commit is contained in:
Wilson Snyder 2019-11-02 16:56:37 -04:00
parent 25f08b29c6
commit 9ff5ef4ad5
4 changed files with 28 additions and 8 deletions

View File

@ -29,7 +29,7 @@ The contributors that suggested a given feature are shown in []. Thanks!
**** Fix bad-syntax crashes, bug1548, bug1550-1553, bug1557-1560, bug1563,
bug1573-1577. [Eric Rippey]
**** Benchmark --protect-lib runtime, bug1519. [Todd Strader]
**** Fix false CMPCONST/UNSIGNED warnings on "inside", bug1581. [Mitch Hayenga]
* Verilator 4.020 2019-10-06

View File

@ -338,6 +338,8 @@ private:
AstNode* bp = AstLte::newTyped(itemp->fileline(),
cexprp->cloneTree(false),
irangep->rhsp()->unlinkFrBack());
ap->fileline()->modifyWarnOff(V3ErrorCode::UNSIGNED, true);
bp->fileline()->modifyWarnOff(V3ErrorCode::CMPCONST, true);
condp = new AstAnd(itemp->fileline(), ap, bp);
} else if (iconstp && iconstp->num().isFourState()
&& (nodep->casex() || nodep->casez() || nodep->caseInside())) {

View File

@ -1475,13 +1475,15 @@ private:
AstNode* inewp;
if (AstInsideRange* irangep = VN_CAST(itemp, InsideRange)) {
// Similar logic in V3Case
inewp = new AstAnd(itemp->fileline(),
new AstGte(itemp->fileline(),
nodep->exprp()->cloneTree(true),
irangep->lhsp()->unlinkFrBack()),
new AstLte(itemp->fileline(),
nodep->exprp()->cloneTree(true),
irangep->rhsp()->unlinkFrBack()));
AstNode* ap = new AstGte(itemp->fileline(),
nodep->exprp()->cloneTree(true),
irangep->lhsp()->unlinkFrBack());
AstNode* bp = new AstLte(itemp->fileline(),
nodep->exprp()->cloneTree(true),
irangep->rhsp()->unlinkFrBack());
ap->fileline()->modifyWarnOff(V3ErrorCode::UNSIGNED, true);
bp->fileline()->modifyWarnOff(V3ErrorCode::CMPCONST, true);
inewp = new AstAnd(itemp->fileline(), ap, bp);
} else {
inewp = new AstEqWild(itemp->fileline(),
nodep->exprp()->cloneTree(true),

View File

@ -32,6 +32,13 @@ module t;
endcase
endfunction
function automatic bit is_00_to_04 (input byte value);
return value inside { [ 8'h0 : 8'h04 ] };
endfunction
function automatic bit is_fe_to_ff (input byte value);
return value inside { [ 8'hfe : 8'hff ] };
endfunction
initial begin
`checkh ((4'd4 inside {4'd1,4'd5}), 1'b0);
`checkh ((4'd4 inside {4'd1,4'd4}), 1'b1);
@ -62,6 +69,15 @@ module t;
`ifndef VERILATOR
`checkh (is_odd(1'b1, XXX), 1'dx);
`endif
//
// Should not give UNSIGNED/CMPCONST warnings
// (Verilator converts to 8'h00 >= 8'h00 which is always true)
`checkh(is_00_to_04(8'h00), 1'b1);
`checkh(is_00_to_04(8'h04), 1'b1);
`checkh(is_00_to_04(8'h05), 1'b0);
`checkh(is_fe_to_ff(8'hfd), 1'b0);
`checkh(is_fe_to_ff(8'hfe), 1'b1);
`checkh(is_fe_to_ff(8'hff), 1'b1);
//
$write("*-* All Finished *-*\n");
$finish;