From 713f727d983ec2c0c8307a7dcafc270aeee900dd Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 18 Oct 2019 14:45:31 +0200 Subject: 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 --- prog/mutation.go | 57 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'prog/mutation.go') diff --git a/prog/mutation.go b/prog/mutation.go index 3f5129f4d..c9f647ae8 100644 --- a/prog/mutation.go +++ b/prog/mutation.go @@ -254,26 +254,50 @@ func regenerate(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve b return } -func mutateInt(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bool) { - if r.bin() { - return regenerate(r, s, arg) +func mutateInt(r *randGen, a *ConstArg, t *IntType) uint64 { + switch { + case r.nOutOf(1, 3): + return a.Val + (uint64(r.Intn(4)) + 1) + case r.nOutOf(1, 2): + return a.Val - (uint64(r.Intn(4)) + 1) + default: + return a.Val ^ (1 << uint64(r.Intn(int(t.TypeBitSize())))) } - bits := arg.Type().TypeBitSize() - a := arg.(*ConstArg) +} + +func mutateAlignedInt(r *randGen, a *ConstArg, t *IntType) uint64 { + rangeEnd := t.RangeEnd + if t.RangeBegin == 0 && int64(rangeEnd) == -1 { + // Special [0:-1] range for all possible values. + rangeEnd = uint64(1<