diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2018-11-15 20:16:20 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-11-21 05:30:44 +0100 |
| commit | 5a0d6e039dc1a8bdf3e14650f0eb106e0196e178 (patch) | |
| tree | 671299895fb86020f1ee8f2210c9d5158d3542ae /prog | |
| parent | 846317099cc35cf590d6bea9950ca5e8ce51664d (diff) | |
prog: try to nullify pointers when minimizing
This patch changes minimization routines to try assigning a.Res to nil
for each pointer arg.
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/minimization.go | 11 | ||||
| -rw-r--r-- | prog/minimization_test.go | 26 |
2 files changed, 33 insertions, 4 deletions
diff --git a/prog/minimization.go b/prog/minimization.go index 35cff7976..1762bbbae 100644 --- a/prog/minimization.go +++ b/prog/minimization.go @@ -121,11 +121,20 @@ func (typ *UnionType) minimize(ctx *minimizeArgsCtx, arg Arg, path string) bool } func (typ *PtrType) minimize(ctx *minimizeArgsCtx, arg Arg, path string) bool { - // TODO: try to remove optional ptrs a := arg.(*PointerArg) if a.Res == nil { return false } + if !ctx.triedPaths[path+"->"] { + removeArg(a.Res) + replaceArg(a, MakeSpecialPointerArg(a.Type(), 0)) + ctx.target.assignSizesCall(ctx.call) + if ctx.pred(ctx.p, ctx.callIndex0) { + *ctx.p0 = ctx.p + } + ctx.triedPaths[path+"->"] = true + return true + } return ctx.do(a.Res, path) } diff --git a/prog/minimization_test.go b/prog/minimization_test.go index d41663e70..a34ce1f3a 100644 --- a/prog/minimization_test.go +++ b/prog/minimization_test.go @@ -47,7 +47,7 @@ func TestMinimize(t *testing.T) { return len(p.Calls) == 2 && p.Calls[0].Meta.Name == "mmap" && p.Calls[1].Meta.Name == "pipe2" }, "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x0, 0x10, 0xffffffffffffffff, 0x0)\n" + - "pipe2(&(0x7f0000000000), 0x0)\n", + "pipe2(0x0, 0x0)\n", 1, }, // Remove two dependent calls. @@ -80,7 +80,7 @@ func TestMinimize(t *testing.T) { return p.String() == "mmap-write-sched_yield" }, "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x0, 0x10, 0xffffffffffffffff, 0x0)\n" + - "write(0xffffffffffffffff, &(0x7f0000000000), 0x0)\n" + + "write(0xffffffffffffffff, 0x0, 0x0)\n" + "sched_yield()\n", 2, }, @@ -95,10 +95,30 @@ func TestMinimize(t *testing.T) { return p.String() == "mmap-write-sched_yield" }, "mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x0, 0x10, 0xffffffffffffffff, 0x0)\n" + - "write(0xffffffffffffffff, &(0x7f0000000000), 0x0)\n" + + "write(0xffffffffffffffff, 0x0, 0x0)\n" + "sched_yield()\n", -1, }, + // Minimize pointer. + { + "pipe2(&(0x7f0000001000)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0)\n", + -1, + func(p *Prog, callIndex int) bool { + return len(p.Calls) == 1 && p.Calls[0].Meta.Name == "pipe2" + }, + "pipe2(0x0, 0x0)\n", + -1, + }, + // Minimize pointee. + { + "pipe2(&(0x7f0000001000)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0)\n", + -1, + func(p *Prog, callIndex int) bool { + return len(p.Calls) == 1 && p.Calls[0].Meta.Name == "pipe2" && p.Calls[0].Args[0].(*PointerArg).Address != 0 + }, + "pipe2(&(0x7f0000001000), 0x0)\n", + -1, + }, } target, _, _ := initTest(t) for ti, test := range tests { |
