llvm.org GIT mirror llvm / 2e6fc83
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306281 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 2 years ago
1 changed file(s) with 6 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
115115
116116 /// Make this like a C++11 random device
117117 typedef uint32_t result_type;
118 uint32_t operator()() { return Rand32(); }
119118 static constexpr result_type min() { return 0; }
120119 static constexpr result_type max() { return 0x7ffff; }
121
120 uint32_t operator()() {
121 uint32_t Val = Rand();
122 assert(Val <= max() && "Random value out of range");
123 return Val;
124 }
125
122126 private:
123127 unsigned Seed;
124128 };