Skip to content

Commit

Permalink
fix width of post-increment/decrement expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
zachjs committed Sep 19, 2023
1 parent 7d07615 commit 28e99f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontends/verilog/verilog_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static AstNode *addIncOrDecExpr(AstNode *lhs, dict<IdString, AstNode*> *attr, AS
log_assert(stmt->type == AST_ASSIGN_EQ);
AstNode *expr = stmt->children[0]->clone();
if (undo) {
AstNode *minus_one = AstNode::mkconst_int(-1, true);
AstNode *minus_one = AstNode::mkconst_int(-1, true, 1);
expr = new AstNode(op, expr, minus_one);
}
SET_AST_NODE_LOC(expr, begin, end);
Expand Down
13 changes: 13 additions & 0 deletions tests/verilog/asgn_expr.sv
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,18 @@ module top;
check(96, 200, 24);
y = (z >>= 1'sb1) * 2; // shift is implicitly cast to unsigned
check(96, 24, 12);

// check width of post-increment expressions
z = (y = 0);
begin
byte w;
w = 0;
x = {1'b1, ++w};
check(257, 0, 0);
assert (w == 1);
x = {2'b10, w++};
check(513, 0, 0);
assert (w == 2);
end
end
endmodule

0 comments on commit 28e99f2

Please sign in to comment.