Fix false ENUMVALUE errors in unstable branch (#3761)
This commit is contained in:
parent
f266b02bc7
commit
09dff9c3a7
|
|
@ -1841,9 +1841,12 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void visit(AstCast* nodep) override {
|
void visit(AstCast* nodep) override {
|
||||||
|
if (nodep->didWidth()) return;
|
||||||
|
UINFO(9, "CAST " << nodep << endl);
|
||||||
nodep->dtypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
|
nodep->dtypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
|
||||||
if (m_vup->prelim()) {
|
if (m_vup->prelim()) {
|
||||||
// if (debug()) nodep->dumpTree(cout, " CastPre: ");
|
// if (debug()) nodep->dumpTree(cout, " CastPre: ");
|
||||||
|
// if (debug()) nodep->backp()->dumpTree(cout, " CastPreUpUp: ");
|
||||||
userIterateAndNext(nodep->fromp(), WidthVP(SELF, PRELIM).p());
|
userIterateAndNext(nodep->fromp(), WidthVP(SELF, PRELIM).p());
|
||||||
AstNodeDType* const toDtp = nodep->dtypep()->skipRefToEnump();
|
AstNodeDType* const toDtp = nodep->dtypep()->skipRefToEnump();
|
||||||
AstNodeDType* const fromDtp = nodep->fromp()->dtypep()->skipRefToEnump();
|
AstNodeDType* const fromDtp = nodep->fromp()->dtypep()->skipRefToEnump();
|
||||||
|
|
@ -1878,8 +1881,10 @@ private:
|
||||||
if (bad) {
|
if (bad) {
|
||||||
} else if (const AstBasicDType* const basicp = toDtp->basicp()) {
|
} else if (const AstBasicDType* const basicp = toDtp->basicp()) {
|
||||||
if (!basicp->isDouble() && !fromDtp->isDouble()) {
|
if (!basicp->isDouble() && !fromDtp->isDouble()) {
|
||||||
|
AstNodeDType* const origDTypep = nodep->dtypep();
|
||||||
const int width = toDtp->width();
|
const int width = toDtp->width();
|
||||||
castSized(nodep, nodep->fromp(), width);
|
castSized(nodep, nodep->fromp(), width);
|
||||||
|
nodep->dtypeFrom(origDTypep); // If was enum, need dtype to preserve as enum
|
||||||
// Note castSized might modify nodep->fromp()
|
// Note castSized might modify nodep->fromp()
|
||||||
} else {
|
} else {
|
||||||
iterateCheck(nodep, "value", nodep->fromp(), SELF, FINAL, fromDtp, EXTEND_EXP,
|
iterateCheck(nodep, "value", nodep->fromp(), SELF, FINAL, fromDtp, EXTEND_EXP,
|
||||||
|
|
@ -1924,8 +1929,10 @@ private:
|
||||||
EXTEND_EXP, false);
|
EXTEND_EXP, false);
|
||||||
AstNode* const underp = nodep->fromp()->unlinkFrBack();
|
AstNode* const underp = nodep->fromp()->unlinkFrBack();
|
||||||
// if (debug()) underp->dumpTree(cout, " CastRep: ");
|
// if (debug()) underp->dumpTree(cout, " CastRep: ");
|
||||||
|
underp->dtypeFrom(nodep);
|
||||||
nodep->replaceWith(underp);
|
nodep->replaceWith(underp);
|
||||||
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
||||||
|
underp->didWidth(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void visit(AstCastSize* nodep) override {
|
void visit(AstCastSize* nodep) override {
|
||||||
|
|
@ -2217,6 +2224,9 @@ private:
|
||||||
// and if we keep minwidth we'll consider it unsized which is incorrect
|
// and if we keep minwidth we'll consider it unsized which is incorrect
|
||||||
iterateCheck(nodep, "Enum value", nodep->valuep(), CONTEXT_DET, FINAL, nodep->dtypep(),
|
iterateCheck(nodep, "Enum value", nodep->valuep(), CONTEXT_DET, FINAL, nodep->dtypep(),
|
||||||
EXTEND_EXP);
|
EXTEND_EXP);
|
||||||
|
// Always create a cast, to avoid later ENUMVALUE warnings
|
||||||
|
nodep->valuep(new AstCast{nodep->valuep()->fileline(), nodep->valuep()->unlinkFrBack(),
|
||||||
|
nodep->dtypep()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void visit(AstEnumItemRef* nodep) override {
|
void visit(AstEnumItemRef* nodep) override {
|
||||||
|
|
@ -6139,12 +6149,13 @@ private:
|
||||||
if (castable != COMPATIBLE && castable != ENUM_IMPLICIT && !VN_IS(underp, Cast)
|
if (castable != COMPATIBLE && castable != ENUM_IMPLICIT && !VN_IS(underp, Cast)
|
||||||
&& !VN_IS(underp, CastDynamic) && !m_enumItemp && warnOn) {
|
&& !VN_IS(underp, CastDynamic) && !m_enumItemp && warnOn) {
|
||||||
nodep->v3warn(ENUMVALUE,
|
nodep->v3warn(ENUMVALUE,
|
||||||
"Illegal implicit conversion to enum "
|
"Implicit conversion to enum "
|
||||||
<< expDTypep->prettyDTypeNameQ() << " from "
|
<< expDTypep->prettyDTypeNameQ() << " from "
|
||||||
<< underp->dtypep()->prettyDTypeNameQ()
|
<< underp->dtypep()->prettyDTypeNameQ()
|
||||||
<< " (IEEE 1800-2017 6.19.3)\n"
|
<< " (IEEE 1800-2017 6.19.3)\n"
|
||||||
<< nodep->warnMore()
|
<< nodep->warnMore()
|
||||||
<< "... Suggest use enum's mnemonic, or static cast");
|
<< "... Suggest use enum's mnemonic, or static cast");
|
||||||
|
if (debug()) nodep->backp()->dumpTree(cout, "- back: ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AstNodeDType* subDTypep = expDTypep;
|
AstNodeDType* subDTypep = expDTypep;
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ public:
|
||||||
num.isSigned(nodep->isSigned());
|
num.isSigned(nodep->isSigned());
|
||||||
AstConst* const newp = new AstConst{nodep->fileline(), num};
|
AstConst* const newp = new AstConst{nodep->fileline(), num};
|
||||||
newp->dtypeFrom(nodep);
|
newp->dtypeFrom(nodep);
|
||||||
|
newp->user1(true);
|
||||||
return newp;
|
return newp;
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -163,6 +164,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void visit(AstConst* nodep) override {
|
void visit(AstConst* nodep) override {
|
||||||
|
if (nodep->user1SetOnce()) return; // Process once
|
||||||
UASSERT_OBJ(nodep->dtypep(), nodep, "No dtype");
|
UASSERT_OBJ(nodep->dtypep(), nodep, "No dtype");
|
||||||
iterate(nodep->dtypep()); // Do datatype first
|
iterate(nodep->dtypep()); // Do datatype first
|
||||||
if (AstConst* const newp = newIfConstCommitSize(nodep)) {
|
if (AstConst* const newp = newIfConstCommitSize(nodep)) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
%Error-ENUMVALUE: t/t_enum_type_bad.v:28:9: Illegal implicit conversion to enum 't.e_t' from 'logic[31:0]' (IEEE 1800-2017 6.19.3)
|
%Error-ENUMVALUE: t/t_enum_type_bad.v:28:9: Implicit conversion to enum 't.e_t' from 'logic[31:0]' (IEEE 1800-2017 6.19.3)
|
||||||
: ... In instance t
|
: ... In instance t
|
||||||
: ... Suggest use enum's mnemonic, or static cast
|
: ... Suggest use enum's mnemonic, or static cast
|
||||||
28 | e = 1;
|
28 | e = 1;
|
||||||
| ^
|
| ^
|
||||||
... For error description see https://verilator.org/warn/ENUMVALUE?v=latest
|
... For error description see https://verilator.org/warn/ENUMVALUE?v=latest
|
||||||
%Error-ENUMVALUE: t/t_enum_type_bad.v:29:9: Illegal implicit conversion to enum 't.o_t' from 't.e_t' (IEEE 1800-2017 6.19.3)
|
%Error-ENUMVALUE: t/t_enum_type_bad.v:29:9: Implicit conversion to enum 't.o_t' from 't.e_t' (IEEE 1800-2017 6.19.3)
|
||||||
: ... In instance t
|
: ... In instance t
|
||||||
: ... Suggest use enum's mnemonic, or static cast
|
: ... Suggest use enum's mnemonic, or static cast
|
||||||
29 | o = e;
|
29 | o = e;
|
||||||
| ^
|
| ^
|
||||||
%Error-ENUMVALUE: t/t_enum_type_bad.v:35:9: Illegal implicit conversion to enum 't.o_t' from 'ENUMDTYPE 't.e_t'' (IEEE 1800-2017 6.19.3)
|
%Error-ENUMVALUE: t/t_enum_type_bad.v:35:9: Implicit conversion to enum 't.o_t' from 'ENUMDTYPE 't.e_t'' (IEEE 1800-2017 6.19.3)
|
||||||
: ... In instance t
|
: ... In instance t
|
||||||
: ... Suggest use enum's mnemonic, or static cast
|
: ... Suggest use enum's mnemonic, or static cast
|
||||||
35 | o = str.m_e;
|
35 | o = str.m_e;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||||
|
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||||
|
#
|
||||||
|
# Copyright 2022 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
|
||||||
|
|
||||||
|
scenarios(simulator => 1);
|
||||||
|
|
||||||
|
compile(
|
||||||
|
);
|
||||||
|
|
||||||
|
execute(
|
||||||
|
check_finished => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
ok(1);
|
||||||
|
1;
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2022 by Wilson Snyder.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
module t(/*AUTOARG*/);
|
||||||
|
|
||||||
|
localparam logic [9:0] V2 = (1 << 2);
|
||||||
|
localparam logic [9:0] V1 = (1 << 1);
|
||||||
|
localparam logic [9:0] V0 = (1 << 0);
|
||||||
|
typedef enum logic [9:0] {
|
||||||
|
ZERO = '0,
|
||||||
|
VAL0 = V0,
|
||||||
|
VAL1 = V1,
|
||||||
|
VAL01 = V0 | V1
|
||||||
|
} enum_t;
|
||||||
|
|
||||||
|
localparam enum_t PARAMVAL1 = VAL1;
|
||||||
|
localparam enum_t PARAMVAL1CONST = enum_t'(2);
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
enum_t e;
|
||||||
|
e = VAL01;
|
||||||
|
if (e != VAL01) $stop;
|
||||||
|
|
||||||
|
if (PARAMVAL1 != VAL1) $stop;
|
||||||
|
if (PARAMVAL1CONST != VAL1) $stop;
|
||||||
|
|
||||||
|
$write("*-* All Finished *-*\n");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue