From 832917008c55de0022593b707ae7566bc0005212 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 15 Sep 2022 12:22:03 +0200 Subject: [PATCH 1/2] Handle unpacked dimensions for struct and union members Unpacked dimensions for struct or union members are currently silently discarded. E.g. ``` struct packed { int x[2]; } s; ``` will elaborate successfully as a struct with a non-array int typed field. This should instead elaborate to an unpacked array of ints typed field. And subsequently, since unpacked arrays are not allowed in a packed struct or union, result in an error instead. Signed-off-by: Lars-Peter Clausen --- elab_type.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elab_type.cc b/elab_type.cc index 413e6f61c..41bdbf15f 100644 --- a/elab_type.cc +++ b/elab_type.cc @@ -215,7 +215,8 @@ ivl_type_t struct_type_t::elaborate_type_raw(Design*des, NetScope*scope) const netstruct_t::member_t memb; memb.name = namep->name; - memb.net_type = mem_vec; + memb.net_type = elaborate_array_type(des, scope, *this, + mem_vec, namep->index); res->append_member(des, memb); } } From cff24f77b4211004c935f37e999a300abfaf6410 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 15 Sep 2022 12:29:48 +0200 Subject: [PATCH 2/2] Add regression tests for packed struct/union with unpacked array members Check that a packed struct or union with an unpacked array, dynamic array or queue as a member is detected as an error. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/struct_packed_darray_fail.v | 14 ++++++++++++++ ivtest/ivltests/struct_packed_queue_fail.v | 13 +++++++++++++ ivtest/ivltests/struct_packed_uarray_fail.v | 14 ++++++++++++++ ivtest/ivltests/union_packed_darray_fail.v | 14 ++++++++++++++ ivtest/ivltests/union_packed_queue_fail.v | 14 ++++++++++++++ ivtest/ivltests/union_packed_uarray_fail.v | 15 +++++++++++++++ ivtest/regress-sv.list | 6 ++++++ 7 files changed, 90 insertions(+) create mode 100644 ivtest/ivltests/struct_packed_darray_fail.v create mode 100644 ivtest/ivltests/struct_packed_queue_fail.v create mode 100644 ivtest/ivltests/struct_packed_uarray_fail.v create mode 100644 ivtest/ivltests/union_packed_darray_fail.v create mode 100644 ivtest/ivltests/union_packed_queue_fail.v create mode 100644 ivtest/ivltests/union_packed_uarray_fail.v diff --git a/ivtest/ivltests/struct_packed_darray_fail.v b/ivtest/ivltests/struct_packed_darray_fail.v new file mode 100644 index 000000000..2c06317cc --- /dev/null +++ b/ivtest/ivltests/struct_packed_darray_fail.v @@ -0,0 +1,14 @@ +// Check that declaring a dynamic array typed member in a packed struct is an +// error. + +module test; + + struct packed { + int x[]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/struct_packed_queue_fail.v b/ivtest/ivltests/struct_packed_queue_fail.v new file mode 100644 index 000000000..4ab174827 --- /dev/null +++ b/ivtest/ivltests/struct_packed_queue_fail.v @@ -0,0 +1,13 @@ +// Check that declaring a queue typed member in a packed struct is an error. + +module test; + + struct packed { + int x[$]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/struct_packed_uarray_fail.v b/ivtest/ivltests/struct_packed_uarray_fail.v new file mode 100644 index 000000000..d05ccd25a --- /dev/null +++ b/ivtest/ivltests/struct_packed_uarray_fail.v @@ -0,0 +1,14 @@ +// Check that declaring an unpacked array typed member in a packed struct is an +// error. + +module test; + + struct packed { + int x[2]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/union_packed_darray_fail.v b/ivtest/ivltests/union_packed_darray_fail.v new file mode 100644 index 000000000..50a5440ca --- /dev/null +++ b/ivtest/ivltests/union_packed_darray_fail.v @@ -0,0 +1,14 @@ +// Check that declaring a dynamic array typed member in a packed union is an +// error. + +module test; + + union packed { + int x[]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/union_packed_queue_fail.v b/ivtest/ivltests/union_packed_queue_fail.v new file mode 100644 index 000000000..8f9a94a86 --- /dev/null +++ b/ivtest/ivltests/union_packed_queue_fail.v @@ -0,0 +1,14 @@ +// Check that declaring a queue typed member in a packed union is an +// error. + +module test; + + union packed { + int x[$]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/union_packed_uarray_fail.v b/ivtest/ivltests/union_packed_uarray_fail.v new file mode 100644 index 000000000..9cea64010 --- /dev/null +++ b/ivtest/ivltests/union_packed_uarray_fail.v @@ -0,0 +1,15 @@ +// Check that declaring an unpacked array typed member in a packed union is an +// error. + +module test; + + struct packed { + int x; + shortint y[2]; + } s; + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index b69e4c0da..acc997669 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -470,8 +470,11 @@ struct_line_info CE,-g2009 ivltests gold=struct_line_info.gold struct_member_signed normal,-g2009 ivltests struct_packed_array normal,-g2009 ivltests struct_packed_array2 normal,-g2009 ivltests +struct_packed_darray_fail CE,-g2009 ivltests +struct_packed_queue_fail CE,-g2009 ivltests struct_packed_sysfunct normal,-g2009 ivltests struct_packed_sysfunct2 normal,-g2009 ivltests +struct_packed_uarray_fail CE,-g2009 ivltests struct_packed_write_read2 normal,-g2009 ivltests struct_invalid_member CE,-g2009 ivltests gold=struct_invalid_member.gold struct_signed normal,-g2009 ivltests @@ -752,6 +755,9 @@ ubyte_test normal,-g2005-sv ivltests uint_test normal,-g2005-sv ivltests ulongint_test normal,-g2005-sv ivltests undef_lval_select_SV normal,-g2009 ivltests +union_packed_darray_fail CE,-g2009 ivltests +union_packed_queue_fail CE,-g2009 ivltests +union_packed_uarray_fail CE,-g2009 ivltests unp_array_typedef normal,-g2005-sv ivltests packed_dims_invalid_class CE,-g2005-sv ivltests packed_dims_invalid_module CE,-g2005-sv ivltests