[PATCH] D61867: [GWP-ASan] Initial build files, implementation of PRNG [1].

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 14 10:30:13 PDT 2019


morehouse added inline comments.


================
Comment at: compiler-rt/lib/gwp_asan/random.cpp:17
+  static thread_local uint32_t RandomState =
+      static_cast<uint64_t>(time(nullptr));
+  RandomState ^= RandomState << 13;
----------------
I think static is actually implicit in this context.  So `static thread_local` is equivalent to `thread_local`. 


================
Comment at: compiler-rt/lib/gwp_asan/random.cpp:25
+uint32_t getRandomUnsigned32() {
+  static constexpr uint32_t WeylConstant = 362437;
+  static thread_local uint32_t RandomState[6] = {xorShift32(), xorShift32(),
----------------
Since this is a compile-time constant, `static` doesn't do anything.


================
Comment at: compiler-rt/lib/gwp_asan/random.cpp:28
+                                                 xorShift32(), xorShift32(),
+                                                 xorShift32(), xorShift32()};
+  uint32_t Temp = RandomState[0] ^ (RandomState[0] >> 2);
----------------
This seems like a lot of state to keep.  Not a big deal, but is there a simpler RNG we can use?  What about just xorshift32?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61867/new/

https://reviews.llvm.org/D61867





More information about the llvm-commits mailing list