Skip to content

Commit 9c8a850

Browse files
authored
Merge pull request #1333 from diffblue/error-unpacked-struct-assignment
Verilog: refuse assignments of other types to unpacked structs
2 parents f3b7374 + 328ca3d commit 9c8a850

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
unpacked_struct2.sv
3+
4+
^file .* line 9: failed to convert `signed \[31:0\]' to `struct'$
5+
^EXIT=2$
6+
^SIGNAL=0$
7+
--
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
3+
// an unpacked struct type
4+
typedef struct {
5+
bit field;
6+
} s_type;
7+
8+
// bit-vectors cannot be assigned to unpacked structs
9+
wire s_type w = 123;
10+
11+
endmodule

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ void verilog_typecheck_exprt::assignment_conversion(
223223
if(lhs_type == rhs.type())
224224
return;
225225

226+
if(lhs_type.id() == ID_struct && !lhs_type.get_bool(ID_packed))
227+
{
228+
// assignment of a non-matching type to unpacked struct
229+
throw errort().with_location(rhs.source_location())
230+
<< "failed to convert `" << to_string(original_rhs_type) << "' to `"
231+
<< to_string(lhs_type) << "'";
232+
}
233+
226234
// do enum, union and struct decay
227235
enum_decay(rhs);
228236
struct_decay(rhs);

0 commit comments

Comments
 (0)