Add additional enum compatibility tests

Add additional enum compatibility tests that check for compatibility in
different contexts.
 * Array element
 * Function return value
 * Function and task argument
 * struct member
 * class property

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-01-15 20:14:53 -08:00
parent d1fb3f8925
commit 300d00b4e2
15 changed files with 273 additions and 1 deletions

View File

@ -0,0 +1,23 @@
// Check that assigning to a enum types variable from an enum typed class
// array element works.
module test;
typedef enum reg [31:0] {
A, B
} E;
E e;
E ea[2];
initial begin
ea[0] = B;
e = ea[0];
if (e === B) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,25 @@
// Check that assigning to a enum types variable from an enum typed function
// call works.
module test;
typedef enum reg [31:0] {
A, B
} E;
function E f();
return B;
endfunction
E e;
initial begin
e = f();
if (e === B) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that passing an enum type task argument works.
module test;
typedef enum reg [31:0] {
A, B
} E;
task t(E e);
if (e === B) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
initial begin
t(B);
end
endmodule

View File

@ -0,0 +1,26 @@
// Check that assigning to a enum types variable from an enum typed struct
// member works.
module test;
typedef enum reg [31:0] {
A, B
} E;
struct packed {
E e;
} s;
E e;
initial begin
s.e = B;
e = s.e;
if (e === B) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,28 @@
// Check that assigning to a enum types variable from an enum typed class
// property works.
module test;
typedef enum reg [31:0] {
A, B
} E;
class C;
E e;
endclass
C c;
E e;
initial begin
c = new;
c.e = B;
e = c.e;
if (e === B) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that an error is reported for implicit cast to enum when assigning
// to an array element.
module test;
typedef enum reg [31:0] {
A, B
} E;
E ea[2];
initial begin
ea[0] = 10; // This should fail. Implicit cast to enum.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that an error is reported for implicit cast to enum when assigning
// from an array element.
module test;
typedef enum reg [31:0] {
A, B
} E;
E e;
int ea[2];
initial begin
ea[0] = B; // This is OK.
e = ea[0]; // This should fail. Implicit cast to enum.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported for implicit cast to enum when assigning
// from a function call.
module test;
typedef enum reg [31:0] {
A, B
} E;
function integer f();
return B;
endfunction
E e;
initial begin
e = f(); // This should fail. Implicit cast to enum type.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that an error is reported for implicit cast to enum for task arguments.
module test;
typedef enum reg [31:0] {
A, B
} E;
task t(E e);
$display("FAILED");
endtask
initial begin
t(10); // This should fail. Implicit cast to enum.
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that an error is reported for implicit cast to enum when assigning to
// struct members.
module test;
typedef enum reg [31:0] {
A, B
} E;
struct packed {
E e;
} s;
initial begin
s.e = 10; // This should fail. Implicit cast to enum.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,22 @@
// Check that an error is reported for implicit cast to enum when assigning to
// class properties.
module test;
typedef enum reg [31:0] {
A, B
} E;
class C;
E e;
endclass
C c;
initial begin
c = new;
c.e = 10; // This should fail. Implicit cast to enum.
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported for implicit cast to enum in function return
// statements.
module test;
typedef enum reg [31:0] {
A, B
} E;
function E f();
return 10; // This should fail. Implicit cast to enum.
endfunction
E e;
initial begin
e = f();
$display("FAILED");
end
endmodule

View File

@ -278,7 +278,19 @@ enum_base_typename2 normal,-g2005-sv ivltests
enum_compatibility1 normal,-g2005-sv ivltests
enum_compatibility2 normal,-g2005-sv ivltests
enum_compatibility3 normal,-g2005-sv ivltests
enum_compatibility_fail CE,-g2005-sv ivltests
enum_compatibility4 normal,-g2005-sv ivltests
enum_compatibility5 normal,-g2005-sv ivltests
enum_compatibility6 normal,-g2005-sv ivltests
enum_compatibility7 normal,-g2005-sv ivltests
enum_compatibility8 normal,-g2005-sv ivltests
enum_compatibility_fail1 CE,-g2005-sv ivltests
enum_compatibility_fail2 CE,-g2005-sv ivltests
enum_compatibility_fail3 CE,-g2005-sv ivltests
enum_compatibility_fail4 CE,-g2005-sv ivltests
enum_compatibility_fail5 CE,-g2005-sv ivltests
enum_compatibility_fail6 CE,-g2005-sv ivltests
enum_compatibility_fail7 CE,-g2005-sv ivltests
enum_compatibility_fail8 CE,-g2005-sv ivltests
enum_elem_ranges normal,-g2005-sv ivltests
enum_dims_invalid CE,-g2005-sv ivltests
enum_in_struct normal,-g2005-sv ivltests

View File

@ -389,6 +389,7 @@ br_gh391 CE,-g2009 ivltests
br_gh437 CE,-g2009 ivltests
br_gh445 CE,-g2009 ivltests
br_gh461 CE,-g2009 ivltests
enum_compatibility8 CE,-g2005-sv ivltests
enum_in_class CE,-g2005-sv ivltests
enum_in_class_name_coll CE,-g2005-sv ivltests
sv_class1 CE,-g2009 ivltests