Fix misoptimizing away `$urandom` (#5703).

This commit is contained in:
Wilson Snyder 2025-01-11 08:48:40 -05:00
parent bb871728c9
commit dfe28f7ed0
3 changed files with 28 additions and 2 deletions

View File

@ -23,6 +23,7 @@ Verilator 5.033 devel
* Fix pattern assignment to real inside struct (#5713).
* Fix %p format output for real inside struct (#5713).
* Fix segfault when only enum value referenced in package (#5714). [Dan Katz]
* Fix misoptimizing away `$urandom` (#5703). [Parker Schless]
* Fix matching language extension options including dots.

View File

@ -1820,7 +1820,6 @@ public:
return "VL_RANDOM_SEEDED_%nq%lq(%li)";
}
}
if (isWide()) {
return "VL_RANDOM_%nq(%nw, %P)";
} else {
@ -1830,6 +1829,7 @@ public:
bool cleanOut() const override { return false; }
bool isGateOptimizable() const override { return false; }
bool isPredictOptimizable() const override { return false; }
bool isPure() override { return !m_reset && !seedp(); }
int instrCount() const override { return INSTR_COUNT_PLI; }
bool sameNode(const AstNode* /*samep*/) const override { return true; }
bool combinable(const AstRand* samep) const {

View File

@ -12,6 +12,9 @@ module t;
int valuea;
int valueb;
int valuec;
int igna;
int ignb;
int ignc;
initial begin
// $random unlike $urandom updates the value if given
@ -32,7 +35,29 @@ module t;
valuea = $urandom(10);
valueb = $urandom(10);
if (valuea !== valueb) $stop;
valuec = $urandom(10);
if (valuea !== valueb && valueb != valuec) $stop;
valuea = $urandom(10);
valueb = $urandom(11);
valuec = $urandom(12);
if (valuea == valueb && valueb == valuec) $stop; // May false fail 1 in 1^64
$urandom(10);
valuea = $urandom;
$urandom(10);
valueb = $urandom;
$urandom(10);
valuec = $urandom;
if (valuea != valueb && valueb != valuec) $stop; // May false fail 1 in 1^64
igna = $urandom(10);
valuea = $urandom;
ignb = $urandom(10);
valueb = $urandom;
ignc = $urandom(10);
valuec = $urandom;
if (valuea != valueb && valueb != valuec) $stop; // May false fail 1 in 1^64
valuea = $urandom(10);
valueb = $urandom();