Add warning on expression coverage class references (#5870)

This commit is contained in:
Todd Strader 2025-03-21 08:55:38 -04:00 committed by GitHub
parent c508fd5d24
commit 8c287134d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 2 deletions

View File

@ -39,9 +39,26 @@ class ExprCoverageEligibleVisitor final : public VNVisitor {
// STATE
bool m_eligible = true;
void visit(AstNodeVarRef* nodep) override {
AstNodeDType* dtypep = nodep->varp()->dtypep();
// Class objecs and references not supported for expression coverage
// because the object may not persist until the point at which
// coverage data is gathered
// This could be resolved in the future by protecting against dereferrencing
// null pointers when cloning the expression for expression coverage
if (VN_CAST(dtypep, ClassRefDType)) {
m_eligible = false;
} else {
iterateChildren(nodep);
}
}
void visit(AstNode* nodep) override {
if (!nodep->isExprCoverageEligible()) m_eligible = false;
iterateChildren(nodep);
if (!nodep->isExprCoverageEligible()) {
m_eligible = false;
} else {
iterateChildren(nodep);
}
}
public:

View File

@ -289,6 +289,7 @@
logic ta, tb, tc;
initial begin
cls obj = new;
cls null_obj = null;
int q[5];
int qv[$];
@ -310,6 +311,7 @@
ta = '0;
end
if (!bit'(obj.randomize() with {x < 100;})) $write("");
if (null_obj != null && null_obj.x == 5) $write("");
end
sub the_sub_1 (.p(t1), .q(t2));

View File

@ -129,6 +129,7 @@ module t (/*AUTOARG*/
logic ta, tb, tc;
initial begin
cls obj = new;
cls null_obj = null;
int q[5];
int qv[$];
@ -146,6 +147,7 @@ module t (/*AUTOARG*/
ta = '0;
end
if (!bit'(obj.randomize() with {x < 100;})) $write("");
if (null_obj != null && null_obj.x == 5) $write("");
end
sub the_sub_1 (.p(t1), .q(t2));

View File

@ -417,6 +417,7 @@
logic ta, tb, tc;
initial begin
cls obj = new;
cls null_obj = null;
int q[5];
int qv[$];
@ -438,6 +439,7 @@
ta = '0;
end
if (!bit'(obj.randomize() with {x < 100;})) $write("");
if (null_obj != null && null_obj.x == 5) $write("");
end
sub the_sub_1 (.p(t1), .q(t2));

View File

@ -289,6 +289,7 @@
logic ta, tb, tc;
initial begin
cls obj = new;
cls null_obj = null;
int q[5];
int qv[$];
@ -310,6 +311,7 @@
ta = '0;
end
if (!bit'(obj.randomize() with {x < 100;})) $write("");
if (null_obj != null && null_obj.x == 5) $write("");
end
sub the_sub_1 (.p(t1), .q(t2));