From: Paul F. <pa...@so...> - 2025-07-17 18:41:36
|
https://sourceware.org/cgit/valgrind/commit/?id=c322bf33df88d1e8813434f7beeba909831a6a79 commit c322bf33df88d1e8813434f7beeba909831a6a79 Author: Paul Floyd <pj...@wa...> Date: Thu Jul 17 20:38:54 2025 +0200 iropt regtest: use mrand32() instead of rand() On illumos rand() has a RAND_MAX of 32k only. That's not enough to generate 64bit values easily. So use mrand48() which genrerates the full range of 32bit int values. Diff: --- none/tests/iropt-test/main.c | 2 +- none/tests/iropt-test/util.c | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/none/tests/iropt-test/main.c b/none/tests/iropt-test/main.c index 2622515e55..9f1cc5083a 100644 --- a/none/tests/iropt-test/main.c +++ b/none/tests/iropt-test/main.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) { assert(sizeof(long long) == 8); - assert(RAND_MAX == INT32_MAX); + srand48(42L); for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-v") == 0) diff --git a/none/tests/iropt-test/util.c b/none/tests/iropt-test/util.c index 072ff90c36..18b671114c 100644 --- a/none/tests/iropt-test/util.c +++ b/none/tests/iropt-test/util.c @@ -109,7 +109,7 @@ bitsof_irtype(IRType ty) uint64_t get_random_value(IRType type) { - uint64_t val = rand(); + uint64_t val = mrand48(); switch (type) { case Ity_I1: return val & 0x1; @@ -117,11 +117,8 @@ get_random_value(IRType type) case Ity_I16: return val & UINT16_MAX; case Ity_I32: return val & UINT32_MAX; case Ity_I64: - /* Note, that RAND_MAX == INT32_MAX. Therefore, simply concatenating - two rand() values would never produce a value with MSB == 1 */ - val <<= (32 + 1); - val |= rand() << 1; - val |= rand() & 0x1; + val <<= 32; + val |= mrand48(); return val; default: |