diff --git a/elab_expr.cc b/elab_expr.cc index 0080d9971..9f1074221 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -5994,6 +5994,8 @@ NetExpr* PEIdent::elaborate_expr_net_idx_up_(Design*des, NetScope*scope, return 0; NetExpr*base = calculate_up_do_base_(des, scope, need_const); + if (!base) + return nullptr; // Use the part select width already calculated by test_width(). unsigned long wid = min_width_; @@ -6141,6 +6143,8 @@ NetExpr* PEIdent::elaborate_expr_net_idx_do_(Design*des, NetScope*scope, return 0; NetExpr*base = calculate_up_do_base_(des, scope, need_const); + if (!base) + return nullptr; // Use the part select width already calculated by test_width(). unsigned long wid = min_width_; diff --git a/ivtest/ivltests/partsel_invalid_idx1.v b/ivtest/ivltests/partsel_invalid_idx1.v new file mode 100644 index 000000000..a6a421982 --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx1.v @@ -0,0 +1,14 @@ +// Check that a non-existent index into a vector results in an elaboration error. + +module test; + + reg [31:0] a; + wire b; + + assign b = a[does_not_exist]; // Error: Invalid index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/partsel_invalid_idx2.v b/ivtest/ivltests/partsel_invalid_idx2.v new file mode 100644 index 000000000..040507d37 --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx2.v @@ -0,0 +1,14 @@ +// Check that a non-existent index into a vector results in an elaboration error. + +module test; + + reg [31:0] a; + wire [1:0] b; + + assign b = a[does_not_exist+:2]; // Error: Invalid base index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/partsel_invalid_idx3.v b/ivtest/ivltests/partsel_invalid_idx3.v new file mode 100644 index 000000000..88b96cd64 --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx3.v @@ -0,0 +1,14 @@ +// Check that a non-existent index into a vector results in an elaboration error. + +module test; + + reg [31:0] a; + wire [1:0] b; + + assign b = a[does_not_exist-:2]; // Error: Invalid base index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/partsel_invalid_idx4.v b/ivtest/ivltests/partsel_invalid_idx4.v new file mode 100644 index 000000000..7c8c602fd --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx4.v @@ -0,0 +1,15 @@ +// Check that a non-existent index into a parameter results in an elaboration error. + +module test; + + parameter [31:0] P = 'h0; + + wire x; + + assign x = P[does_not_exist]; // Error: Invalid index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/partsel_invalid_idx5.v b/ivtest/ivltests/partsel_invalid_idx5.v new file mode 100644 index 000000000..22ba33e28 --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx5.v @@ -0,0 +1,15 @@ +// Check that a non-existent index into a parameter results in an elaboration error. + +module test; + + parameter [31:0] P = 'h0; + + wire [1:0] x; + + assign x = P[does_not_exist+:2]; // Error: Invalid base index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/partsel_invalid_idx6.v b/ivtest/ivltests/partsel_invalid_idx6.v new file mode 100644 index 000000000..6fae10381 --- /dev/null +++ b/ivtest/ivltests/partsel_invalid_idx6.v @@ -0,0 +1,15 @@ +// Check that a non-existent index into a parameter results in an elaboration error. + +module test; + + parameter [31:0] P = 'h0; + + wire [1:0] x; + + assign x = P[does_not_exist-:2]; // Error: Invalid base index + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 8aeca1fcb..009eb69c0 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -87,6 +87,12 @@ module_ordered_list2 vvp_tests/module_ordered_list2.json module_port_array1 vvp_tests/module_port_array1.json module_port_array_init1 vvp_tests/module_port_array_init1.json non-polymorphic-abs vvp_tests/non-polymorphic-abs.json +partsel_invalid_idx1 vvp_tests/partsel_invalid_idx1.json +partsel_invalid_idx2 vvp_tests/partsel_invalid_idx2.json +partsel_invalid_idx3 vvp_tests/partsel_invalid_idx3.json +partsel_invalid_idx4 vvp_tests/partsel_invalid_idx4.json +partsel_invalid_idx5 vvp_tests/partsel_invalid_idx5.json +partsel_invalid_idx6 vvp_tests/partsel_invalid_idx6.json param_test3 vvp_tests/param_test3.json param-width vvp_tests/param-width.json param-width-vlog95 vvp_tests/param-width-vlog95.json diff --git a/ivtest/vvp_tests/partsel_invalid_idx1.json b/ivtest/vvp_tests/partsel_invalid_idx1.json new file mode 100644 index 000000000..df6648396 --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx1.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx1.v" +} diff --git a/ivtest/vvp_tests/partsel_invalid_idx2.json b/ivtest/vvp_tests/partsel_invalid_idx2.json new file mode 100644 index 000000000..ef3a7c5cd --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx2.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx2.v" +} diff --git a/ivtest/vvp_tests/partsel_invalid_idx3.json b/ivtest/vvp_tests/partsel_invalid_idx3.json new file mode 100644 index 000000000..7df8bafd1 --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx3.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx3.v" +} diff --git a/ivtest/vvp_tests/partsel_invalid_idx4.json b/ivtest/vvp_tests/partsel_invalid_idx4.json new file mode 100644 index 000000000..b8db08862 --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx4.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx4.v" +} diff --git a/ivtest/vvp_tests/partsel_invalid_idx5.json b/ivtest/vvp_tests/partsel_invalid_idx5.json new file mode 100644 index 000000000..d9212489a --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx5.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx5.v" +} diff --git a/ivtest/vvp_tests/partsel_invalid_idx6.json b/ivtest/vvp_tests/partsel_invalid_idx6.json new file mode 100644 index 000000000..3c7b2c5b8 --- /dev/null +++ b/ivtest/vvp_tests/partsel_invalid_idx6.json @@ -0,0 +1,4 @@ +{ + "type" : "CE", + "source" : "partsel_invalid_idx6.v" +}