summaryrefslogtreecommitdiff
path: root/test/fixedbugs
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2020-09-11 14:23:34 -0400
committerRob Findley <rfindley@google.com>2020-09-11 14:23:34 -0400
commitf8b1c17aced24a1618c6984794be9770c5d260be (patch)
tree45af8d39b5c3d9f43d439ebec0a2ba42b49efe70 /test/fixedbugs
parente5d91ab096a9ff9673311f1a7f3f860a7f9c2062 (diff)
parent07c1788357cfe6a4ee5f6f6a54d4fe9f579fa844 (diff)
downloadgo-git-dev.types.tar.gz
[dev.types] all: merge master into dev.typesdev.types
Change-Id: Ia6964cb4e09153c15cc9c5b441373d1b3cb8f757
Diffstat (limited to 'test/fixedbugs')
-rw-r--r--test/fixedbugs/bug229.go8
-rw-r--r--test/fixedbugs/issue22921.go18
-rw-r--r--test/fixedbugs/issue24491.go45
-rw-r--r--test/fixedbugs/issue38125.go22
-rw-r--r--test/fixedbugs/issue39505.go31
-rw-r--r--test/fixedbugs/issue39505b.go183
-rw-r--r--test/fixedbugs/issue41247.go11
-rw-r--r--test/fixedbugs/issue8606b.go63
8 files changed, 377 insertions, 4 deletions
diff --git a/test/fixedbugs/bug229.go b/test/fixedbugs/bug229.go
index 4baf65e48b..a30202fa2c 100644
--- a/test/fixedbugs/bug229.go
+++ b/test/fixedbugs/bug229.go
@@ -10,11 +10,11 @@ import "testing"
func main() {
var t testing.T
-
+
// make sure error mentions that
// name is unexported, not just "name not found".
- t.common.name = nil // ERROR "unexported"
-
- println(testing.anyLowercaseName("asdf")) // ERROR "unexported" "undefined: testing.anyLowercaseName"
+ t.common.name = nil // ERROR "unexported"
+
+ println(testing.anyLowercaseName("asdf")) // ERROR "unexported"
}
diff --git a/test/fixedbugs/issue22921.go b/test/fixedbugs/issue22921.go
new file mode 100644
index 0000000000..04f78b2c08
--- /dev/null
+++ b/test/fixedbugs/issue22921.go
@@ -0,0 +1,18 @@
+// errorcheck
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "bytes"
+
+type _ struct{ bytes.nonexist } // ERROR "unexported"
+
+type _ interface{ bytes.nonexist } // ERROR "unexported"
+
+func main() {
+ var _ bytes.Buffer
+ var _ bytes.buffer // ERROR "unexported"
+}
diff --git a/test/fixedbugs/issue24491.go b/test/fixedbugs/issue24491.go
new file mode 100644
index 0000000000..4703368793
--- /dev/null
+++ b/test/fixedbugs/issue24491.go
@@ -0,0 +1,45 @@
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This test makes sure unsafe-uintptr arguments are handled correctly.
+
+package main
+
+import (
+ "runtime"
+ "unsafe"
+)
+
+var done = make(chan bool, 1)
+
+func setup() unsafe.Pointer {
+ s := "ok"
+ runtime.SetFinalizer(&s, func(p *string) { *p = "FAIL" })
+ return unsafe.Pointer(&s)
+}
+
+//go:noinline
+//go:uintptrescapes
+func test(s string, p uintptr) {
+ runtime.GC()
+ if *(*string)(unsafe.Pointer(p)) != "ok" {
+ panic(s + " return unexpected result")
+ }
+ done <- true
+}
+
+func main() {
+ test("normal", uintptr(setup()))
+ <-done
+
+ go test("go", uintptr(setup()))
+ <-done
+
+ func() {
+ defer test("defer", uintptr(setup()))
+ }()
+ <-done
+}
diff --git a/test/fixedbugs/issue38125.go b/test/fixedbugs/issue38125.go
new file mode 100644
index 0000000000..1207aecd39
--- /dev/null
+++ b/test/fixedbugs/issue38125.go
@@ -0,0 +1,22 @@
+// compile
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// gccgo mishandled embedded methods of type aliases.
+
+package p
+
+type I int
+
+func (I) M() {}
+
+type T = struct {
+ I
+}
+
+func F() {
+ _ = T.M
+ _ = struct { I }.M
+}
diff --git a/test/fixedbugs/issue39505.go b/test/fixedbugs/issue39505.go
new file mode 100644
index 0000000000..711b562867
--- /dev/null
+++ b/test/fixedbugs/issue39505.go
@@ -0,0 +1,31 @@
+// compile
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f() {
+ if len([]int{})-1 < len([]int{}) {
+ }
+
+ var st struct {
+ i int
+ }
+ g := func() string {
+ return ""
+ }
+ h := func(string) string {
+ return g() + g()
+ }
+ s, i := "", 0
+
+ st.i = len(s)
+ i = len(h(s[i+0:i+1])) + len(s[len(s)+1:i+1])
+ s = s[(len(s[i+1:len(s)+1])+1):len(h(""))+1] + (s[i+1 : len([]int{})+i])
+ i = 1 + len([]int{len([]string{s[i+len([]int{}) : len(s)+i]})})
+
+ var ch chan int
+ ch <- len(h("")) - len(s)
+}
diff --git a/test/fixedbugs/issue39505b.go b/test/fixedbugs/issue39505b.go
new file mode 100644
index 0000000000..ecf1ab64f4
--- /dev/null
+++ b/test/fixedbugs/issue39505b.go
@@ -0,0 +1,183 @@
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+ ff := []func(){lt_f1, lt_f2, lt_f3, lt_f4, lt_f5, lt_f6, lt_f7, lt_f8, lt_f9,
+ gt_f1, gt_f2, gt_f3, le_f1, le_f2, le_f3, ge_f1, ge_f2, ge_f3}
+
+ for _, f := range ff {
+ f()
+ }
+}
+
+func lt_f1() {
+ const c = 1
+ var a = 0
+ var v *int = &a
+ if *v-c < len([]int{}) {
+ } else {
+ panic("bad")
+ }
+}
+
+func lt_f2() {
+ const c = 10
+ var a = 0
+ var v *int = &a
+ if *v+c < len([]int{}) {
+ panic("bad")
+ }
+}
+
+func lt_f3() {
+ const c = -10
+ var a = 0
+ var v *int = &a
+ if *v|0xff+c < len([]int{}) {
+ panic("bad")
+ }
+}
+
+func lt_f4() {
+ const c = 10
+ var a = 0
+ var v *int = &a
+ if *v|0x0f+c < len([]int{}) {
+ panic("bad")
+ }
+}
+
+func lt_f5() {
+ const c int32 = 1
+ var a int32 = 0
+ var v *int32 = &a
+ if *v-c < int32(len([]int32{})) {
+ } else {
+ panic("bad")
+ }
+}
+
+func lt_f6() {
+ const c int32 = 10
+ var a int32 = 0
+ var v *int32 = &a
+ if *v+c < int32(len([]int32{})) {
+ panic("bad")
+ }
+}
+
+func lt_f7() {
+ const c int32 = -10
+ var a int32 = 0
+ var v *int32 = &a
+ if *v|0xff+c < int32(len([]int{})) {
+ panic("bad")
+ }
+}
+
+func lt_f8() {
+ const c int32 = 10
+ var a int32 = 0
+ var v *int32 = &a
+ if *v|0x0f+c < int32(len([]int{})) {
+ panic("bad")
+ }
+}
+
+func lt_f9() {
+ const c int32 = -10
+ var a int32 = 0
+ var v *int32 = &a
+ if *v|0x0a+c < int32(len([]int{})) {
+ panic("bad")
+ }
+}
+
+func gt_f1() {
+ const c = 1
+ var a = 0
+ var v *int = &a
+ if len([]int{}) > *v-c {
+ } else {
+ panic("bad")
+ }
+}
+
+func gt_f2() {
+ const c = 10
+ var a = 0
+ var v *int = &a
+ if len([]int{}) > *v|0x0f+c {
+ panic("bad")
+ }
+}
+
+func gt_f3() {
+ const c int32 = 10
+ var a int32 = 0
+ var v *int32 = &a
+ if int32(len([]int{})) > *v|0x0f+c {
+ panic("bad")
+ }
+}
+
+func le_f1() {
+ const c = -10
+ var a = 0
+ var v *int = &a
+ if *v|0xff+c <= len([]int{}) {
+ panic("bad")
+ }
+}
+
+func le_f2() {
+ const c = 0xf
+ var a = 0
+ var v *int = &a
+ if *v|0xf-c <= len([]int{}) {
+ } else {
+ panic("bad")
+ }
+}
+
+func le_f3() {
+ const c int32 = -10
+ var a int32 = 0
+ var v *int32 = &a
+ if *v|0xff+c <= int32(len([]int{})) {
+ panic("bad")
+ }
+}
+
+func ge_f1() {
+ const c = -10
+ var a = 0
+ var v *int = &a
+ if len([]int{}) >= *v|0xff+c {
+ panic("bad")
+ }
+}
+
+func ge_f2() {
+ const c int32 = 10
+ var a int32 = 0
+ var v *int32 = &a
+ if int32(len([]int{})) >= *v|0x0f+c {
+ panic("bad")
+ }
+}
+
+func ge_f3() {
+ const c = -10
+ var a = 0
+ var v *int = &a
+ if len([]int{}) >= *v|0x0a+c {
+ } else {
+ panic("bad")
+ }
+}
diff --git a/test/fixedbugs/issue41247.go b/test/fixedbugs/issue41247.go
new file mode 100644
index 0000000000..2df919c9e6
--- /dev/null
+++ b/test/fixedbugs/issue41247.go
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f() [2]int {
+ return [...]int{2: 0} // ERROR "cannot use \[\.\.\.\]int literal \(type \[3\]int\)"
+}
diff --git a/test/fixedbugs/issue8606b.go b/test/fixedbugs/issue8606b.go
new file mode 100644
index 0000000000..448ea566f0
--- /dev/null
+++ b/test/fixedbugs/issue8606b.go
@@ -0,0 +1,63 @@
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This is an optimization check. We want to make sure that we compare
+// string lengths, and other scalar fields, before checking string
+// contents. There's no way to verify this in the language, and
+// codegen tests in test/codegen can't really detect ordering
+// optimizations like this. Instead, we generate invalid strings with
+// bad backing store pointers but nonzero length, so we can check that
+// the backing store never gets compared.
+//
+// We use two different bad strings so that pointer comparisons of
+// backing store pointers fail.
+
+package main
+
+import (
+ "fmt"
+ "reflect"
+ "unsafe"
+)
+
+func bad1() string {
+ s := "foo"
+ (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = 1 // write bad value to data ptr
+ return s
+}
+func bad2() string {
+ s := "foo"
+ (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = 2 // write bad value to data ptr
+ return s
+}
+
+type SI struct {
+ s string
+ i int
+}
+
+type SS struct {
+ s string
+ t string
+}
+
+func main() {
+ for _, test := range []struct {
+ a, b interface{}
+ }{
+ {SI{s: bad1(), i: 1}, SI{s: bad2(), i: 2}},
+ {SS{s: bad1(), t: "a"}, SS{s: bad2(), t: "aa"}},
+ {SS{s: "a", t: bad1()}, SS{s: "b", t: bad2()}},
+ // This one would panic because the length of both strings match, and we check
+ // the body of the bad strings before the body of the good strings.
+ //{SS{s: bad1(), t: "a"}, SS{s: bad2(), t: "b"}},
+ } {
+ if test.a == test.b {
+ panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b))
+ }
+ }
+
+}