From d85b90905456870a12dd6dc63a37c64347ec4456 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 14 Sep 2022 21:10:19 -0400 Subject: [PATCH] Internals: Use std:: for mem and str functions. --- examples/make_protect_lib/sim_main.cpp | 2 +- examples/make_tracing_sc/sc_main.cpp | 2 +- src/V3Ast.cpp | 8 ++--- src/V3Ast.h | 5 +-- src/V3Begin.cpp | 2 +- src/V3EmitCModel.cpp | 2 +- src/V3EmitCSyms.cpp | 2 +- src/V3File.cpp | 10 +++--- src/V3File.h | 4 +-- src/V3FileLine.cpp | 4 +-- src/V3LinkDot.cpp | 2 +- src/V3Number.cpp | 16 +++++----- src/V3OptionParser.cpp | 8 ++--- src/V3Options.cpp | 39 ++++++++++++------------ src/V3Os.cpp | 2 +- src/V3ParseImp.cpp | 10 +++--- src/V3PreLex.l | 4 +-- src/V3PreProc.cpp | 16 +++++----- src/V3String.cpp | 4 +-- src/V3Width.cpp | 2 +- src/verilog.l | 2 +- test_regress/driver.pl | 2 +- test_regress/t/TestCheck.h | 2 +- test_regress/t/TestSimulator.h | 6 ++-- test_regress/t/t_dpi_arg_inout_type.cpp | 16 +++++----- test_regress/t/t_dpi_arg_input_type.cpp | 8 ++--- test_regress/t/t_dpi_arg_output_type.cpp | 8 ++--- test_regress/t/t_dpi_export_c.cpp | 7 +++-- test_regress/t/t_dpi_result_type.cpp | 8 ++--- test_regress/t/t_dpi_string_c.cpp | 2 +- test_regress/t/t_dpi_var.cpp | 4 +-- test_regress/t/t_sc_names.cpp | 2 +- test_regress/t/t_scope_map.cpp | 2 +- test_regress/t/t_vpi_get.cpp | 2 +- test_regress/t/t_vpi_module.cpp | 6 ++-- test_regress/t/t_vpi_param.cpp | 2 +- test_regress/t/t_vpi_unimpl.cpp | 2 +- test_regress/t/t_vpi_var.cpp | 6 ++-- 38 files changed, 118 insertions(+), 113 deletions(-) diff --git a/examples/make_protect_lib/sim_main.cpp b/examples/make_protect_lib/sim_main.cpp index b3096b4c5..fefcb0c5a 100644 --- a/examples/make_protect_lib/sim_main.cpp +++ b/examples/make_protect_lib/sim_main.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv, char** env) { // When tracing, the contents of the secret module will not be seen VerilatedVcdC* tfp = nullptr; const char* flag = contextp->commandArgsPlusMatch("trace"); - if (flag && 0 == strcmp(flag, "+trace")) { + if (flag && 0 == std::strcmp(flag, "+trace")) { contextp->traceEverOn(true); VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n"); tfp = new VerilatedVcdC; diff --git a/examples/make_tracing_sc/sc_main.cpp b/examples/make_tracing_sc/sc_main.cpp index 93861ceea..3d3cb1392 100644 --- a/examples/make_tracing_sc/sc_main.cpp +++ b/examples/make_tracing_sc/sc_main.cpp @@ -89,7 +89,7 @@ int sc_main(int argc, char* argv[]) { // and if at run time passed the +trace argument, turn on tracing VerilatedVcdSc* tfp = nullptr; const char* flag = Verilated::commandArgsPlusMatch("trace"); - if (flag && 0 == strcmp(flag, "+trace")) { + if (flag && 0 == std::strcmp(flag, "+trace")) { cout << "Enabling waves into logs/vlt_dump.vcd...\n"; tfp = new VerilatedVcdSc; top->trace(tfp, 99); // Trace 99 levels of hierarchy diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 2f1467f03..7694e1e69 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -165,22 +165,22 @@ string AstNode::prettyName(const string& namein) { continue; } if (pos[0] == '_' && pos[1] == '_') { // Short-circuit - if (0 == strncmp(pos, "__BRA__", 7)) { + if (0 == std::strncmp(pos, "__BRA__", 7)) { pretty += "["; pos += 7; continue; } - if (0 == strncmp(pos, "__KET__", 7)) { + if (0 == std::strncmp(pos, "__KET__", 7)) { pretty += "]"; pos += 7; continue; } - if (0 == strncmp(pos, "__DOT__", 7)) { + if (0 == std::strncmp(pos, "__DOT__", 7)) { pretty += "."; pos += 7; continue; } - if (0 == strncmp(pos, "__PVT__", 7)) { + if (0 == std::strncmp(pos, "__PVT__", 7)) { pretty += ""; pos += 7; continue; diff --git a/src/V3Ast.h b/src/V3Ast.h index 6e455ef1c..bb945564c 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -467,8 +467,9 @@ public: return names[m_e]; } static void selfTest() { - UASSERT(0 == strcmp(VBasicDTypeKwd(_ENUM_MAX).ascii(), " MAX"), "SelfTest: Enum mismatch"); - UASSERT(0 == strcmp(VBasicDTypeKwd(_ENUM_MAX).dpiType(), " MAX"), + UASSERT(0 == std::strcmp(VBasicDTypeKwd(_ENUM_MAX).ascii(), " MAX"), + "SelfTest: Enum mismatch"); + UASSERT(0 == std::strcmp(VBasicDTypeKwd(_ENUM_MAX).dpiType(), " MAX"), "SelfTest: Enum mismatch"); } inline VBasicDTypeKwd() diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 0e4176739..6a40e1233 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -85,7 +85,7 @@ private: string::size_type pos; while ((pos = dottedname.find("__DOT__")) != string::npos) { const string ident = dottedname.substr(0, pos); - dottedname = dottedname.substr(pos + strlen("__DOT__")); + dottedname = dottedname.substr(pos + std::strlen("__DOT__")); if (nodep->name() != "") { m_displayScope = dot(m_displayScope, ident); m_namedScope = dot(m_namedScope, ident); diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index 28687c19c..c8dc7b521 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -565,7 +565,7 @@ class EmitCModel final : public EmitCFunc { // Some hackery to locate handle__V for trace_init_task // Considered a pragma on the handle, but that still doesn't help us attach it here string handle = funcp->name(); - const size_t wr_len = strlen("__Vdpiimwrap_"); + const size_t wr_len = std::strlen("__Vdpiimwrap_"); UASSERT_OBJ(handle.substr(0, wr_len) == "__Vdpiimwrap_", funcp, "Strange trace_init_task function name"); handle = "vlSymsp->TOP." + handle.substr(wr_len); diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 5193bd7e6..2bff31190 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -211,7 +211,7 @@ class EmitCSyms final : EmitCBaseVisitor { const string::size_type dpos = whole.rfind("__DOT__"); if (dpos != string::npos) { scpName = whole.substr(0, dpos); - varBase = whole.substr(dpos + strlen("__DOT__")); + varBase = whole.substr(dpos + std::strlen("__DOT__")); } else { varBase = whole; } diff --git a/src/V3File.cpp b/src/V3File.cpp index 57452b969..c4adf58bc 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -94,7 +94,7 @@ class V3FileDependImp final { const string fn = filename(); const int err = stat(fn.c_str(), &m_stat); if (err != 0) { - memset(&m_stat, 0, sizeof(m_stat)); + std::memset(&m_stat, 0, sizeof(m_stat)); m_stat.st_mtime = 1; m_exists = false; // Not an error... This can occur due to `line directives in the .vpp files @@ -389,7 +389,7 @@ private: if (!m_pidExited && waitpid(m_pid, &m_pidStatus, hang ? 0 : WNOHANG)) { UINFO(1, "--pipe-filter: Exited, status " << m_pidStatus << " exit=" << WEXITSTATUS(m_pidStatus) << " err" - << strerror(errno) << endl); + << std::strerror(errno) << endl); m_readEof = true; m_pidExited = true; } @@ -495,7 +495,7 @@ private: constexpr int P_WR = 1; if (pipe(fd_stdin) != 0 || pipe(fd_stdout) != 0) { - v3fatal("--pipe-filter: Can't pipe: " << strerror(errno)); + v3fatal("--pipe-filter: Can't pipe: " << std::strerror(errno)); } if (fd_stdin[P_RD] <= 2 || fd_stdin[P_WR] <= 2 || fd_stdout[P_RD] <= 2 || fd_stdout[P_WR] <= 2) { @@ -507,7 +507,7 @@ private: UINFO(1, "--pipe-filter: /bin/sh -c " << command << endl); const pid_t pid = fork(); - if (pid < 0) v3fatal("--pipe-filter: fork failed: " << strerror(errno)); + if (pid < 0) v3fatal("--pipe-filter: fork failed: " << std::strerror(errno)); if (pid == 0) { // Child UINFO(6, "In child\n"); close(fd_stdin[P_WR]); @@ -518,7 +518,7 @@ private: execl("/bin/sh", "sh", "-c", command.c_str(), static_cast(nullptr)); // Don't use v3fatal, we don't share the common structures any more - fprintf(stderr, "--pipe-filter: exec failed: %s\n", strerror(errno)); + fprintf(stderr, "--pipe-filter: exec failed: %s\n", std::strerror(errno)); _exit(1); } else { // Parent UINFO(6, "In parent, child pid " << pid << " stdin " << fd_stdin[P_WR] << "->" diff --git a/src/V3File.h b/src/V3File.h index 309f136c9..95b29eb8d 100644 --- a/src/V3File.h +++ b/src/V3File.h @@ -224,7 +224,7 @@ private: std::size_t len = strlen(str); std::size_t availableBytes = WRITE_BUFFER_SIZE_BYTES - m_usedBytes; while (VL_UNLIKELY(len >= availableBytes)) { - memcpy(m_bufferp->data() + m_usedBytes, str, availableBytes); + std::memcpy(m_bufferp->data() + m_usedBytes, str, availableBytes); m_usedBytes = WRITE_BUFFER_SIZE_BYTES; writeBlock(); str += availableBytes; @@ -232,7 +232,7 @@ private: availableBytes = WRITE_BUFFER_SIZE_BYTES; } if (len > 0) { - memcpy(m_bufferp->data() + m_usedBytes, str, len); + std::memcpy(m_bufferp->data() + m_usedBytes, str, len); m_usedBytes += len; } } diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index 6b7b2e58b..0d9705c82 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -185,7 +185,7 @@ void FileLine::lineDirective(const char* textp, int& enterExitRef) { const char* const ln = textp; while (*textp && !isspace(*textp)) textp++; if (isdigit(*ln)) { - lineno(atoi(ln)); + lineno(std::atoi(ln)); } else { fail = true; } @@ -207,7 +207,7 @@ void FileLine::lineDirective(const char* textp, int& enterExitRef) { // Grab level while (*textp && (isspace(*textp) || *textp == '"')) textp++; if (isdigit(*textp)) { - enterExitRef = atoi(textp); + enterExitRef = std::atoi(textp); if (enterExitRef >= 3) fail = true; } else { enterExitRef = 0; diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 02e6b439b..493beaf4d 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -919,7 +919,7 @@ class LinkDotFindVisitor final : public VNVisitor { string::size_type pos; if ((pos = dottedname.rfind("__DOT__")) != string::npos) { const string dotted = dottedname.substr(0, pos); - const string ident = dottedname.substr(pos + strlen("__DOT__")); + const string ident = dottedname.substr(pos + std::strlen("__DOT__")); string baddot; VSymEnt* okSymp; aboveSymp = m_statep->findDotted(nodep->fileline(), aboveSymp, dotted, baddot, okSymp); diff --git a/src/V3Number.cpp b/src/V3Number.cpp index d7473cd29..81b059442 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -156,14 +156,15 @@ void V3Number::V3NumberCreate(AstNode* nodep, const char* sourcep, FileLine* fl) } value_startp = cp; - if (atoi(widthn.c_str())) { - if (atoi(widthn.c_str()) < 0 || atoi(widthn.c_str()) > v3Global.opt.maxNumWidth()) { + if (std::atoi(widthn.c_str())) { + if (std::atoi(widthn.c_str()) < 0 + || std::atoi(widthn.c_str()) > v3Global.opt.maxNumWidth()) { // atoi might convert large number to negative, so can't tell which v3error("Unsupported: Width of number exceeds implementation limit: " << sourcep << " (IEEE 1800-2017 6.9.1)"); width(v3Global.opt.maxNumWidth(), true); } else { - width(atoi(widthn.c_str()), true); + width(std::atoi(widthn.c_str()), true); } } } else { @@ -278,7 +279,8 @@ void V3Number::V3NumberCreate(AstNode* nodep, const char* sourcep, FileLine* fl) } } else { // Convert bin/octal number to hex - for (const char* cp = value_startp + strlen(value_startp) - 1; cp >= value_startp; cp--) { + for (const char* cp = value_startp + std::strlen(value_startp) - 1; cp >= value_startp; + cp--) { if (*cp != '_' && *cp != '0' && obit >= width()) { v3error("Too many digits for " << width() << " bit number: " << sourcep); break; @@ -698,7 +700,7 @@ string V3Number::displayed(FileLine* fl, const string& vformat) const { if (fmtsize != "0") str += ' '; } } - const size_t fmtsizen = static_cast(atoi(fmtsize.c_str())); + const size_t fmtsizen = static_cast(std::atoi(fmtsize.c_str())); str = displayPad(fmtsizen, ' ', left, str); return str; } @@ -747,7 +749,7 @@ string V3Number::displayed(FileLine* fl, const string& vformat) const { } const bool zeropad = fmtsize.length() > 0 && fmtsize[0] == '0'; // fmtsize might have changed since we parsed the %fmtsize - const size_t fmtsizen = static_cast(atoi(fmtsize.c_str())); + const size_t fmtsizen = static_cast(std::atoi(fmtsize.c_str())); str = displayPad(fmtsizen, (zeropad ? '0' : ' '), left, str); return str; } @@ -802,7 +804,7 @@ string V3Number::displayed(FileLine* fl, const string& vformat) const { return str; } case '@': { // Packed string - const size_t fmtsizen = static_cast(atoi(fmtsize.c_str())); + const size_t fmtsizen = static_cast(std::atoi(fmtsize.c_str())); str = displayPad(fmtsizen, ' ', left, toString()); return str; } diff --git a/src/V3OptionParser.cpp b/src/V3OptionParser.cpp index 308a26e10..8035916e7 100644 --- a/src/V3OptionParser.cpp +++ b/src/V3OptionParser.cpp @@ -130,8 +130,8 @@ V3OptionParser::ActionIfs* V3OptionParser::find(const char* optp) { for (auto&& act : m_pimpl->m_options) { if (act.second->isFOnOffAllowed()) { // Find starts with "-fno" if (const char* const nop - = VString::startsWith(optp, "-fno-") ? (optp + strlen("-fno-")) : nullptr) { - if (act.first.substr(strlen("-f"), std::string::npos) + = VString::startsWith(optp, "-fno-") ? (optp + std::strlen("-fno-")) : nullptr) { + if (act.first.substr(std::strlen("-f"), std::string::npos) == nop) { // [-f]opt = [-fno-]opt return act.second.get(); } @@ -139,7 +139,7 @@ V3OptionParser::ActionIfs* V3OptionParser::find(const char* optp) { } if (act.second->isOnOffAllowed()) { // Find starts with "-no" if (const char* const nop - = VString::startsWith(optp, "-no") ? (optp + strlen("-no")) : nullptr) { + = VString::startsWith(optp, "-no") ? (optp + std::strlen("-no")) : nullptr) { if (act.first == nop || act.first == (std::string{"-"} + nop)) { return act.second.get(); } @@ -206,7 +206,7 @@ void V3OptionParser::finalize() { m_pimpl->m_spellCheck.pushCandidate(opt.first); if (opt.second->isFOnOffAllowed()) { m_pimpl->m_spellCheck.pushCandidate( - "-fno-" + opt.first.substr(strlen("-f"), std::string::npos)); + "-fno-" + opt.first.substr(std::strlen("-f"), std::string::npos)); } if (opt.second->isOnOffAllowed()) m_pimpl->m_spellCheck.pushCandidate("-no" + opt.first); } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 474cc3e57..0580fdac4 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -908,8 +908,8 @@ void V3Options::parseOpts(FileLine* fl, int argc, char** argv) { //====================================================================== bool V3Options::suffixed(const string& sw, const char* arg) { - if (strlen(arg) > sw.length()) return false; - return (0 == strcmp(sw.c_str() + sw.length() - strlen(arg), arg)); + if (std::strlen(arg) > sw.length()) return false; + return (0 == std::strcmp(sw.c_str() + sw.length() - std::strlen(arg), arg)); } void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char** argv) { @@ -1019,15 +1019,15 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char DECL_OPTION("-comp-limit-parens", Set, &m_compLimitParens).undocumented(); DECL_OPTION("-comp-limit-syms", CbVal, [](int val) { VName::maxLength(val); }).undocumented(); DECL_OPTION("-compiler", CbVal, [this, fl](const char* valp) { - if (!strcmp(valp, "clang")) { + if (!std::strcmp(valp, "clang")) { m_compLimitBlocks = 80; // limit unknown m_compLimitMembers = 64; // soft limit, has slowdown bug as of clang++ 3.8 m_compLimitParens = 240; // controlled by -fbracket-depth, which defaults to 256 - } else if (!strcmp(valp, "gcc")) { + } else if (!std::strcmp(valp, "gcc")) { m_compLimitBlocks = 0; // Bug free m_compLimitMembers = 64; // soft limit, has slowdown bug as of g++ 7.1 m_compLimitParens = 240; // Unlimited, but generate same code as for clang - } else if (!strcmp(valp, "msvc")) { + } else if (!std::strcmp(valp, "msvc")) { m_compLimitBlocks = 80; // 128, but allow some room m_compLimitMembers = 0; // probably ok, and AFAIK doesn't support anon structs m_compLimitParens = 80; // 128, but allow some room @@ -1180,9 +1180,9 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char }); DECL_OPTION("-main", OnOff, &m_main); DECL_OPTION("-make", CbVal, [this, fl](const char* valp) { - if (!strcmp(valp, "cmake")) { + if (!std::strcmp(valp, "cmake")) { m_cmake = true; - } else if (!strcmp(valp, "gmake")) { + } else if (!std::strcmp(valp, "gmake")) { m_gmake = true; } else { fl->v3fatal("Unknown --make system specified: '" << valp << "'"); @@ -1329,13 +1329,13 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char if (m_threads < 0) fl->v3fatal("--threads must be >= 0: " << valp); }); DECL_OPTION("-threads-dpi", CbVal, [this, fl](const char* valp) { - if (!strcmp(valp, "all")) { + if (!std::strcmp(valp, "all")) { m_threadsDpiPure = true; m_threadsDpiUnpure = true; - } else if (!strcmp(valp, "none")) { + } else if (!std::strcmp(valp, "none")) { m_threadsDpiPure = false; m_threadsDpiUnpure = false; - } else if (!strcmp(valp, "pure")) { + } else if (!std::strcmp(valp, "pure")) { m_threadsDpiPure = true; m_threadsDpiUnpure = false; } else { @@ -1470,13 +1470,13 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char DECL_OPTION("-waiver-output", Set, &m_waiverOutput); DECL_OPTION("-x-assign", CbVal, [this, fl](const char* valp) { - if (!strcmp(valp, "0")) { + if (!std::strcmp(valp, "0")) { m_xAssign = "0"; - } else if (!strcmp(valp, "1")) { + } else if (!std::strcmp(valp, "1")) { m_xAssign = "1"; - } else if (!strcmp(valp, "fast")) { + } else if (!std::strcmp(valp, "fast")) { m_xAssign = "fast"; - } else if (!strcmp(valp, "unique")) { + } else if (!std::strcmp(valp, "unique")) { m_xAssign = "unique"; } else { fl->v3fatal("Unknown setting for --x-assign: '" @@ -1485,11 +1485,11 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char } }); DECL_OPTION("-x-initial", CbVal, [this, fl](const char* valp) { - if (!strcmp(valp, "0")) { + if (!std::strcmp(valp, "0")) { m_xInitial = "0"; - } else if (!strcmp(valp, "fast")) { + } else if (!std::strcmp(valp, "fast")) { m_xInitial = "fast"; - } else if (!strcmp(valp, "unique")) { + } else if (!std::strcmp(valp, "unique")) { m_xInitial = "unique"; } else { fl->v3fatal("Unknown setting for --x-initial: '" @@ -1511,11 +1511,12 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char for (int i = 0; i < argc;) { UINFO(9, " Option: " << argv[i] << endl); - if (!strcmp(argv[i], "-j") || !strcmp(argv[i], "--j")) { // Allow gnu -- switches + if (!std::strcmp(argv[i], "-j") + || !std::strcmp(argv[i], "--j")) { // Allow gnu -- switches ++i; m_buildJobs = 0; // Unlimited parallelism if (i < argc && isdigit(argv[i][0])) { - m_buildJobs = atoi(argv[i]); + m_buildJobs = std::atoi(argv[i]); if (m_buildJobs <= 0) { fl->v3error("-j accepts positive integer, but '" << argv[i] << "' is passed"); } diff --git a/src/V3Os.cpp b/src/V3Os.cpp index c410c6735..2abc200c0 100644 --- a/src/V3Os.cpp +++ b/src/V3Os.cpp @@ -347,7 +347,7 @@ int V3Os::system(const string& command) { const int ret = ::system(command.c_str()); if (VL_UNCOVERABLE(ret == -1)) { v3fatal("Failed to execute command:" // LCOV_EXCL_LINE - << command << " " << strerror(errno)); + << command << " " << std::strerror(errno)); return -1; // LCOV_EXCL_LINE } else { UASSERT(WIFEXITED(ret), "system(" << command << ") returned unexpected value of " << ret); diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 8a1481323..1d2832ce5 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -150,8 +150,8 @@ void V3ParseImp::lexVerilatorCmtLint(FileLine* fl, const char* textp, bool warnO void V3ParseImp::lexVerilatorCmtBad(FileLine* fl, const char* textp) { string cmtparse = textp; - if (cmtparse.substr(0, strlen("/*verilator")) == "/*verilator") { - cmtparse.replace(0, strlen("/*verilator"), ""); + if (cmtparse.substr(0, std::strlen("/*verilator")) == "/*verilator") { + cmtparse.replace(0, std::strlen("/*verilator"), ""); } while (isspace(cmtparse[0])) cmtparse.replace(0, 1, ""); string cmtname; @@ -178,14 +178,14 @@ void V3ParseImp::lexErrorPreprocDirective(FileLine* fl, const char* textp) { } string V3ParseImp::lexParseTag(const char* textp) { - string tmp = textp + strlen("/*verilator tag "); + string tmp = textp + std::strlen("/*verilator tag "); string::size_type pos; if ((pos = tmp.rfind("*/")) != string::npos) tmp.erase(pos); return tmp; } double V3ParseImp::lexParseTimenum(const char* textp) { - const size_t length = strlen(textp); + const size_t length = std::strlen(textp); char* const strgp = new char[length + 1]; char* dp = strgp; const char* sp = textp; @@ -234,7 +234,7 @@ size_t V3ParseImp::ppInputToLex(char* buf, size_t max_size) { m_ppBuffers.push_front(remainder); // Put back remainder for next time len = (max_size - got); } - memcpy(buf + got, front.c_str(), len); + std::memcpy(buf + got, front.c_str(), len); got += len; } if (debug() >= 9) { diff --git a/src/V3PreLex.l b/src/V3PreLex.l index bfe69e7c7..a83a55db9 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -126,7 +126,7 @@ bom [\357\273\277] if (LEXP->m_protBytes > 0) { LEXP->curFilelinep()->v3warn(BADSTDPRAGMA, "multiple `pragma protected encoding sections"); } - res = sscanf(yytext + strlen("encoding"), " = (enctype = \"%15[A-Za-z0-9]\", line_length = %d, bytes = %d)", &enctype[0], &LEXP->m_protLength, &LEXP->m_protBytes); + res = sscanf(yytext + std::strlen("encoding"), " = (enctype = \"%15[A-Za-z0-9]\", line_length = %d, bytes = %d)", &enctype[0], &LEXP->m_protLength, &LEXP->m_protBytes); if (res == 0) LEXP->curFilelinep()->v3warn(BADSTDPRAGMA, "`pragma protected encoding must have an \"enctype\" field"); LEXP->m_encType = !VL_STRCASECMP(enctype, "uuencode") ? Enctype::UUENCODE : @@ -242,7 +242,7 @@ bom [\357\273\277] "`__LINE__" { FL_FWDC; static char buf[25]; VL_SNPRINTF(buf, 25, "%d", LEXP->curFilelinep()->lastLineno()); - yytext = buf; yyleng = strlen(yytext); + yytext = buf; yyleng = std::strlen(yytext); return VP_TEXT; } /* Pass-through strings */ diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 59ba4398b..0cf66dc24 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -395,7 +395,7 @@ string V3PreProcImp::commentCleanup(const string& text) { } bool V3PreProcImp::commentTokenMatch(string& cmdr, const char* strg) { - int len = strlen(strg); + int len = std::strlen(strg); if (VString::startsWith(cmdr, strg) && (cmdr[len] == '\0' || isspace(cmdr[len]))) { if (isspace(cmdr[len])) len++; cmdr = cmdr.substr(len); @@ -425,27 +425,27 @@ void V3PreProcImp::comment(const string& text) { bool synth = false; bool vlcomment = false; if ((cp[0] == 'v' || cp[0] == 'V') && VString::startsWith(cp + 1, "erilator")) { - cp += strlen("verilator"); + cp += std::strlen("verilator"); if (*cp == '_') { fileline()->v3error("Extra underscore in meta-comment;" " use /*verilator {...}*/ not /*verilator_{...}*/"); } vlcomment = true; } else if (VString::startsWith(cp, "synopsys")) { - cp += strlen("synopsys"); + cp += std::strlen("synopsys"); synth = true; if (*cp == '_') { fileline()->v3error("Extra underscore in meta-comment;" " use /*synopsys {...}*/ not /*synopsys_{...}*/"); } } else if (VString::startsWith(cp, "cadence")) { - cp += strlen("cadence"); + cp += std::strlen("cadence"); synth = true; } else if (VString::startsWith(cp, "pragma")) { - cp += strlen("pragma"); + cp += std::strlen("pragma"); synth = true; } else if (VString::startsWith(cp, "ambit synthesis")) { - cp += strlen("ambit synthesis"); + cp += std::strlen("ambit synthesis"); synth = true; } else { return; @@ -478,7 +478,7 @@ void V3PreProcImp::comment(const string& text) { string::size_type pos; if ((pos = cmd.find("public_flat_rw")) != string::npos) { // "/*verilator public_flat_rw @(foo) */" -> "/*verilator public_flat_rw*/ @(foo)" - cmd = cmd.substr(pos + strlen("public_flat_rw")); + cmd = cmd.substr(pos + std::strlen("public_flat_rw")); while (isspace(cmd[0])) cmd = cmd.substr(1); if (!printed) insertUnreadback("/*verilator public_flat_rw*/ " + cmd + " /**/"); } else { @@ -1593,7 +1593,7 @@ string V3PreProcImp::getline() { if (isEof()) return ""; const char* rtnp; bool gotEof = false; - while (nullptr == (rtnp = strchr(m_lineChars.c_str(), '\n')) && !gotEof) { + while (nullptr == (rtnp = std::strchr(m_lineChars.c_str(), '\n')) && !gotEof) { string buf; const int tok = getFinalToken(buf /*ref*/); if (debug() >= 5) { diff --git a/src/V3String.cpp b/src/V3String.cpp index 9d20bd078..1a42ee2e7 100644 --- a/src/V3String.cpp +++ b/src/V3String.cpp @@ -150,7 +150,7 @@ double VString::parseDouble(const string& str, bool* successp) { char* endp = strgp; const double d = strtod(strgp, &endp); const size_t parsed_len = endp - strgp; - if (parsed_len != strlen(strgp)) { + if (parsed_len != std::strlen(strgp)) { if (successp) *successp = false; } VL_DO_DANGLING(delete[] strgp, strgp); @@ -402,7 +402,7 @@ void VHashSha256::selfTest() { string VName::dehash(const string& in) { static const char VHSH[] = "__Vhsh"; - static const size_t DOT_LEN = strlen("__DOT__"); + static const size_t DOT_LEN = std::strlen("__DOT__"); std::string dehashed; // Need to split 'in' into components separated by __DOT__, 'last_dot_pos' diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 081fc526e..a784b3024 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5963,7 +5963,7 @@ private: } if ((VN_IS(nodep, Add) && underp->width() == 1 && underp->isOne()) || (VN_IS(nodep, Sub) && underp->width() == 1 && underp->isOne() - && 0 == strcmp(side, "RHS"))) { + && 0 == std::strcmp(side, "RHS"))) { // "foo + 1'b1", or "foo - 1'b1" are very common, people assume // they extend correctly warnOn = false; diff --git a/src/verilog.l b/src/verilog.l index a3cc59ef6..46f612ef4 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -1004,7 +1004,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} return yaT_RESETALL; } // Rest handled by preproc "`suppress_faults" { FL_FWD; FL_BRK; } // Verilog-XL compatibility "`timescale"{ws}+[^\n\r]* { FL; PARSEP->lexTimescaleParse(yylval.fl, - yytext + strlen("`timescale")); + yytext + std::strlen("`timescale")); FL_BRK; } "`unconnected_drive"{ws}+"pull0" { FL; return yaT_UNCONNECTED_PULL0; } "`unconnected_drive"{ws}+"pull1" { FL; return yaT_UNCONNECTED_PULL1; } diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 22a2a67f8..fe0bd9498 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -1845,7 +1845,7 @@ sub _make_main { if ($self->{savable}) { $fh->print(" const char* save_time_strp = contextp->commandArgsPlusMatch(\"save_time=\");\n"); - $fh->print(" unsigned int save_time = !save_time_strp[0] ? 0 : atoi(save_time_strp+strlen(\"+save_time=\"));\n"); + $fh->print(" unsigned int save_time = !save_time_strp[0] ? 0 : std::atoi(save_time_strp + std::strlen(\"+save_time=\"));\n"); $fh->print(" const char* save_restore_strp = contextp->commandArgsPlusMatch(\"save_restore=\");\n"); $fh->print(" unsigned int save_restore = !save_restore_strp[0] ? 0 : 1;\n"); } diff --git a/test_regress/t/TestCheck.h b/test_regress/t/TestCheck.h index ac42dde3b..2f8cf2283 100644 --- a/test_regress/t/TestCheck.h +++ b/test_regress/t/TestCheck.h @@ -34,7 +34,7 @@ static const bool verbose = false; #define TEST_CHECK_EQ(got, exp) TEST_CHECK(got, exp, ((got) == (exp))); #define TEST_CHECK_NE(got, exp) TEST_CHECK(got, exp, ((got) != (exp))); -#define TEST_CHECK_CSTR(got, exp) TEST_CHECK(got, exp, 0 == strcmp((got), (exp))); +#define TEST_CHECK_CSTR(got, exp) TEST_CHECK(got, exp, 0 == std::strcmp((got), (exp))); #define TEST_CHECK_HEX_EQ(got, exp) \ do { \ diff --git a/test_regress/t/TestSimulator.h b/test_regress/t/TestSimulator.h index 6272887d8..c25304f6e 100644 --- a/test_regress/t/TestSimulator.h +++ b/test_regress/t/TestSimulator.h @@ -28,13 +28,13 @@ private: public: TestSimulator() { vpi_get_vlog_info(&m_info); - if (0 == strcmp(m_info.product, "Verilator")) { + if (0 == std::strcmp(m_info.product, "Verilator")) { m_simulators.verilator = true; - } else if (0 == strcmp(m_info.product, "Verilator")) { + } else if (0 == std::strcmp(m_info.product, "Verilator")) { m_simulators.icarus = true; } else if (0 == strncmp(m_info.product, "Chronologic Simulation VCS", - strlen("Chronologic Simulation VCS"))) { + std::strlen("Chronologic Simulation VCS"))) { m_simulators.vcs = true; } else { printf("%%Warning: %s:%d: Unknown simulator in TestSimulator.h: %s\n", __FILE__, diff --git a/test_regress/t/t_dpi_arg_inout_type.cpp b/test_regress/t/t_dpi_arg_inout_type.cpp index a5c346d8f..f5b109b39 100644 --- a/test_regress/t/t_dpi_arg_inout_type.cpp +++ b/test_regress/t/t_dpi_arg_inout_type.cpp @@ -168,10 +168,10 @@ void i_string(const char** x) { static int n = 0; printf("i_string %d\n", n); if (n++ % 2 == 0) { - if (strcmp(*x, "Hello") != 0) stop(); + if (std::strcmp(*x, "Hello") != 0) stop(); *x = "Good"; } else { - if (strcmp(*x, "World") != 0) stop(); + if (std::strcmp(*x, "World") != 0) stop(); *x = "Bye"; } } @@ -296,10 +296,10 @@ void i_string_t(const char** x) { static int n = 0; printf("i_string_t %d\n", n); if (n++ % 2 == 0) { - if (strcmp(*x, "World") != 0) stop(); + if (std::strcmp(*x, "World") != 0) stop(); *x = "Bye"; } else { - if (strcmp(*x, "Hello") != 0) stop(); + if (std::strcmp(*x, "Hello") != 0) stop(); *x = "Good"; } } @@ -962,10 +962,10 @@ void check_exports() { e_string(&x_string); if ((n % 2) == 0) { if (x_chandle) stop(); - if (strcmp(x_string, "Hello") != 0) stop(); + if (std::strcmp(x_string, "Hello") != 0) stop(); } else { if (x_chandle) stop(); - if (strcmp(x_string, "World") != 0) stop(); + if (std::strcmp(x_string, "World") != 0) stop(); } x_bit = n % 2; @@ -1045,10 +1045,10 @@ void check_exports() { e_string_t(&x_string_t); if ((n % 2) == 0) { if (x_chandle_t != NULL) stop(); - if (strcmp(x_string_t, "World") != 0) stop(); + if (std::strcmp(x_string_t, "World") != 0) stop(); } else { if (x_chandle_t != NULL) stop(); - if (strcmp(x_string_t, "Hello") != 0) stop(); + if (std::strcmp(x_string_t, "Hello") != 0) stop(); } x_bit_t = n % 2; diff --git a/test_regress/t/t_dpi_arg_input_type.cpp b/test_regress/t/t_dpi_arg_input_type.cpp index 1593e1dfc..ee7f56d79 100644 --- a/test_regress/t/t_dpi_arg_input_type.cpp +++ b/test_regress/t/t_dpi_arg_input_type.cpp @@ -155,9 +155,9 @@ void i_string(const char* i) { static int n = 0; printf("i_string %d\n", n); if (n++ % 2 == 0) { - if (strcmp(i, "World") != 0) stop(); + if (std::strcmp(i, "World") != 0) stop(); } else { - if (strcmp(i, "Hello") != 0) stop(); + if (std::strcmp(i, "Hello") != 0) stop(); } } @@ -266,9 +266,9 @@ void i_string_t(const char* i) { static int n = 0; printf("i_string_t %d\n", n); if (n++ % 2 == 0) { - if (strcmp(i, "World") != 0) stop(); + if (std::strcmp(i, "World") != 0) stop(); } else { - if (strcmp(i, "Hello") != 0) stop(); + if (std::strcmp(i, "Hello") != 0) stop(); } } diff --git a/test_regress/t/t_dpi_arg_output_type.cpp b/test_regress/t/t_dpi_arg_output_type.cpp index cf127ee6e..b8eda4a74 100644 --- a/test_regress/t/t_dpi_arg_output_type.cpp +++ b/test_regress/t/t_dpi_arg_output_type.cpp @@ -711,9 +711,9 @@ void check_exports() { e_string(&x_string); if ((n % 2) == 0) { - if (strcmp(x_string, "Hello") != 0) stop(); + if (std::strcmp(x_string, "Hello") != 0) stop(); } else { - if (strcmp(x_string, "World") != 0) stop(); + if (std::strcmp(x_string, "World") != 0) stop(); } e_bit(&x_bit); @@ -772,9 +772,9 @@ void check_exports() { e_string_t(&x_string_t); if ((n % 2) == 0) { - if (strcmp(x_string_t, "Hello") != 0) stop(); + if (std::strcmp(x_string_t, "Hello") != 0) stop(); } else { - if (strcmp(x_string_t, "World") != 0) stop(); + if (std::strcmp(x_string_t, "World") != 0) stop(); } e_bit_t(&x_bit_t); diff --git a/test_regress/t/t_dpi_export_c.cpp b/test_regress/t/t_dpi_export_c.cpp index da9fee221..8b60a1c66 100644 --- a/test_regress/t/t_dpi_export_c.cpp +++ b/test_regress/t/t_dpi_export_c.cpp @@ -115,9 +115,10 @@ int dpix_run_tests() { #ifndef CADENCE // Unimplemented; how hard is it? printf("svDpiVersion: %s\n", svDpiVersion()); - CHECK_RESULT( - bool, - strcmp(svDpiVersion(), "1800-2005") == 0 || strcmp(svDpiVersion(), "P1800-2005") == 0, 1); + CHECK_RESULT(bool, + std::strcmp(svDpiVersion(), "1800-2005") == 0 + || std::strcmp(svDpiVersion(), "P1800-2005") == 0, + 1); #endif CHECK_RESULT(int, dpix_int123(), 0x123); diff --git a/test_regress/t/t_dpi_result_type.cpp b/test_regress/t/t_dpi_result_type.cpp index a0d7b3cb5..bc8314a15 100644 --- a/test_regress/t/t_dpi_result_type.cpp +++ b/test_regress/t/t_dpi_result_type.cpp @@ -303,9 +303,9 @@ void check_exports() { #endif if (e_chandle()) stop(); if ((n % 2) == 0) { - if (strcmp(e_string(), "Hello") != 0) stop(); + if (std::strcmp(e_string(), "Hello") != 0) stop(); } else { - if (strcmp(e_string(), "World") != 0) stop(); + if (std::strcmp(e_string(), "World") != 0) stop(); } if (e_bit() != (n % 2)) stop(); if (e_logic() != !(n % 2)) stop(); @@ -327,9 +327,9 @@ void check_exports() { #endif if (e_chandle_t()) stop(); if ((n % 2) == 0) { - if (strcmp(e_string_t(), "Hello") != 0) stop(); + if (std::strcmp(e_string_t(), "Hello") != 0) stop(); } else { - if (strcmp(e_string_t(), "World") != 0) stop(); + if (std::strcmp(e_string_t(), "World") != 0) stop(); } if (e_bit_t() != (n % 2)) stop(); if (e_logic_t() != !(n % 2)) stop(); diff --git a/test_regress/t/t_dpi_string_c.cpp b/test_regress/t/t_dpi_string_c.cpp index 05b001886..9216d9316 100644 --- a/test_regress/t/t_dpi_string_c.cpp +++ b/test_regress/t/t_dpi_string_c.cpp @@ -39,5 +39,5 @@ extern int dpii_string(const char* s); int dpii_string(const char* s) { printf("dpii_string: %s\n", s); - return strlen(s); + return std::strlen(s); } diff --git a/test_regress/t/t_dpi_var.cpp b/test_regress/t/t_dpi_var.cpp index f35647d41..5f9ee79f1 100644 --- a/test_regress/t/t_dpi_var.cpp +++ b/test_regress/t/t_dpi_var.cpp @@ -60,9 +60,9 @@ void mon_scope_name(const char* namep) { #ifdef TEST_VERBOSE VL_PRINTF("- mon_scope_name('%s', \"%s\");\n", modp, namep); #endif - if (strcmp(namep, "t.sub")) + if (std::strcmp(namep, "t.sub")) vl_fatal(__FILE__, __LINE__, "", (std::string{"Unexp scope name "} + namep).c_str()); - if (strcmp(modp, "t.sub")) + if (std::strcmp(modp, "t.sub")) vl_fatal(__FILE__, __LINE__, "", (std::string{"Unexp dpiscope name "} + modp).c_str()); } diff --git a/test_regress/t/t_sc_names.cpp b/test_regress/t/t_sc_names.cpp index 6839252b0..6f73c4c1d 100644 --- a/test_regress/t/t_sc_names.cpp +++ b/test_regress/t/t_sc_names.cpp @@ -15,7 +15,7 @@ int sc_main(int argc, char* argv[]) { /* We expect to find clk in here. */ for (int i = 0; i < ch.size(); ++i) { - if (!strcmp(ch[i]->basename(), "clk")) found = true; + if (!std::strcmp(ch[i]->basename(), "clk")) found = true; } if (found) { diff --git a/test_regress/t/t_scope_map.cpp b/test_regress/t/t_scope_map.cpp index 9136c8ee3..d9f554d8b 100644 --- a/test_regress/t/t_scope_map.cpp +++ b/test_regress/t/t_scope_map.cpp @@ -100,7 +100,7 @@ int main(int argc, char** argv, char** env) { #endif // Clear out the data - memset(varData, 0, (varBits + 7) / 8); + std::memset(varData, 0, (varBits + 7) / 8); } } diff --git a/test_regress/t/t_vpi_get.cpp b/test_regress/t/t_vpi_get.cpp index fdd93ee01..898664841 100644 --- a/test_regress/t/t_vpi_get.cpp +++ b/test_regress/t/t_vpi_get.cpp @@ -71,7 +71,7 @@ } #define CHECK_RESULT_CSTR(got, exp) \ - if (strcmp((got), (exp))) { \ + if (std::strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ (got) ? (got) : "", (exp) ? (exp) : ""); \ return __LINE__; \ diff --git a/test_regress/t/t_vpi_module.cpp b/test_regress/t/t_vpi_module.cpp index 754cc2660..1c2de048c 100644 --- a/test_regress/t/t_vpi_module.cpp +++ b/test_regress/t/t_vpi_module.cpp @@ -61,7 +61,7 @@ } #define CHECK_RESULT_CSTR(got, exp) \ - if (strcmp((got), (exp))) { \ + if (std::strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ (got) ? (got) : "", (exp) ? (exp) : ""); \ return __LINE__; \ @@ -100,7 +100,7 @@ int mon_check() { CHECK_RESULT_NZ(t_name); // Icarus reports the top most module as "top" - if (strcmp(t_name, "top") == 0) { + if (std::strcmp(t_name, "top") == 0) { it = vpi_iterate(vpiModule, topmod); CHECK_RESULT_NZ(it); CHECK_RESULT(vpi_get(vpiType, it), vpiModule); @@ -129,7 +129,7 @@ int mon_check() { CHECK_RESULT_NZ(mod3); const char* mod_c_name = vpi_get_str(vpiName, mod3); - if (strcmp(mod_c_name, "mod_b") == 0) { + if (std::strcmp(mod_c_name, "mod_b") == 0) { // Full visibility in other simulators, skip mod_b TestVpiHandle mod4 = vpi_scan(it3); CHECK_RESULT_NZ(mod4); diff --git a/test_regress/t/t_vpi_param.cpp b/test_regress/t/t_vpi_param.cpp index 51415a38b..dcc4a7fb9 100644 --- a/test_regress/t/t_vpi_param.cpp +++ b/test_regress/t/t_vpi_param.cpp @@ -71,7 +71,7 @@ } #define CHECK_RESULT_CSTR(got, exp) \ - if (strcmp((got), (exp))) { \ + if (std::strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ (got) ? (got) : "", (exp) ? (exp) : ""); \ return __LINE__; \ diff --git a/test_regress/t/t_vpi_unimpl.cpp b/test_regress/t/t_vpi_unimpl.cpp index 549d66e1e..e91515a6e 100644 --- a/test_regress/t/t_vpi_unimpl.cpp +++ b/test_regress/t/t_vpi_unimpl.cpp @@ -66,7 +66,7 @@ unsigned int callback_count = 0; } #define CHECK_RESULT_CSTR(got, exp) \ - if (strcmp((got), (exp))) { \ + if (std::strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ (got) ? (got) : "", (exp) ? (exp) : ""); \ return __LINE__; \ diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index b8186c281..1c5c76f50 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -90,7 +90,7 @@ bool verbose = false; } #define CHECK_RESULT_CSTR(got, exp) \ - if (strcmp((got), (exp))) { \ + if (std::strcmp((got), (exp))) { \ printf("%%Error: %s:%d: GOT = '%s' EXP = '%s'\n", FILENM, __LINE__, \ ((got) != NULL) ? (got) : "", ((exp) != NULL) ? (exp) : ""); \ return __LINE__; \ @@ -117,7 +117,7 @@ int _mon_check_mcd() { } status = vpi_mcd_printf(mcd, (PLI_BYTE8*)"hello %s", "vpi_mcd_printf"); - CHECK_RESULT(status, strlen("hello vpi_mcd_printf")); + CHECK_RESULT(status, std::strlen("hello vpi_mcd_printf")); status = vpi_mcd_printf(0, (PLI_BYTE8*)"empty"); CHECK_RESULT(status, 0); @@ -634,7 +634,7 @@ int _mon_check_vlog_info() { CHECK_RESULT_Z(vlog_info.argv[4]); if (TestSimulator::is_verilator()) { CHECK_RESULT_CSTR(vlog_info.product, "Verilator"); - CHECK_RESULT(strlen(vlog_info.version) > 0, 1); + CHECK_RESULT(std::strlen(vlog_info.version) > 0, 1); } return 0; }