Skip to content

Commit

Permalink
go-fuzz-build: use _go_fuzz_dep_.Bool instead of bool in generated code
Browse files Browse the repository at this point in the history
This avoids compilation errors when user code shadows the built-in bool,
as happens (for example) in cmd/compile.
  • Loading branch information
josharian authored and dvyukov committed Dec 27, 2018
1 parent 85215ac commit 31e2128
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions go-fuzz-build/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func (s *Sonar) Visit(n ast.Node) ast.Visitor {
// Replace:
// x != y
// with:
// func() bool { v1 := x; v2 := y; go-fuzz-dep.Sonar(v1, v2, flags); return v1 != v2 }() == true
// func() _go_fuzz_dep_.Bool { v1 := x; v2 := y; go-fuzz-dep.Sonar(v1, v2, flags); return v1 != v2 }() == true
// Using "== true" lets us modify the AST Node in-place.
v1 := nn.X
v2 := nn.Y
ast.Walk(s, v1)
Expand Down Expand Up @@ -339,7 +340,7 @@ func (s *Sonar) Visit(n ast.Node) ast.Visitor {
)
nn.X = &ast.CallExpr{
Fun: &ast.FuncLit{
Type: &ast.FuncType{Results: &ast.FieldList{List: []*ast.Field{{Type: ast.NewIdent("bool")}}}},
Type: &ast.FuncType{Results: &ast.FieldList{List: []*ast.Field{{Type: ast.NewIdent("_go_fuzz_dep_.Bool")}}}},
Body: block,
},
}
Expand Down
5 changes: 5 additions & 0 deletions go-fuzz-dep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
. "go-fuzz-defs"
)

// Bool is just a bool.
// It is used by code autogenerated by go-fuzz-build
// to avoid compilation errors when a user's code shadows the built-in bool.
type Bool bool

var (
inFD FD
outFD FD
Expand Down
9 changes: 9 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ func test6() {
func issue194(v testdep.I) testdep.I {
return testdep.B(v == testdep.V1{} || v == testdep.V2{})
}

func shadowedBool() {
var bool int
var x int
if x == 0 {
return
}
_ = bool
}

0 comments on commit 31e2128

Please sign in to comment.