[all-commits] [llvm/llvm-project] 66d049: [libc++] Fix std::mt19937 seeding with std::seed_s...

Kyungtak Woo via All-commits all-commits at lists.llvm.org
Thu Jul 30 08:08:46 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 66d049cdad21a7ad387f358f7593bee91221bd39
      https://github.com/llvm/llvm-project/commit/66d049cdad21a7ad387f358f7593bee91221bd39
  Author: Kyungtak Woo <kevinwkt at google.com>
  Date:   2026-07-30 (Thu, 30 Jul 2026)

  Changed paths:
    M libcxx/include/__random/mersenne_twister_engine.h
    M libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp
    M libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp

  Log Message:
  -----------
  [libc++] Fix std::mt19937 seeding with std::seed_seq under vectorized ABI (#209860)

This PR fixes a bug in `std::mersenne_twister_engine::seed(_Sseq&)`
where the initialization twist is bypassed when the vectorized engine
optimization (`_LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE`) is
enabled.

In the vectorized implementation introduced in #206423, the engine state
must be pre-twisted during initialization by calling
`__update_all_states()` at the end of the `seed` functions.

However, in `seed(_Sseq& __q)`, the all-zero state check contains an
early `return;` when a non-zero state is verified. This early return
bypasses the trailing `__update_all_states()` call. Consequently, the
generator is initialized with raw, untwisted seed values (tempered)
rather than the standard twisted values.

This only manifests when compiled with unstable ABI settings
(`_LIBCPP_ABI_VERSION >= 2`) which enables the vectorized
implementation.

I replaced the early `return;` inside the all-zero state verification
block with a loop break, and conditionalized the zero-state fix using
the loop index `__i`, ensuring `__update_all_states()` is always
executed at the end of the function. Added regression tests to
`seed_sseq.pass.cpp` asserting the exact deterministic outputs for both
32-bit and 64-bit engines.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list