Skip to content

Commit

Permalink
forbid bit-selects and part-selects of scalar struct fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zachjs committed Sep 28, 2021
1 parent 814f965 commit ff24111
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
* Non-positive integer size casts are now detected and forbidden
* Negative indices in struct pattern literals are now detected and forbidden
* Escaped vendor block comments in macro bodies are now tolerated
* Illegal bit-selects and part-selects of scalar struct fields are now detected
and forbidden, rather than yielding an internal assertion failure

### Bug Fixes

Expand Down
9 changes: 9 additions & 0 deletions src/Convert/Struct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
(UnknownType, orig')
else if structIsntReady subExprType then
(replaceInnerTypeRange NonIndexed rOuter' fieldType, orig')
else if null dims then
error $ "illegal access to range " ++ show (Range Nil NonIndexed rOuter)
++ " of " ++ show (Dot e x) ++ ", which has type " ++ show fieldType
else
(replaceInnerTypeRange NonIndexed rOuter' fieldType, undotted)
where
Expand All @@ -408,6 +411,9 @@ convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
(UnknownType, orig')
else if structIsntReady subExprType then
(replaceInnerTypeRange mode (baseO', lenO') fieldType, orig')
else if null dims then
error $ "illegal access to range " ++ show (Range Nil mode (baseO, lenO))
++ " of " ++ show (Dot e x) ++ ", which has type " ++ show fieldType
else
(replaceInnerTypeRange mode (baseO', lenO') fieldType, undotted)
where
Expand Down Expand Up @@ -438,6 +444,9 @@ convertSubExpr scopes (Bit (Dot e x) i) =
(dropInnerTypeRange backupType, orig')
else if structIsntReady subExprType then
(dropInnerTypeRange fieldType, orig')
else if null dims then
error $ "illegal access to bit " ++ show i ++ " of " ++ show (Dot e x)
++ ", which has type " ++ show fieldType
else
(dropInnerTypeRange fieldType, Bit e' iFlat)
where
Expand Down
7 changes: 7 additions & 0 deletions test/error/struct_logic_bit.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// pattern: illegal access to bit 0 of s\.x, which has type logic
module top;
struct packed {
logic x;
} s;
initial s.x[0] = 1;
endmodule
7 changes: 7 additions & 0 deletions test/error/struct_logic_part_range.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// pattern: illegal access to range \[0:0\] of s\.x, which has type logic
module top;
struct packed {
logic x;
} s;
initial s.x[0:0] = 1;
endmodule
7 changes: 7 additions & 0 deletions test/error/struct_logic_part_select.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// pattern: illegal access to range \[0\+:1\] of s\.x, which has type logic
module top;
struct packed {
logic x;
} s;
initial s.x[0+:1] = 1;
endmodule

0 comments on commit ff24111

Please sign in to comment.