Fix accessing non-rand struct member in constraints (#6960)

This commit is contained in:
Pawel Kojma 2026-01-28 13:33:16 +01:00 committed by GitHub
parent 76949f00d3
commit 30e6cd9092
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 1 deletions

View File

@ -1121,6 +1121,7 @@ class ConstraintExprVisitor final : public VNVisitor {
editSMT(nodep, nodep->fromp(), lsbp, msbp);
}
void visit(AstStructSel* nodep) override {
if (editFormat(nodep)) return;
m_structSel = true;
if (VN_IS(nodep->fromp()->dtypep()->skipRefp(), StructDType)) {
AstNodeExpr* const fromp = nodep->fromp();
@ -1154,7 +1155,6 @@ class ConstraintExprVisitor final : public VNVisitor {
}
}
iterateChildren(nodep);
if (editFormat(nodep)) return;
FileLine* const fl = nodep->fileline();
AstSFormatF* newp = nullptr;
if (VN_AS(nodep->fromp(), SFormatF)->name() == "%@.%@") {

View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# 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-FileCopyrightText: 2025 Wilson Snyder
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
if not test.have_solver:
test.skip("No constraint solver installed")
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,27 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain
// SPDX-FileCopyrightText: 2026 Antmicro
// SPDX-License-Identifier: CC0-1.0
typedef struct {int x;} struct_t;
class ConstrClass;
struct_t obj;
rand int rand_int;
constraint addr_c {rand_int == obj.x;}
endclass
module t;
ConstrClass o;
initial begin
o = new;
o.obj.x = 42;
if (o.randomize() == 0) begin
$display("Randomization failed");
$stop;
end else if (o.obj.x != o.rand_int) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule