Fix wildcard equality and inside operators for non-fourstate expressions (#5673)

This commit is contained in:
Ryszard Rozak 2024-12-12 14:51:48 +01:00 committed by GitHub
parent a2f327f729
commit 03e8ef0b0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 124 additions and 6 deletions

View File

@ -1412,9 +1412,9 @@ class TristateVisitor final : public TristateBaseVisitor {
}
}
void visitEqNeqWild(AstNodeBiop* nodep) {
if (!VN_IS(nodep->rhsp(), Const)) {
nodep->v3warn(E_UNSUPPORTED, // Says spac.
"Unsupported: RHS of ==? or !=? must be constant to be synthesizable");
if (!VN_IS(nodep->rhsp(), Const) && nodep->rhsp()->dtypep()->isFourstate()) {
nodep->v3warn(E_UNSUPPORTED,
"Unsupported: RHS of ==? or !=? is fourstate but not a constant");
// rhs we want to keep X/Z intact, so otherwise ignore
}
iterateAndNextNull(nodep->lhsp());

View File

@ -237,9 +237,11 @@ class UnknownVisitor final : public VNVisitor {
AstNodeExpr* const rhsp = nodep->rhsp()->unlinkFrBack();
AstNodeExpr* newp;
if (!VN_IS(rhsp, Const)) {
nodep->v3warn(E_UNSUPPORTED, "Unsupported: RHS of ==? or !=? must be "
"constant to be synthesizable"); // Says spec.
// Replace with anything that won't cause more errors
if (rhsp->dtypep()->isFourstate()) {
nodep->v3warn(
E_UNSUPPORTED,
"Unsupported: RHS of ==? or !=? is fourstate but not a constant");
}
newp = new AstEq{nodep->fileline(), lhsp, rhsp};
} else {
// X or Z's become mask, ala case statements.

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

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 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,21 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
function bit get_1_or_0(bit get_1);
return get_1 ? 1'b1 : 1'b0;
endfunction
module t (/*AUTOARG*/);
initial begin
if (get_1_or_0(0) ==? get_1_or_0(1)) $stop;
if (!(get_1_or_0(0) !=? get_1_or_0(1))) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,6 @@
%Error-UNSUPPORTED: t/t_eq_wild_unsup.v:13:13: Unsupported: RHS of ==? or !=? is fourstate but not a constant
: ... note: In instance 't'
13 | if (1 ==? get_x_or_0(0)) $stop;
| ^~~
... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest
%Error: Exiting due to

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 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('vlt')
test.lint(fails=True, expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,19 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
function logic get_x_or_0(logic get_x);
return get_x ? 1'bx : 1'b0;
endfunction
module t;
initial begin
if (1 ==? get_x_or_0(0)) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 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,18 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Antmicro.
// SPDX-License-Identifier: CC0-1.0
module t (/*AUTOARG*/);
initial begin
int q[$] = {1, 2};
if (!(1 inside {q[0], q[1]})) $stop;
if (3 inside {q[0], q[1]}) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule