Skip to content

Commit

Permalink
prog: reuse defaultArg
Browse files Browse the repository at this point in the history
Reuse defaultArg in generateArg. There is code that does the same.
Also, don't generate pointer value for output arguments.
  • Loading branch information
dvyukov committed Aug 9, 2017
1 parent 9e56135 commit 0939075
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion prog/prog.go
Expand Up @@ -292,7 +292,7 @@ func defaultArg(t sys.Type) Arg {
return pointerArg(t, 0, 0, 1, nil)
case *sys.PtrType:
var res Arg
if !t.Optional() {
if !t.Optional() && t.Dir() != sys.DirOut {
res = defaultArg(typ.Type)
}
return pointerArg(t, 0, 0, 0, res)
Expand Down
20 changes: 4 additions & 16 deletions prog/rand.go
Expand Up @@ -608,26 +608,14 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg Arg, calls []*Call) {
// in subsequent calls. For the same reason we do generate pointer/array/struct
// output arguments (their elements can be referenced in subsequent calls).
switch typ.(type) {
case *sys.IntType, *sys.FlagsType, *sys.ConstType, *sys.ProcType:
return constArg(typ, typ.Default()), nil
case *sys.VmaType:
return pointerArg(typ, 0, 0, 0, nil), nil
case *sys.ResourceType:
return resultArg(typ, nil, typ.Default()), nil
case *sys.IntType, *sys.FlagsType, *sys.ConstType, *sys.ProcType,
*sys.VmaType, *sys.ResourceType:
return defaultArg(typ), nil
}
}

if typ.Optional() && r.oneOf(5) {
switch typ.(type) {
case *sys.PtrType:
return pointerArg(typ, 0, 0, 0, nil), nil
case *sys.BufferType:
panic("impossible") // parent PtrType must be Optional instead
case *sys.VmaType:
return pointerArg(typ, 0, 0, 0, nil), nil
default:
return constArg(typ, typ.Default()), nil
}
return defaultArg(typ), nil
}

// Allow infinite recursion for optional pointers.
Expand Down

0 comments on commit 0939075

Please sign in to comment.