From de35c90847ba5012fb9401e02b35a9d113ef6208 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 11 Oct 2017 19:01:37 -0400 Subject: [PATCH] Fix float-conversion warning, bug1229. --- Changes | 2 ++ configure.ac | 1 + include/verilated.cpp | 2 +- include/verilated_vcd_c.cpp | 2 +- src/V3Graph.cpp | 4 ++-- src/V3Order.cpp | 3 ++- src/V3Stats.cpp | 14 +++++++++----- src/VlcTest.h | 2 +- test_regress/t/t_dpi_import_c.cpp | 4 ++-- 9 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Changes b/Changes index 5b1a0b0a5..90f8a11dc 100644 --- a/Changes +++ b/Changes @@ -35,6 +35,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix -E duplicating output, bug1226. [Odd Magne Reitan] +**** Fix float-conversion warning, bug1229. [Robert Henry] + * Verilator 3.912 2017-09-23 diff --git a/configure.ac b/configure.ac index f6233c3c1..3fd566ec6 100644 --- a/configure.ac +++ b/configure.ac @@ -183,6 +183,7 @@ AC_SUBST(CFG_CXXFLAGS_STD_OLDEST) # Flags for compiling Verilator internals including parser, and Verilated files # These turn on extra warnings and are only used with 'configure --enable-ccwarn' _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wextra) +_MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wfloat-conversion) _MY_CXX_CHECK_OPT(CFG_CXXFLAGS_WEXTRA,-Wlogical-op) AC_SUBST(CFG_CXXFLAGS_WEXTRA) diff --git a/include/verilated.cpp b/include/verilated.cpp index bb44e8efb..fed28d6a7 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -817,7 +817,7 @@ void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) { void _VL_STRING_TO_VINT(int obits, void* destp, size_t srclen, const char* srcp) { // Convert C string to Verilog format - int bytes = VL_BYTES_I(obits); + size_t bytes = VL_BYTES_I(obits); char* op = reinterpret_cast(destp); if (srclen > bytes) srclen = bytes; // Don't overflow destination size_t i; diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index e1b59b60b..90fe1618d 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -354,7 +354,7 @@ void VerilatedVcd::set_time_resolution (const char* unitp) { double VerilatedVcd::timescaleToDouble (const char* unitp) { char* endp; double value = strtod(unitp, &endp); - if (!value) value=1; // On error so we allow just "ns" to return 1e-9. + if (value==0.0 && endp==unitp) value=1; // On error so we allow just "ns" to return 1e-9. unitp=endp; while (*unitp && isspace(*unitp)) unitp++; switch (*unitp) { diff --git a/src/V3Graph.cpp b/src/V3Graph.cpp index cea5d7003..92bf1ff8c 100644 --- a/src/V3Graph.cpp +++ b/src/V3Graph.cpp @@ -121,7 +121,7 @@ uint32_t V3GraphVertex::outHash() const { ostream& operator<<(ostream& os, V3GraphVertex* vertexp) { os<<" VERTEX="<name(); if (vertexp->rank()) os<<" r"<rank(); - if (vertexp->fanout()) os<<" f"<fanout(); + if (vertexp->fanout()!=0.0) os<<" f"<fanout(); if (vertexp->color()) os<<" c"<color(); return os; } @@ -327,7 +327,7 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) { <<"\t[fontsize=8 " <<"label=\""<<(vertexp->name()!="" ? vertexp->name() : "\\N"); if (vertexp->rank()) *logp<<" r"<rank(); - if (vertexp->fanout()) *logp<<" f"<fanout(); + if (vertexp->fanout()!=0.0) *logp<<" f"<fanout(); if (vertexp->color()) *logp<<"\\n c"<color(); *logp<<"\""; *logp<<", color="<dotColor(); diff --git a/src/V3Order.cpp b/src/V3Order.cpp index 6f4ff8b1e..5217aa790 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -1015,7 +1015,8 @@ public: virtual ~OrderVisitor() { // Stats for (int type=0; type