Skip to content

Commit

Permalink
prog: don't produce the same program when mutating with hints
Browse files Browse the repository at this point in the history
No point in producing the same program as result of mutation with hints.
So don't do it.
  • Loading branch information
dvyukov committed Jan 3, 2019
1 parent adddc5f commit 709e893
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions prog/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func shrinkExpand(v uint64, compMap CompMap) []uint64 {
// Replace size least significant bits of v with
// corresponding bits of newV. Leave the rest of v as it was.
replacer := (v &^ mask) | newV
if replacer == v {
continue
}
// TODO(dvyukov): should we try replacing with arg+/-1?
// This could trigger some off-by-ones.
if replacers == nil {
Expand Down
15 changes: 8 additions & 7 deletions prog/hints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestHintsCheckConstArg(t *testing.T) {
{
"One replacer test",
0xdeadbeef,
CompMap{0xdeadbeef: uint64Set{0xcafebabe: true}},
CompMap{0xdeadbeef: uint64Set{0xdeadbeef: true, 0xcafebabe: true}},
[]uint64{0xcafebabe},
},
// Test for cases when there's multiple comparisons (op1, op2), (op1, op3), ...
Expand All @@ -57,7 +57,6 @@ func TestHintsCheckConstArg(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
t.Parallel()
var res []uint64
constArg := &ConstArg{ArgCommon{nil}, test.in}
checkConstArg(constArg, test.comps, func() {
Expand All @@ -79,7 +78,11 @@ func TestHintsCheckDataArg(t *testing.T) {
{
"One replacer test",
"\xef\xbe\xad\xde",
CompMap{0xdeadbeef: uint64Set{0xcafebabe: true}},
CompMap{
0xdeadbeef: uint64Set{0xcafebabe: true, 0xdeadbeef: true},
0xbeef: uint64Set{0xbeef: true},
0xef: uint64Set{0xef: true},
},
map[string]bool{
"\xbe\xba\xfe\xca": true,
},
Expand Down Expand Up @@ -190,7 +193,6 @@ func TestHintsCheckDataArg(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
t.Parallel()
res := make(map[string]bool)
// Whatever type here. It's just needed to pass the
// dataArg.Type().Dir() == DirIn check.
Expand Down Expand Up @@ -272,16 +274,16 @@ func TestHintsShrinkExpand(t *testing.T) {
"Shrink 64 test",
0x1234567890abcdef,
CompMap{
0xef: uint64Set{0xab: true},
0xef: uint64Set{0xab: true, 0xef: true},
0xcdef: uint64Set{0xcdcd: true},
0x90abcdef: uint64Set{0xefefefef: true},
0x1234567890abcdef: uint64Set{0x0101010101010101: true},
},
[]uint64{
0x0101010101010101,
0x1234567890abcdab,
0x1234567890abcdcd,
0x12345678efefefef,
0x0101010101010101,
},
},
{
Expand Down Expand Up @@ -367,7 +369,6 @@ func TestHintsShrinkExpand(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
t.Parallel()
res := shrinkExpand(test.in, test.comps)
if !reflect.DeepEqual(res, test.res) {
t.Fatalf("\ngot : %v\nwant: %v", res, test.res)
Expand Down

0 comments on commit 709e893

Please sign in to comment.