]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
iropt regtest: use mrand32() instead of rand()
authorPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 17 Jul 2025 18:38:54 +0000 (20:38 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 17 Jul 2025 18:38:54 +0000 (20:38 +0200)
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.

none/tests/iropt-test/main.c
none/tests/iropt-test/util.c

index 2622515e5550e04a4e7663c0c47c9833b8f5832b..9f1cc5083af0055e05d4aef8660cdf470d3821e7 100644 (file)
@@ -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)
index 072ff90c36c1037db566e8ac73d0b90591b09a0a..18b671114ce26701b17d3f403280406ef4738963 100644 (file)
@@ -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: