mirror of
https://github.com/verilator/verilator.git
synced 2026-10-02 16:13:34 +02:00
Fix modification of members of object with const handle (#7433)
Signed-off-by: Kamil Danecki <[email protected]>
This commit is contained in:
+10
-2
@@ -218,6 +218,7 @@ class WidthVisitor final : public VNVisitor {
|
|||||||
bool m_underFork = false; // Visiting under a fork
|
bool m_underFork = false; // Visiting under a fork
|
||||||
bool m_underSExpr = false; // Visiting under a sequence expression
|
bool m_underSExpr = false; // Visiting under a sequence expression
|
||||||
bool m_underPackedArray = false; // Visiting under a AstPackArrayDType
|
bool m_underPackedArray = false; // Visiting under a AstPackArrayDType
|
||||||
|
bool m_underMemberSel = false; // Viting under a MemberSel
|
||||||
bool m_hasNamedType = false; // Packed array is defined using named type
|
bool m_hasNamedType = false; // Packed array is defined using named type
|
||||||
AstNode* m_seqUnsupp = nullptr; // Property has unsupported node
|
AstNode* m_seqUnsupp = nullptr; // Property has unsupported node
|
||||||
bool m_hasSExpr = false; // Property has a sequence expression
|
bool m_hasSExpr = false; // Property has a sequence expression
|
||||||
@@ -2924,8 +2925,8 @@ class WidthVisitor final : public VNVisitor {
|
|||||||
}
|
}
|
||||||
} else if (nodep->access().isWriteOrRW() && nodep->varp()->isConst() && !m_paramsOnly
|
} else if (nodep->access().isWriteOrRW() && nodep->varp()->isConst() && !m_paramsOnly
|
||||||
&& (!m_ftaskp || !m_ftaskp->isConstructor())
|
&& (!m_ftaskp || !m_ftaskp->isConstructor())
|
||||||
&& !VN_IS(m_procedurep, InitialAutomatic)
|
&& !VN_IS(m_procedurep, InitialAutomatic) && !VN_IS(m_procedurep, InitialStatic)
|
||||||
&& !VN_IS(m_procedurep, InitialStatic)) {
|
&& !m_underMemberSel) {
|
||||||
// Too loose, but need to allow our generated first assignment
|
// Too loose, but need to allow our generated first assignment
|
||||||
// Move this to a property of the AstInitial block
|
// Move this to a property of the AstInitial block
|
||||||
nodep->v3warn(E_CONSTWRITTEN, "Writing to 'const' data-typed variable "
|
nodep->v3warn(E_CONSTWRITTEN, "Writing to 'const' data-typed variable "
|
||||||
@@ -3561,6 +3562,8 @@ class WidthVisitor final : public VNVisitor {
|
|||||||
void visit(AstMemberSel* nodep) override {
|
void visit(AstMemberSel* nodep) override {
|
||||||
UINFO(5, " MEMBERSEL " << nodep);
|
UINFO(5, " MEMBERSEL " << nodep);
|
||||||
if (nodep->didWidth()) return;
|
if (nodep->didWidth()) return;
|
||||||
|
VL_RESTORER(m_underMemberSel);
|
||||||
|
m_underMemberSel = true;
|
||||||
UINFOTREE(9, nodep, "", "mbs-in");
|
UINFOTREE(9, nodep, "", "mbs-in");
|
||||||
userIterateChildren(nodep, WidthVP{SELF, BOTH}.p());
|
userIterateChildren(nodep, WidthVP{SELF, BOTH}.p());
|
||||||
UINFOTREE(9, nodep, "", "mbs-ic");
|
UINFOTREE(9, nodep, "", "mbs-ic");
|
||||||
@@ -3709,6 +3712,11 @@ class WidthVisitor final : public VNVisitor {
|
|||||||
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (nodep->access().isWriteOrRW() && varp->isConst()) {
|
||||||
|
nodep->v3warn(E_CONSTWRITTEN, "Writing to 'const' data-typed variable "
|
||||||
|
<< nodep->prettyNameQ()
|
||||||
|
<< " (IEEE 1800-2023 6.20.6)");
|
||||||
|
}
|
||||||
nodep->dtypep(foundp->dtypep());
|
nodep->dtypep(foundp->dtypep());
|
||||||
nodep->varp(varp);
|
nodep->varp(varp);
|
||||||
nodep->didWidth(true);
|
nodep->didWidth(true);
|
||||||
|
|||||||
Executable
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#!/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: 2026 Wilson Snyder
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('simulator')
|
||||||
|
|
||||||
|
test.compile()
|
||||||
|
|
||||||
|
test.execute()
|
||||||
|
|
||||||
|
test.passes()
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
// verilog_format: off
|
||||||
|
`define stop $stop
|
||||||
|
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
|
||||||
|
// verilog_format: on
|
||||||
|
|
||||||
|
class Cls;
|
||||||
|
int x;
|
||||||
|
endclass
|
||||||
|
|
||||||
|
module t;
|
||||||
|
initial begin
|
||||||
|
const automatic Cls cls = new;
|
||||||
|
cls.x = 1;
|
||||||
|
`checkd(cls.x, 1);
|
||||||
|
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
%Error-CONSTWRITTEN: t/t_const_handle_bad.v:15:9: Writing to 'const' data-typed variable 'x' (IEEE 1800-2023 6.20.6)
|
||||||
|
: ... note: In instance 't'
|
||||||
|
15 | cls.x = 1;
|
||||||
|
| ^
|
||||||
|
... For error description see https://verilator.org/warn/CONSTWRITTEN?v=latest
|
||||||
|
%Error-CONSTWRITTEN: t/t_const_handle_bad.v:16:10: Writing to 'const' data-typed variable 'x' (IEEE 1800-2023 6.20.6)
|
||||||
|
: ... note: In instance 't'
|
||||||
|
16 | cls2.x = 1;
|
||||||
|
| ^
|
||||||
|
%Error-CONSTWRITTEN: t/t_const_handle_bad.v:18:5: Writing to 'const' data-typed variable 'cls' (IEEE 1800-2023 6.20.6)
|
||||||
|
: ... note: In instance 't'
|
||||||
|
18 | cls = cls2;
|
||||||
|
| ^~~
|
||||||
|
%Error: Exiting due to
|
||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/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: 2026 Wilson Snyder
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('vlt')
|
||||||
|
|
||||||
|
test.lint(fails=True, expect_filename=test.golden_filename)
|
||||||
|
|
||||||
|
test.passes()
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
class Cls;
|
||||||
|
const int x;
|
||||||
|
endclass
|
||||||
|
|
||||||
|
module t;
|
||||||
|
initial begin
|
||||||
|
const automatic Cls cls = new;
|
||||||
|
automatic Cls cls2 = new;
|
||||||
|
cls.x = 1;
|
||||||
|
cls2.x = 1;
|
||||||
|
|
||||||
|
cls = cls2;
|
||||||
|
cls2 = cls;
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
Reference in New Issue
Block a user