From d64971ba3524c6ee620f644cca39f7b8aac312df Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 22 Dec 2022 12:19:09 -0500 Subject: [PATCH] Fix some MSVC warnings. --- include/verilated.cpp | 8 ++++---- include/verilated_funcs.h | 2 +- include/verilated_vcd_c.cpp | 2 +- src/V3Error.h | 14 ++++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index 334e95d08..f1f477483 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -1383,7 +1383,7 @@ static IData getLine(std::string& str, IData fpi, size_t maxLen) VL_MT_SAFE { str.push_back(c); if (c == '\n') break; } - return str.size(); + return static_cast(str.size()); } IData VL_FGETS_IXI(int obits, void* destp, IData fpi) VL_MT_SAFE { @@ -1633,12 +1633,12 @@ std::string VL_STACKTRACE_N() VL_MT_SAFE { static VerilatedMutex s_stackTraceMutex; const VerilatedLockGuard lock{s_stackTraceMutex}; - constexpr int BT_BUF_SIZE = 100; - void* buffer[BT_BUF_SIZE]; int nptrs = 0; char** strings = nullptr; #ifdef _VL_HAVE_STACKTRACE + constexpr int BT_BUF_SIZE = 100; + void* buffer[BT_BUF_SIZE]; nptrs = backtrace(buffer, BT_BUF_SIZE); strings = backtrace_symbols(buffer, nptrs); #endif @@ -2569,7 +2569,7 @@ std::pair VerilatedContextImp::argc_argv() VL_MT_SAFE_EXCLUDES(m_ar static char** s_argvp = nullptr; if (VL_UNLIKELY(!s_loaded)) { s_loaded = true; - s_argc = m_args.m_argVec.size(); + s_argc = static_cast(m_args.m_argVec.size()); s_argvp = new char*[s_argc + 1]; int in = 0; for (const auto& i : m_args.m_argVec) { diff --git a/include/verilated_funcs.h b/include/verilated_funcs.h index 1e188e30d..57d76ab9a 100644 --- a/include/verilated_funcs.h +++ b/include/verilated_funcs.h @@ -2208,7 +2208,7 @@ inline std::string VL_REPLICATEN_NNI(const std::string& lhs, IData rep) VL_PURE return VL_REPLICATEN_NNQ(lhs, rep); } -inline IData VL_LEN_IN(const std::string& ld) { return ld.length(); } +inline IData VL_LEN_IN(const std::string& ld) { return static_cast(ld.length()); } extern std::string VL_TOLOWER_NN(const std::string& ld) VL_PURE; extern std::string VL_TOUPPER_NN(const std::string& ld) VL_PURE; diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index e65b0380f..df95de814 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -527,7 +527,7 @@ void VerilatedVcd::declare(uint32_t code, const char* name, const char* wirep, b std::strlen(buf)); // Code (overwrite separator if isBit) entryp[length + !isBit] = '\n'; // Replace '\0' with line termination '\n' // Set length of suffix (used to increment write pointer) - entryp[VL_TRACE_SUFFIX_ENTRY_SIZE - 1] = !isBit + length + 1; + entryp[VL_TRACE_SUFFIX_ENTRY_SIZE - 1] = static_cast(length + !isBit + 1); decl += " "; decl += basename; if (array) { diff --git a/src/V3Error.h b/src/V3Error.h index 63fb4828d..71c173c7b 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -431,11 +431,12 @@ inline void v3errorEndFatal(std::ostringstream& sstr) { return value // Helper macros for VL_DEFINE_DEBUG_FUNCTIONS -#define VL_DEFINE_DEBUG(name) \ - VL_ATTR_UNUSED static int debug##name() { \ +// Takes an optional "name" (as __VA_ARGS__) +#define VL_DEFINE_DEBUG(...) \ + VL_ATTR_UNUSED static int debug##__VA_ARGS__() { \ static int level = -1; \ if (VL_UNLIKELY(level < 0)) { \ - std::string tag{VL_STRINGIFY(name)}; \ + std::string tag{VL_STRINGIFY(__VA_ARGS__)}; \ tag[0] = std::tolower(tag[0]); \ const unsigned debugTag = v3Global.opt.debugLevel(tag); \ const unsigned debugSrc = v3Global.opt.debugSrcLevel(__FILE__); \ @@ -447,11 +448,12 @@ inline void v3errorEndFatal(std::ostringstream& sstr) { } \ static_assert(true, "") -#define VL_DEFINE_DUMP(name) \ - VL_ATTR_UNUSED static int dump##name() { \ +// Takes an optional "name" (as __VA_ARGS__) +#define VL_DEFINE_DUMP(...) \ + VL_ATTR_UNUSED static int dump##__VA_ARGS__() { \ static int level = -1; \ if (VL_UNLIKELY(level < 0)) { \ - std::string tag{VL_STRINGIFY(name)}; \ + std::string tag{VL_STRINGIFY(__VA_ARGS__)}; \ tag[0] = std::tolower(tag[0]); \ const unsigned dumpTag = v3Global.opt.dumpLevel(tag); \ const unsigned dumpSrc = v3Global.opt.dumpSrcLevel(__FILE__); \