This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by RKSimon on Jun 11 2017, 5:45 AM.

Details

Summary

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.

Not sure the best way to test this - would an assert in the operator be enough?

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Jun 11 2017, 5:45 AM
vsk edited edge metadata.Jun 12 2017, 10:33 AM

Asserting 'r <= max()' in the operator would be a good check.

RKSimon updated this revision to Diff 102311.Jun 13 2017, 4:17 AM

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

Stripped UTF8 BOM from my previous patch

mclow.lists edited edge metadata.Jun 13 2017, 9:01 AM

After thinking about this, I agree with @bogner 's comment that we should just remove the whole Random class, and use the C++11 random number facilities instead.

After thinking about this, I agree with @bogner 's comment that we should just remove the whole Random class, and use the C++11 random number facilities instead.

Is there a C++11 random class that covers the features we need (same results on different targets, drivable by input seed)?

mclow.lists added a comment.EditedJun 13 2017, 11:01 AM

Is there a C++11 random class that covers the features we need (same results on different targets, drivable by input seed)?

Given that the libc++ mersenne_twister_engine tests test specifically that, yes.

see <libc++ root>/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp

Is there a C++11 random class that covers the features we need (same results on different targets, drivable by input seed)?

Given that the libc++ mersenne_twister_engine tests test specifically that, yes.

see <libc++ root>/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp

I've created D34157 for the refactor which is going to take a few days, in the meantime are there any objections to committing this patch to fix PR32585's current assertion in fuzz testing?

ping - D34157 pretty much needs to be started again from scratch and it'd be nice to at least stop the assert from happening from long run fuzz tests.....

hfinkel accepted this revision.Jun 25 2017, 2:29 PM
hfinkel added a subscriber: hfinkel.

Yes, go ahead. Let's fix the current code in the mean time.

This revision is now accepted and ready to land.Jun 25 2017, 2:29 PM
This revision was automatically updated to reflect the committed changes.