Fix associative arrays with enum keys (#6034) (#6035)

This commit is contained in:
Petr Nohavica 2025-05-24 23:59:23 +02:00 committed by GitHub
parent 90d4cf1361
commit 22d484d54d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 69 additions and 1 deletions

View File

@ -183,6 +183,7 @@ Pengcheng Xu
Peter Debacker
Peter Horvath
Peter Monsson
Petr Nohavica
Philip Axer
Philipp Wagner
Pierre-Henri Horrein

View File

@ -4802,7 +4802,12 @@ class WidthVisitor final : public VNVisitor {
patp = VN_AS(patp->nextp(), PatMember)) {
patp->dtypep(arrayDtp->subDTypep());
AstNodeExpr* const valuep = patternMemberValueIterate(patp);
AstNode* keyp = patp->keyp();
AstNode* keyp;
if (patp->varrefp()) {
keyp = patp->varrefp();
} else {
keyp = patp->keyp();
}
if (!keyp) {
patp->v3error("Missing pattern key (need an expression then a ':')");
keyp = new AstConst{nodep->fileline(), AstConst::Signed32{}, 0};

18
test_regress/t/t_assoc_enum.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,44 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0x exp=%0x (%s !== %s)\n", `__FILE__,`__LINE__, (gotv), (expv), `"gotv`", `"expv`"); `stop; end while(0);
`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
class X;
typedef enum int {
INITIAL, RUNNING, SUSPENDED, COMPLETING, DONE
} state_t;
static string state_names[state_t] = '{
INITIAL: "INITIAL",
RUNNING: "RUNNING",
SUSPENDED: "SUSPENDED",
COMPLETING: "COMPLETING",
DONE: "DONE"
};
protected state_t state;
function new();
this.state = INITIAL;
`checks(state_names[this.state], "INITIAL");
this.state = RUNNING;
`checks(state_names[this.state], "RUNNING");
endfunction
endclass
module t;/*AUTOARG*/
initial begin
X x = new;
$finish;
end
endmodule