Skip to content

Commit b5fdf06

Browse files
committed
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>
1 parent bea0fde commit b5fdf06

13 files changed

Lines changed: 147 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ivltests/sv_cast_indexed_target_fail.v:9: error: Dimensions after a type identifier are not allowed in a cast target.
2+
ivltests/sv_cast_indexed_target_fail.v:5: : The type was declared here.
3+
Elaboration failed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ivltests/sv_cast_type_error_once_fail.v:8: error: Unable to bind parameter `missing' in `test'
2+
ivltests/sv_cast_type_error_once_fail.v:8: error: Dimensions must be a constant with no unknown or high-Z bits.
3+
ivltests/sv_cast_type_error_once_fail.v:8 : This MSB expression violates the rule: missing
4+
2 error(s) during elaboration.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Check that typed elaboration uses the explicit cast target type.
2+
3+
module test;
4+
5+
typedef logic scalar_t;
6+
typedef scalar_t [7:0] packed_byte_t;
7+
typedef logic [7:0] byte_array_t[];
8+
9+
packed_byte_t result[];
10+
bit failed = 1'b0;
11+
12+
initial begin
13+
result = byte_array_t'(16'h12ab);
14+
15+
if (result.size() != 2 || result[0] !== 8'h12 ||
16+
result[1] !== 8'hab) begin
17+
$display("FAILED(%0d). Incorrect result", `__LINE__);
18+
failed = 1'b1;
19+
end
20+
21+
if (!failed) begin
22+
$display("PASSED");
23+
end
24+
end
25+
26+
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Check that dimensions cannot follow a type identifier in a cast target.
2+
3+
module test;
4+
5+
typedef logic [7:0] T;
6+
logic [7:0] value;
7+
8+
initial begin
9+
value = T[3:0]'(1);
10+
end
11+
12+
endmodule
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check an inline packed dimension in a type cast.
2+
3+
module test;
4+
5+
logic [7:0] result;
6+
7+
initial begin
8+
result = logic [3:0]'(8'haf);
9+
10+
if (result !== 8'h0f) begin
11+
$display("FAILED(%0d). Expected 0f, got %h", `__LINE__, result);
12+
end else begin
13+
$display("PASSED");
14+
end
15+
end
16+
17+
endmodule
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Check that a cast target type is elaborated only once.
2+
3+
module test;
4+
5+
logic [7:0] value;
6+
7+
initial begin
8+
value = logic [missing:0]'(1);
9+
end
10+
11+
endmodule
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Check that a cast target type is resolved separately for each instance.
2+
3+
module M #(
4+
parameter type T = logic [3:0],
5+
parameter integer EXPECTED_WIDTH = 4
6+
) (
7+
output reg failed
8+
);
9+
10+
initial begin
11+
failed = 1'b0;
12+
13+
if ($bits(T'(0)) !== EXPECTED_WIDTH) begin
14+
$display("FAILED(%0d). Expected %0d, got %0d", `__LINE__,
15+
EXPECTED_WIDTH, $bits(T'(0)));
16+
failed = 1'b1;
17+
end
18+
end
19+
20+
endmodule
21+
22+
module test;
23+
24+
wire failed4;
25+
wire failed8;
26+
27+
M #(.T(logic [3:0]), .EXPECTED_WIDTH(4)) i4(.failed(failed4));
28+
M #(.T(logic [7:0]), .EXPECTED_WIDTH(8)) i8(.failed(failed8));
29+
30+
initial begin
31+
#1;
32+
33+
if (!failed4 && !failed8) begin
34+
$display("PASSED");
35+
end
36+
end
37+
38+
endmodule

‎ivtest/regress-vvp.list‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ sv_byte_array_string_fail3 vvp_tests/sv_byte_array_string_fail3.json
284284
sv_byte_array_string_fail4 vvp_tests/sv_byte_array_string_fail4.json
285285
sv_byte_array_string_fail5 vvp_tests/sv_byte_array_string_fail5.json
286286
sv_call_chain_method1 vvp_tests/sv_call_chain_method1.json
287+
sv_cast_darray_target vvp_tests/sv_cast_darray_target.json
288+
sv_cast_indexed_target_fail vvp_tests/sv_cast_indexed_target_fail.json
289+
sv_cast_type_dimension vvp_tests/sv_cast_type_dimension.json
290+
sv_cast_type_error_once_fail vvp_tests/sv_cast_type_error_once_fail.json
291+
sv_cast_type_parameter_scope vvp_tests/sv_cast_type_parameter_scope.json
287292
sv_chained_constructor1 vvp_tests/sv_chained_constructor1.json
288293
sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json
289294
sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type" : "normal",
3+
"source" : "sv_cast_darray_target.v",
4+
"iverilog-args" : [ "-g2005-sv" ],
5+
"vlog95" : {
6+
"__comment" : "SystemVerilog dynamic arrays are not supported",
7+
"type" : "CE"
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type" : "CE",
3+
"source" : "sv_cast_indexed_target_fail.v",
4+
"gold" : "sv_cast_indexed_target_fail",
5+
"iverilog-args" : [ "-g2005-sv" ]
6+
}

0 commit comments

Comments
 (0)