aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-12-28 03:46:20 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-12-28 03:46:20 +0000
commit1358551fc61841e7a78b6f04919d96a54dc24bd1 (patch)
tree0620cac8fee9b74e18be59d7bcc70a0982606b41 /gcc/testsuite/go.test/test
parent9437ab32a5b5d62b625680eaca90b189f8728ec5 (diff)
downloadgcc-1358551fc61841e7a78b6f04919d96a54dc24bd1.zip
gcc-1358551fc61841e7a78b6f04919d96a54dc24bd1.tar.gz
gcc-1358551fc61841e7a78b6f04919d96a54dc24bd1.tar.bz2
compiler: Prohibit comparisons of funcs, maps, and slices to non-nil.
From-SVN: r182703
Diffstat (limited to 'gcc/testsuite/go.test/test')
-rw-r--r--gcc/testsuite/go.test/test/closure.go5
-rw-r--r--gcc/testsuite/go.test/test/cmp1.go130
-rw-r--r--gcc/testsuite/go.test/test/fixedbugs/bug285.go14
-rw-r--r--gcc/testsuite/go.test/test/typeswitch.go5
4 files changed, 2 insertions, 152 deletions
diff --git a/gcc/testsuite/go.test/test/closure.go b/gcc/testsuite/go.test/test/closure.go
index 3033c02..191514d 100644
--- a/gcc/testsuite/go.test/test/closure.go
+++ b/gcc/testsuite/go.test/test/closure.go
@@ -76,7 +76,6 @@ func h() {
func newfunc() func(int) int { return func(x int) int { return x } }
-
func main() {
go f()
check([]int{1, 4, 5, 4})
@@ -90,10 +89,6 @@ func main() {
check([]int{100, 200, 101, 201, 500, 101, 201, 500})
x, y := newfunc(), newfunc()
- if x == y {
- println("newfunc returned same func")
- panic("fail")
- }
if x(1) != 1 || y(2) != 2 {
println("newfunc returned broken funcs")
panic("fail")
diff --git a/gcc/testsuite/go.test/test/cmp1.go b/gcc/testsuite/go.test/test/cmp1.go
deleted file mode 100644
index 698544c..0000000
--- a/gcc/testsuite/go.test/test/cmp1.go
+++ /dev/null
@@ -1,130 +0,0 @@
-// $G $D/$F.go && $L $F.$A && ./$A.out
-
-// Copyright 2009 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 "unsafe"
-
-func use(bool) {}
-
-func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
-
-func isfalse(b bool) {
- if b {
- // stack will explain where
- panic("wanted false, got true")
- }
-}
-
-func istrue(b bool) {
- if !b {
- // stack will explain where
- panic("wanted true, got false")
- }
-}
-
-type T *int
-
-func main() {
- var a []int
- var b map[string]int
-
- var c string = "hello"
- var d string = "hel" // try to get different pointer
- d = d + "lo"
- if stringptr(c) == stringptr(d) {
- panic("compiler too smart -- got same string")
- }
-
- var e = make(chan int)
-
- var ia interface{} = a
- var ib interface{} = b
- var ic interface{} = c
- var id interface{} = d
- var ie interface{} = e
-
- // these comparisons are okay because
- // string compare is okay and the others
- // are comparisons where the types differ.
- isfalse(ia == ib)
- isfalse(ia == ic)
- isfalse(ia == id)
- isfalse(ib == ic)
- isfalse(ib == id)
- istrue(ic == id)
- istrue(ie == ie)
-
- // these are okay because one side of the
- // comparison need only be assignable to the other.
- isfalse(a == ib)
- isfalse(a == ic)
- isfalse(a == id)
- isfalse(b == ic)
- isfalse(b == id)
- istrue(c == id)
- istrue(e == ie)
-
- isfalse(ia == b)
- isfalse(ia == c)
- isfalse(ia == d)
- isfalse(ib == c)
- isfalse(ib == d)
- istrue(ic == d)
- istrue(ie == e)
-
- // 6g used to let this go through as true.
- var g uint64 = 123
- var h int64 = 123
- var ig interface{} = g
- var ih interface{} = h
- isfalse(ig == ih)
-
- // map of interface should use == on interface values,
- // not memory.
- // TODO: should m[c], m[d] be valid here?
- var m = make(map[interface{}]int)
- m[ic] = 1
- m[id] = 2
- if m[ic] != 2 {
- println("m[ic] = ", m[ic])
- panic("bad m[ic]")
- }
-
- // non-interface comparisons
- {
- c := make(chan int)
- c1 := (<-chan int)(c)
- c2 := (chan<- int)(c)
- istrue(c == c1)
- istrue(c == c2)
- istrue(c1 == c)
- istrue(c2 == c)
-
- d := make(chan int)
- isfalse(c == d)
- isfalse(d == c)
- isfalse(d == c1)
- isfalse(d == c2)
- isfalse(c1 == d)
- isfalse(c2 == d)
- }
-
- // named types vs not
- {
- var x = new(int)
- var y T
- var z T = x
-
- isfalse(x == y)
- istrue(x == z)
- isfalse(y == z)
-
- isfalse(y == x)
- istrue(z == x)
- isfalse(z == y)
- }
-}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug285.go b/gcc/testsuite/go.test/test/fixedbugs/bug285.go
index 544d348..7eed8fb 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/bug285.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/bug285.go
@@ -45,20 +45,6 @@ func main() {
mp[p] = 42
mp[&T{7}] = 42
- type F func(x int)
- f := func(x int) {}
- mf := make(map[F]int)
- mf[nil] = 42
- mf[f] = 42
- mf[func(x int) {}] = 42
-
- type M map[int]int
- m := make(M)
- mm := make(map[M]int)
- mm[nil] = 42
- mm[m] = 42
- mm[make(M)] = 42
-
type C chan int
c := make(C)
mc := make(map[C]int)
diff --git a/gcc/testsuite/go.test/test/typeswitch.go b/gcc/testsuite/go.test/test/typeswitch.go
index 83fb098..aa911f9 100644
--- a/gcc/testsuite/go.test/test/typeswitch.go
+++ b/gcc/testsuite/go.test/test/typeswitch.go
@@ -82,9 +82,9 @@ func main() {
case []int:
assert(x[3] == 3 && i == Array, "array")
case map[string]int:
- assert(x == m && i == Map, "map")
+ assert(x != nil && i == Map, "map")
case func(i int) interface{}:
- assert(x == f && i == Func, "fun")
+ assert(x != nil && i == Func, "fun")
default:
assert(false, "unknown")
}
@@ -111,5 +111,4 @@ func main() {
default:
assert(false, "switch 4 unknown")
}
-
}