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

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 04:17:35 PDT 2017


RKSimon updated this revision to Diff 102311.
RKSimon added a comment.

Added assertion that the random value doesn't exceed the maximum.

Stripped UTF8 BOM from my previous patch


Repository:
  rL LLVM

https://reviews.llvm.org/D34089

Files:
  tools/llvm-stress/llvm-stress.cpp


Index: tools/llvm-stress/llvm-stress.cpp
===================================================================
--- tools/llvm-stress/llvm-stress.cpp
+++ tools/llvm-stress/llvm-stress.cpp
@@ -116,10 +116,14 @@
 
   /// 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;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34089.102311.patch
Type: text/x-patch
Size: 631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170613/5962c8f6/attachment.bin>


More information about the llvm-commits mailing list