diff --git a/Changes b/Changes index 4ecc566e0..4c5f7a619 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/src/V3Case.cpp b/src/V3Case.cpp index 789b0aae5..c86bde76a 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -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())) { diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 68d0105ed..4742deb68 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -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), diff --git a/test_regress/t/t_inside.v b/test_regress/t/t_inside.v index de6baba67..06adfe4e3 100644 --- a/test_regress/t/t_inside.v +++ b/test_regress/t/t_inside.v @@ -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;