aboutsummaryrefslogtreecommitdiffstats
path: root/prog/rand.go
diff options
context:
space:
mode:
authorPaul Chaignon <paul.chaignon@orange.com>2019-10-18 14:45:31 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-10-25 18:16:59 +0200
commit713f727d983ec2c0c8307a7dcafc270aeee900dd (patch)
tree6f3d539931db47b892b5eecafd8a890a1cb9faf4 /prog/rand.go
parentced0f73a673b1ab94725fe1710dcf7105015eb74 (diff)
prog, pkg/compiler: alignment for integer ranges
Enables the syntax intN[start:end, alignment] for integer ranges. For instance, int32[0:10, 2] represents even 32-bit numbers between 0 and 10 included. With this change, two NEED tags in syscall descriptions can be addressed. Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
Diffstat (limited to 'prog/rand.go')
-rw-r--r--prog/rand.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 1b02dc728..41738c09e 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -119,10 +119,18 @@ func truncateToBitSize(v, bitSize uint64) uint64 {
return v & uint64(1<<bitSize-1)
}
-func (r *randGen) randRangeInt(begin, end, bitSize uint64) uint64 {
+func (r *randGen) randRangeInt(begin, end, bitSize, align uint64) uint64 {
if r.oneOf(100) {
return r.randInt(bitSize)
}
+ if align != 0 {
+ if begin == 0 && int64(end) == -1 {
+ // Special [0:-1] range for all possible values.
+ end = uint64(1<<bitSize - 1)
+ }
+ endAlign := (end - begin) / align
+ return begin + r.randRangeInt(0, endAlign, bitSize, 0)*align
+ }
return begin + (r.Uint64() % (end - begin + 1))
}
@@ -753,7 +761,7 @@ func (a *IntType) generate(r *randGen, s *state) (arg Arg, calls []*Call) {
v = r.randInt(bits)
}
case IntRange:
- v = r.randRangeInt(a.RangeBegin, a.RangeEnd, bits)
+ v = r.randRangeInt(a.RangeBegin, a.RangeEnd, bits, a.Align)
}
return MakeConstArg(a, v), nil
}