Skip to content

Commit

Permalink
Instrument comparisons inside comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Nov 25, 2022
1 parent 58c366f commit 410d978
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions instrumenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,10 @@ func (i *instrumenter) visitExpr(exprPtr *ast.Expr) {
if expr.Op.Precedence() == token.EQL.Precedence() {
*exprPtr = i.wrap(expr)
}
// TODO: i.visitExpr(&expr.X)
// TODO: i.visitExpr(&expr.Y)
if expr.Op != token.LAND && expr.Op != token.LOR {
i.visitExpr(&expr.X)
i.visitExpr(&expr.Y)
}

case *ast.KeyValueExpr:
i.visitExpr(&expr.Key)
Expand Down
2 changes: 1 addition & 1 deletion testdata/instrumenter/BinaryExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ func binaryExpr(i int, a bool, b bool) {
i >= 34 && i <= 35

m := map[bool]int{}
_ = m[i == 41] == m[i == 42] // TODO: instrument
_ = m[i == 41] == m[i == 42]
}
4 changes: 3 additions & 1 deletion testdata/instrumenter/BinaryExpr.gobco
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func binaryExpr(i int, a bool, b bool) {
gobcoCover(16, gobcoCover(21, i >= 34) && gobcoCover(22, i <= 35))

m := map[bool]int{}
_ = gobcoCover(23, m[i == 41] == m[i == 42])
_ = gobcoCover(23, m[gobcoCover(24, i == 41)] == m[gobcoCover(25, i == 42)])
}

// :15:6: "i > 0"
Expand All @@ -54,3 +54,5 @@ func binaryExpr(i int, a bool, b bool) {
// :55:3: "i >= 34"
// :55:14: "i <= 35"
// :58:6: "m[i == 41] == m[i == 42]"
// :58:8: "i == 41"
// :58:22: "i == 42"

0 comments on commit 410d978

Please sign in to comment.