aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-05-01 17:19:27 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-02 12:16:06 +0200
commit58da4c35b15200b7279f18ea15bc8644618aae78 (patch)
tree412d59572c980c4eb582d6d0e187eb6ec32345c9 /prog/mutation.go
parentbc734e7ada413654f1b7d948b2a857260a52dd9c (diff)
prog: introduce Field type
Remvoe FieldName from Type and add a separate Field type that holds field name. Use Field for struct fields, union options and syscalls arguments, only these really have names. Reduces size of sys/linux/gen/amd64.go from 5665583 to 5201321 (-8.2%). Allows to not create new type for squashed any pointer. But main advantages will follow, e.g. removing StructDesc, using TypeRef in Arg, etc. Update #1580
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index ada2febdb..8758b94f2 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -94,7 +94,7 @@ func (ctx *mutator) squashAny() bool {
}
ptr := complexPtrs[r.Intn(len(complexPtrs))]
if !p.Target.isAnyPtr(ptr.Type()) {
- p.Target.squashPtr(ptr, true)
+ p.Target.squashPtr(ptr)
}
var blobs []*DataArg
var bases []*PointerArg
@@ -320,7 +320,7 @@ func (t *FlagsType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*
}
func (t *LenType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {
- if !r.mutateSize(arg.(*ConstArg), *ctx.Parent) {
+ if !r.mutateSize(arg.(*ConstArg), *ctx.Parent, ctx.Fields) {
retry = true
return
}
@@ -464,25 +464,15 @@ func (t *UnionType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*
return
}
a := arg.(*UnionArg)
- current := -1
- for i, option := range t.Fields {
- if a.Option.Type().FieldName() == option.FieldName() {
- current = i
- break
- }
- }
- if current == -1 {
- panic("can't find current option in union")
- }
- newIdx := r.Intn(len(t.Fields) - 1)
- if newIdx >= current {
- newIdx++
+ index := r.Intn(len(t.Fields) - 1)
+ if index >= a.Index {
+ index++
}
- optType := t.Fields[newIdx]
+ optType := t.Fields[index].Type
removeArg(a.Option)
var newOpt Arg
newOpt, calls = r.generateArg(s, optType, a.Dir())
- replaceArg(arg, MakeUnionArg(t, a.Dir(), newOpt))
+ replaceArg(arg, MakeUnionArg(t, a.Dir(), newOpt, index))
return
}