diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-11-13 13:58:27 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-11-13 14:27:16 +0100 |
| commit | e1140d252a56611cacd9475e76581812ec7010c9 (patch) | |
| tree | 8623339e33c51eaeeacd26611dc1cefc67481285 | |
| parent | 857a060fe3a415c1909ad8a342d9ca21019ab2fc (diff) | |
prog: add safety check in randGen.flags
This loop used to hang infinitely occasionally when all values are 0s.
The previous commit makes compiler not generate such flags,
but also add a check here to be on the safer side
(we don't have a local check for values and the failure mode was very obscure).
| -rw-r--r-- | prog/rand.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/prog/rand.go b/prog/rand.go index cfe20fb0b..a115b22ec 100644 --- a/prog/rand.go +++ b/prog/rand.go @@ -231,7 +231,9 @@ func (r *randGen) flags(vv []uint64, bitmask bool, oldVal uint64) uint64 { } // We don't want to return 0 here, because we already given 0 // fixed probability above (otherwise we get 0 too frequently). - for v == 0 || r.nOutOf(2, 3) { + // Note: this loop can hang if all values are equal to 0. We don't generate such flags in the compiler now, + // but it used to hang occasionally, so we keep the try < 10 logic b/c we don't have a local check for values. + for try := 0; try < 10 && (v == 0 || r.nOutOf(2, 3)); try++ { flag := vv[r.rand(len(vv))] if r.oneOf(20) { // Try choosing adjacent bit values in case we forgot |
