diff --git a/Changes b/Changes index 6662cfff7..2c76dba5e 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,7 @@ Verilator 5.031 devel * Fix VPI error instead of fatal for vpi_get_value() on large signals (#5571). [Todd Strader] * Fix --output-groups leftover files issue (#5574). [Todd Strader] * Fix slow unsized number parsing (#5577). [Geza Lore] +* Fix negative assignment pattern keys (#5580). [Iztok Jeras] Verilator 5.030 2024-10-27 diff --git a/src/verilog.y b/src/verilog.y index 9fbf16bde..0272e2c4d 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -4006,11 +4006,18 @@ patternKey: // IEEE: merge structure_pattern_key, array_patt // // "foo"member (if structure) // // So for now we only allow a true constant number, or an // // identifier which we treat as a structure member name - yaINTNUM { $$ = new AstConst{$1, *$1}; } - | yaFLOATNUM { $$ = new AstConst{$1, AstConst::RealDouble{}, $1}; } - | id { $$ = new AstText{$1, *$1}; } - | strAsInt { $$ = $1; } - | simple_typeNoRef { $$ = $1; } + yaINTNUM + { $$ = new AstConst{$1, *$1}; } + | '-' yaINTNUM + { V3Number neg{*$2}; neg.opNegate(*$2); $$ = new AstConst{$2, neg}; } + | yaFLOATNUM + { $$ = new AstConst{$1, AstConst::RealDouble{}, $1}; } + | id + { $$ = new AstText{$1, *$1}; } + | strAsInt + { $$ = $1; } + | simple_typeNoRef + { $$ = $1; } // // expanded from simple_type ps_type_identifier (part of simple_type) // // expanded from simple_type ps_parameter_identifier (part of simple_type) | packageClassScopeE idType diff --git a/test_regress/t/t_array_pattern_2d.v b/test_regress/t/t_array_pattern_2d.v index dba37eef2..051e1f1d8 100644 --- a/test_regress/t/t_array_pattern_2d.v +++ b/test_regress/t/t_array_pattern_2d.v @@ -13,6 +13,8 @@ module t (/*AUTOARG*/); logic [31:0] larray_assign [0:3]; logic [31:0] larray_other [0:3]; + logic [31:0] array_neg [-1:1]; + initial begin array_assign[0] = 32'd1; array_assign[3:1] = '{32'd4, 32'd3, 32'd2}; @@ -34,6 +36,11 @@ module t (/*AUTOARG*/); if (larray_other[2] != 3) $stop; if (larray_other[3] != 2) $stop; + array_neg = '{-1: 5, 1: 7, default: 'd6}; + if (array_neg[-1] != 5) $stop; + if (array_neg[0] != 6) $stop; + if (array_neg[1] != 7) $stop; + $write("*-* All Finished *-*\n"); $finish; end