Add regression tests for elaborated cast targets

Check a type cast with an inline packed dimension and reject dimensions
following a type identifier in a cast target. Use a dimensioned typedef in
the reject test to distinguish dimensions in the type from dimensions after
the identifier.

Check that an error reported while elaborating a cast-target type is emitted
only once when width checking and expression elaboration reuse the cached
target information. Also check that each module instance resolves a
type-parameter cast target using its own parameter value.

Check that typed dynamic-array elaboration constructs the explicit cast
target rather than the enclosing expression type.

Run the tests through the native and vlog95 backends.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-08-03 19:57:03 -07:00
parent bea0fdeb3c
commit b5fdf06475
13 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,3 @@
ivltests/sv_cast_indexed_target_fail.v:9: error: Dimensions after a type identifier are not allowed in a cast target.
ivltests/sv_cast_indexed_target_fail.v:5: : The type was declared here.
Elaboration failed

View File

@ -0,0 +1,4 @@
ivltests/sv_cast_type_error_once_fail.v:8: error: Unable to bind parameter `missing' in `test'
ivltests/sv_cast_type_error_once_fail.v:8: error: Dimensions must be a constant with no unknown or high-Z bits.
ivltests/sv_cast_type_error_once_fail.v:8 : This MSB expression violates the rule: missing
2 error(s) during elaboration.

View File

@ -0,0 +1,26 @@
// Check that typed elaboration uses the explicit cast target type.
module test;
typedef logic scalar_t;
typedef scalar_t [7:0] packed_byte_t;
typedef logic [7:0] byte_array_t[];
packed_byte_t result[];
bit failed = 1'b0;
initial begin
result = byte_array_t'(16'h12ab);
if (result.size() != 2 || result[0] !== 8'h12 ||
result[1] !== 8'hab) begin
$display("FAILED(%0d). Incorrect result", `__LINE__);
failed = 1'b1;
end
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,12 @@
// Check that dimensions cannot follow a type identifier in a cast target.
module test;
typedef logic [7:0] T;
logic [7:0] value;
initial begin
value = T[3:0]'(1);
end
endmodule

View File

@ -0,0 +1,17 @@
// Check an inline packed dimension in a type cast.
module test;
logic [7:0] result;
initial begin
result = logic [3:0]'(8'haf);
if (result !== 8'h0f) begin
$display("FAILED(%0d). Expected 0f, got %h", `__LINE__, result);
end else begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,11 @@
// Check that a cast target type is elaborated only once.
module test;
logic [7:0] value;
initial begin
value = logic [missing:0]'(1);
end
endmodule

View File

@ -0,0 +1,38 @@
// Check that a cast target type is resolved separately for each instance.
module M #(
parameter type T = logic [3:0],
parameter integer EXPECTED_WIDTH = 4
) (
output reg failed
);
initial begin
failed = 1'b0;
if ($bits(T'(0)) !== EXPECTED_WIDTH) begin
$display("FAILED(%0d). Expected %0d, got %0d", `__LINE__,
EXPECTED_WIDTH, $bits(T'(0)));
failed = 1'b1;
end
end
endmodule
module test;
wire failed4;
wire failed8;
M #(.T(logic [3:0]), .EXPECTED_WIDTH(4)) i4(.failed(failed4));
M #(.T(logic [7:0]), .EXPECTED_WIDTH(8)) i8(.failed(failed8));
initial begin
#1;
if (!failed4 && !failed8) begin
$display("PASSED");
end
end
endmodule

View File

@ -284,6 +284,11 @@ sv_byte_array_string_fail3 vvp_tests/sv_byte_array_string_fail3.json
sv_byte_array_string_fail4 vvp_tests/sv_byte_array_string_fail4.json
sv_byte_array_string_fail5 vvp_tests/sv_byte_array_string_fail5.json
sv_call_chain_method1 vvp_tests/sv_call_chain_method1.json
sv_cast_darray_target vvp_tests/sv_cast_darray_target.json
sv_cast_indexed_target_fail vvp_tests/sv_cast_indexed_target_fail.json
sv_cast_type_dimension vvp_tests/sv_cast_type_dimension.json
sv_cast_type_error_once_fail vvp_tests/sv_cast_type_error_once_fail.json
sv_cast_type_parameter_scope vvp_tests/sv_cast_type_parameter_scope.json
sv_chained_constructor1 vvp_tests/sv_chained_constructor1.json
sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json
sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json

View File

@ -0,0 +1,9 @@
{
"type" : "normal",
"source" : "sv_cast_darray_target.v",
"iverilog-args" : [ "-g2005-sv" ],
"vlog95" : {
"__comment" : "SystemVerilog dynamic arrays are not supported",
"type" : "CE"
}
}

View File

@ -0,0 +1,6 @@
{
"type" : "CE",
"source" : "sv_cast_indexed_target_fail.v",
"gold" : "sv_cast_indexed_target_fail",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_cast_type_dimension.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,6 @@
{
"type" : "CE",
"source" : "sv_cast_type_error_once_fail.v",
"gold" : "sv_cast_type_error_once_fail",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_cast_type_parameter_scope.v",
"iverilog-args" : [ "-g2005-sv" ]
}