From 19abce5535f08da94a80fd552dc3711d8a62af83 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 1 Apr 2020 18:43:53 -0400 Subject: [PATCH] Suppress REALCVT for whole real numbers. --- Changes | 2 ++ src/V3Width.cpp | 9 ++++++++- test_regress/t/t_lint_realcvt_bad.v | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 4dafd40f2..0758bd808 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ The contributors that suggested a given feature are shown in []. Thanks! *** Change --quiet-exit to also suppress 'Exiting due to N errors'. +**** Suppress REALCVT for whole real numbers. + **** Fix parameter type redeclaring a type, #2195. [hdzhangdoc] **** Fix VCD open with empty filename, #2198. [Julius Baxter] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index dbe2f591c..df700b182 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4338,9 +4338,16 @@ private: // IEEE-2012 11.8.1: Signed: Type coercion creates signed // 11.8.2: Argument to convert is self-determined if (nodep && nodep->dtypep()->skipRefp()->isDouble()) { - UINFO(6," spliceCvtS: "<unlinkFrBack(&linker); + if (AstConst* constp = VN_CAST(nodep, Const)) { + // Ignore obvious conversions of whole real numbers, e.g. 1.0 -> 1 + if (constp->isDouble() + && constp->num().toDouble() == floor(constp->num().toDouble())) { + warnOn = false; + } + } if (warnOn) nodep->v3warn(REALCVT, "Implicit conversion of real to integer"); AstNode* newp = new AstRToIRoundS(nodep->fileline(), nodep); linker.relink(newp); diff --git a/test_regress/t/t_lint_realcvt_bad.v b/test_regress/t/t_lint_realcvt_bad.v index 9cba932c9..3ebd6ed7c 100644 --- a/test_regress/t/t_lint_realcvt_bad.v +++ b/test_regress/t/t_lint_realcvt_bad.v @@ -8,5 +8,6 @@ module sub; integer i; initial begin i = 23.2; + i = 23.0; // No warning - often happens with units of time end endmodule