aboutsummaryrefslogtreecommitdiffstats
path: root/prog/validation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-05-05 10:25:45 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-05-05 10:25:45 +0200
commitafe402d20af0d54d4e0baeb9e70e668e2a26f188 (patch)
tree58f79c51ee9c8a48939059a23c47d68751d55701 /prog/validation.go
parent9dfb5efa91fc0f051a1ddc88ace2867bb6b32275 (diff)
prog: make c.Ret optional
No reason to allocate return value if there is no return type. c.Ret == nil is the reasonable indication that this is a "void" call.
Diffstat (limited to 'prog/validation.go')
-rw-r--r--prog/validation.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/prog/validation.go b/prog/validation.go
index f6e0780fd..ac7faeee2 100644
--- a/prog/validation.go
+++ b/prog/validation.go
@@ -47,26 +47,31 @@ func (p *Prog) validateCall(ctx *validCtx, c *Call) error {
return err
}
}
- if c.Ret == nil {
- return fmt.Errorf("syscall %v: return value is absent", c.Meta.Name)
- }
- if c.Ret.Type() != nil && c.Ret.Type().Dir() != DirOut {
- return fmt.Errorf("syscall %v: return value %v is not output", c.Meta.Name, c.Ret)
- } else if c.Ret.Res != nil || c.Ret.Val != 0 || c.Ret.OpDiv != 0 || c.Ret.OpAdd != 0 {
- return fmt.Errorf("syscall %v: return value %v is not empty", c.Meta.Name, c.Ret)
- }
- if c.Meta.Ret != nil {
+ if c.Meta.Ret == nil {
+ if c.Ret != nil {
+ return fmt.Errorf("syscall %v: return value without type", c.Meta.Name)
+ }
+ } else {
+ if c.Ret == nil {
+ return fmt.Errorf("syscall %v: return value is absent", c.Meta.Name)
+ }
+ if c.Ret.Type() != c.Meta.Ret {
+ return fmt.Errorf("syscall %v: wrong return type", c.Meta.Name)
+ }
+ if c.Ret.Type().Dir() != DirOut {
+ return fmt.Errorf("syscall %v: return value %v is not output", c.Meta.Name, c.Ret)
+ }
+ if c.Ret.Res != nil || c.Ret.Val != 0 || c.Ret.OpDiv != 0 || c.Ret.OpAdd != 0 {
+ return fmt.Errorf("syscall %v: return value %v is not empty", c.Meta.Name, c.Ret)
+ }
if err := validateArg(ctx, c, c.Ret); err != nil {
return err
}
- } else if c.Ret.Type() != nil {
- return fmt.Errorf("syscall %v: return value has spurious type: %+v",
- c.Meta.Name, c.Ret.Type())
}
return nil
}
-// nolint
+// nolint: gocyclo
func validateArg(ctx *validCtx, c *Call, arg Arg) error {
if arg == nil {
return fmt.Errorf("syscall %v: nil arg", c.Meta.Name)
@@ -76,6 +81,7 @@ func validateArg(ctx *validCtx, c *Call, arg Arg) error {
c.Meta.Name, arg)
}
ctx.args[arg] = true
+ // TODO(dvyukov): move this to ResultArg verification.
if used, ok := arg.(*ResultArg); ok {
for u := range used.uses {
if u == nil {