From fa62cd34863fe9fe91e833aebe3289a9c9677904 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 25 Jul 2025 07:23:02 -0400 Subject: [PATCH] Fix `--stats` overridden by skipping identical build (#6220). --- Changes | 1 + src/Verilator.cpp | 12 ++++++---- test_regress/t/t_flag_skipidentical.py | 32 ++++++++++++++++---------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Changes b/Changes index b857da768..b1d19faac 100644 --- a/Changes +++ b/Changes @@ -45,6 +45,7 @@ Verilator 5.039 devel * Fix VPI signal range order (#6189) (#6200). [Ibrahim Burak Yorulmaz] * Fix structure select causing 'Wide Op' error (#6191). [Danny Oler] * Fix 'driver same component' assertion (#6211) (#6215). [Geza Lore] +* Fix `--stats` overridden by skipping identical build (#6220). [Geza Lore] Verilator 5.038 2025-07-08 diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 3ef409ebc..2e1be9ac0 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -651,7 +651,8 @@ static void process() { if (v3Global.opt.stats()) V3Stats::statsStage("emit"); } -static void verilate(const string& argString) { +static bool verilate(const string& argString) { + // Run verilation, and return false if skipped UINFO(1, "Option --verilate: Start Verilation"); // Can we skip doing everything if times are ok? @@ -661,7 +662,7 @@ static void verilate(const string& argString) { + "__verFiles.dat", argString)) { UINFO(1, "--skip-identical: No change to any source files, exiting"); - return; + return false; } // Undocumented debugging - cannot be a switch as then command line // would mismatch forcing non-identicalness when we set it @@ -775,10 +776,12 @@ static void verilate(const string& argString) { V3Error::abortIfWarnings(); // Free memory so compiler has more for --build + // No need to do this if skipped (above) as didn't alloc much UINFO(1, "Releasing netlist memory"); v3Global.rootp()->deleteContents(); V3Os::releaseMemory(); if (v3Global.opt.stats()) V3Stats::statsStage("released"); + return true; } static string buildMakeCmd(const string& makefile, const string& target) { @@ -862,8 +865,9 @@ int main(int argc, char** argv) { V3Error::abortIfErrors(); + bool didVerilate = false; if (v3Global.opt.verilate()) { - verilate(argString); + didVerilate = verilate(argString); } else { UINFO(1, "Option --no-verilate: Skip Verilation"); } @@ -874,7 +878,7 @@ int main(int argc, char** argv) { execBuildJob(); } - reportStatsIfEnabled(); + if (didVerilate) reportStatsIfEnabled(); V3DiagSarif::output(true); // Explicitly release resources diff --git a/test_regress/t/t_flag_skipidentical.py b/test_regress/t/t_flag_skipidentical.py index 5b20bd00b..c69949f33 100755 --- a/test_regress/t/t_flag_skipidentical.py +++ b/test_regress/t/t_flag_skipidentical.py @@ -10,27 +10,35 @@ import vltest_bootstrap import time +FileTimes = {} + + +def prep_output_file(filename): + oldstats = os.path.getmtime(filename) + if not oldstats: + test.error("No output file found: " + filename) + print("Old %s mtime=%d" % (filename, oldstats)) + FileTimes[filename] = oldstats + + test.scenarios('vlt') -test.compile() +test.compile(verilator_flags2=['--stats']) print("NOTE: use --debugi, as --debug in driver turns off skip-identical") -outfile = test.obj_dir + "/V" + test.name + ".cpp" -oldstats = os.path.getmtime(outfile) -if not oldstats: - test.error("No output file found: " + outfile) -print("Old mtime=", oldstats) +prep_output_file(test.obj_dir + "/V" + test.name + ".cpp") +prep_output_file(test.obj_dir + "/V" + test.name + "__stats.txt") time.sleep(2) # Or else it might take < 1 second to compile and see no diff. test.setenv('VERILATOR_DEBUG_SKIP_IDENTICAL', "1") -test.compile() +test.compile(verilator_flags2=['--stats']) -newstats = os.path.getmtime(outfile) -print("New mtime=", newstats) - -if oldstats != newstats: - test.error("--skip-identical was ignored -- recompiled") +for filename, oldtime in FileTimes.items(): + newstats = os.path.getmtime(filename) + print("New %s mtime=%d" % (filename, newstats)) + if oldtime != newstats: + test.error("--skip-identical was ignored -- regenerated %s" % (filename)) test.passes()