Add error on class 'function static'.
This commit is contained in:
parent
4bd17f0a6f
commit
6467351752
1
Changes
1
Changes
|
|
@ -20,6 +20,7 @@ Verilator 5.039 devel
|
|||
* Add enum base data type, wire data type, and I/O versus data declaration checking per IEEE.
|
||||
* Add error on missing forward declarations (#6206). [Alex Solomatnikov]
|
||||
* Add error when trying to assign class object to variable of non-class types (#6237). [Igor Zaworski, Antmicro Ltd.]
|
||||
* Add error on class 'function static'.
|
||||
* Add `-DVERILATOR=1` definition to compiler flags when using verilated.mk.
|
||||
* Support member-level triggers for virtual interfaces (#5166) (#6148). [Yilou Wang]
|
||||
* Support unassigned virtual interfaces (#5265) (#6245). [Szymon Gizler, Antmicro Ltd.]
|
||||
|
|
|
|||
|
|
@ -2480,6 +2480,7 @@ public:
|
|||
AstNodeFTask* cloneType(const string& name) override {
|
||||
return new AstFunc{fileline(), name, nullptr, nullptr};
|
||||
}
|
||||
string verilogKwd() const override { return "function"; }
|
||||
};
|
||||
class AstLet final : public AstNodeFTask {
|
||||
// Verilog "let" statement
|
||||
|
|
@ -2495,6 +2496,7 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
AstNodeFTask* cloneType(const string& name) override { return new AstLet{fileline(), name}; }
|
||||
string verilogKwd() const override { return "let"; }
|
||||
};
|
||||
class AstProperty final : public AstNodeFTask {
|
||||
// A property inside a module
|
||||
|
|
@ -2506,6 +2508,7 @@ public:
|
|||
AstNodeFTask* cloneType(const string& name) override {
|
||||
return new AstProperty{fileline(), name, nullptr};
|
||||
}
|
||||
string verilogKwd() const override { return "property"; }
|
||||
};
|
||||
class AstTask final : public AstNodeFTask {
|
||||
// A task inside a module
|
||||
|
|
@ -2516,6 +2519,7 @@ public:
|
|||
AstNodeFTask* cloneType(const string& name) override {
|
||||
return new AstTask{fileline(), name, nullptr};
|
||||
}
|
||||
string verilogKwd() const override { return "task"; }
|
||||
};
|
||||
|
||||
// === AstNodeFile ===
|
||||
|
|
|
|||
|
|
@ -198,10 +198,11 @@ class LinkParseVisitor final : public VNVisitor {
|
|||
// DPI-imported functions and properties don't have lifetime specifiers
|
||||
m_lifetime = VLifetime::NONE;
|
||||
}
|
||||
nodep->lifetime(m_lifetime);
|
||||
for (AstNode* itemp = nodep->stmtsp(); itemp; itemp = itemp->nextp()) {
|
||||
AstVar* const varp = VN_CAST(itemp, Var);
|
||||
if (varp && varp->valuep() && varp->lifetime().isNone()
|
||||
&& m_lifetime.isStatic() && !varp->isIO()) {
|
||||
&& nodep->lifetime().isStatic() && !varp->isIO()) {
|
||||
if (VN_IS(m_modp, Module)) {
|
||||
nodep->v3warn(IMPLICITSTATIC,
|
||||
"Function/task's lifetime implicitly set to static\n"
|
||||
|
|
@ -223,7 +224,12 @@ class LinkParseVisitor final : public VNVisitor {
|
|||
}
|
||||
}
|
||||
}
|
||||
nodep->lifetime(m_lifetime);
|
||||
}
|
||||
if (nodep->classMethod() && nodep->lifetime().isStatic()) {
|
||||
nodep->v3error("Class function/task cannot be static lifetime ('"
|
||||
<< nodep->verilogKwd() << " static') (IEEE 1800-2023 6.21)\n"
|
||||
<< nodep->warnMore() << "... May have intended 'static "
|
||||
<< nodep->verilogKwd() << "'");
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
%Error: t/t_class_func_static_bad.v:10:17: Class function/task cannot be static lifetime ('task static') (IEEE 1800-2023 6.21)
|
||||
: ... May have intended 'static task'
|
||||
10 | task static task_st(int x);
|
||||
| ^~~~~~~
|
||||
... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance.
|
||||
%Error: t/t_class_func_static_bad.v:14:25: Class function/task cannot be static lifetime ('function static') (IEEE 1800-2023 6.21)
|
||||
: ... May have intended 'static function'
|
||||
14 | function static int func_st(int x);
|
||||
| ^~~~~~~
|
||||
%Error: Exiting due to
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#!/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('linter')
|
||||
|
||||
test.lint(fails=True, expect_filename=test.golden_filename)
|
||||
|
||||
test.passes()
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// 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
|
||||
|
||||
module t;
|
||||
|
||||
class C;
|
||||
task static task_st(int x); // BAD - methods have automatic lifetime
|
||||
int y;
|
||||
y = 2 * x;
|
||||
endtask
|
||||
function static int func_st(int x); // BAD - methods have automatic lifetime
|
||||
int y;
|
||||
y = 2 * x;
|
||||
return y;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
initial $stop;
|
||||
|
||||
endmodule
|
||||
|
|
@ -16,7 +16,7 @@ class Bar;
|
|||
endclass
|
||||
|
||||
class Baz;
|
||||
function static Bar get_bar;
|
||||
static function Bar get_bar;
|
||||
Bar b = new;
|
||||
return b;
|
||||
endfunction
|
||||
|
|
@ -37,7 +37,7 @@ class ExtendCls extends Cls;
|
|||
endclass
|
||||
|
||||
class Getter1;
|
||||
function static int get_1;
|
||||
static function int get_1;
|
||||
return 1;
|
||||
endfunction
|
||||
endclass
|
||||
|
|
@ -54,8 +54,7 @@ class uvm_root;
|
|||
endfunction
|
||||
endclass
|
||||
|
||||
module t (/*AUTOARG*/
|
||||
);
|
||||
module t (/*AUTOARG*/);
|
||||
|
||||
initial begin
|
||||
Foo foo = new;
|
||||
|
|
|
|||
|
|
@ -22,10 +22,6 @@ class my_cls;
|
|||
static int cnt = 0;
|
||||
return ++cnt;
|
||||
endfunction
|
||||
static function static int get_cnt2;
|
||||
int cnt = 0;
|
||||
return ++cnt;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
module t (/*AUTOARG*/
|
||||
|
|
@ -103,8 +99,6 @@ module t (/*AUTOARG*/
|
|||
//
|
||||
v = my_cls::get_cnt1(); `checkh(v, 1);
|
||||
v = my_cls::get_cnt1(); `checkh(v, 2);
|
||||
v = my_cls::get_cnt2(); `checkh(v, 1);
|
||||
v = my_cls::get_cnt2(); `checkh(v, 2);
|
||||
//
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue