Skip to content
Permalink
Browse files

prog: try to nullify pointers when minimizing

This patch changes minimization routines to try assigning a.Res to nil
for each pointer arg.
  • Loading branch information...
xairy authored and dvyukov committed Nov 15, 2018
1 parent 8463170 commit 5a0d6e039dc1a8bdf3e14650f0eb106e0196e178
Showing with 33 additions and 4 deletions.
  1. +10 −1 prog/minimization.go
  2. +23 −3 prog/minimization_test.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)
}

@@ -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 {

0 comments on commit 5a0d6e0

Please sign in to comment.
You can’t perform that action at this time.