[llvm] r306281 - [llvm-stress] Ensure that the C++11 random device respects its min/max values (PR32585)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 03:16:34 PDT 2017


Author: rksimon
Date: Mon Jun 26 03:16:34 2017
New Revision: 306281

URL: http://llvm.org/viewvc/llvm-project?rev=306281&view=rev
Log:
[llvm-stress] Ensure that the C++11 random device respects its min/max values (PR32585)

As noted on PR32585, the change in D29780/rL295325 resulted in calls to Rand32() (values 0 -> 0xFFFFFFFF) but the min()/max() operators indicated it would be (0 -> 0x7FFFF).

This patch changes the random operator to call Rand() instead which does respect the 0 -> 0x7FFFF range and asserts that the value is in range as well.

Differential Revision: https://reviews.llvm.org/D34089

Modified:
    llvm/trunk/tools/llvm-stress/llvm-stress.cpp

Modified: llvm/trunk/tools/llvm-stress/llvm-stress.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-stress/llvm-stress.cpp?rev=306281&r1=306280&r2=306281&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-stress/llvm-stress.cpp (original)
+++ llvm/trunk/tools/llvm-stress/llvm-stress.cpp Mon Jun 26 03:16:34 2017
@@ -116,10 +116,14 @@ public:
 
   /// Make this like a C++11 random device
   typedef uint32_t result_type;
-  uint32_t operator()() { return Rand32(); }
   static constexpr result_type min() { return 0; }
   static constexpr result_type max() { return 0x7ffff; }
-  
+  uint32_t operator()() {
+    uint32_t Val = Rand();
+    assert(Val <= max() && "Random value out of range");
+    return Val;
+  }
+
 private:
   unsigned Seed;
 };




More information about the llvm-commits mailing list