diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/go.test/test/ken | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/go.test/test/ken')
41 files changed, 5074 insertions, 0 deletions
diff --git a/gcc/testsuite/go.test/test/ken/array.go b/gcc/testsuite/go.test/test/ken/array.go new file mode 100644 index 000000000..40209f5da --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/array.go @@ -0,0 +1,133 @@ +// $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 + +func setpd(a []int) { + // print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i + } +} + +func sumpd(a []int) int { + // print("sumpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] + } + // print("sumpd t=", t, "\n"); + return t +} + +func setpf(a *[20]int) { + // print("setpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i := 0; i < len(a); i++ { + a[i] = i + } +} + +func sumpf(a *[20]int) int { + // print("sumpf a=", a, " len=", len(a), " cap=", cap(a), "\n"); + t := 0 + for i := 0; i < len(a); i++ { + t += a[i] + } + // print("sumpf t=", t, "\n"); + return t +} + +func res(t int, lb, hb int) { + sb := (hb - lb) * (hb + lb - 1) / 2 + if t != sb { + print("lb=", lb, + "; hb=", hb, + "; t=", t, + "; sb=", sb, + "\n") + panic("res") + } +} + +// call ptr dynamic with ptr dynamic +func testpdpd() { + a := make([]int, 10, 100) + if len(a) != 10 && cap(a) != 100 { + print("len and cap from new: ", len(a), " ", cap(a), "\n") + panic("fail") + } + + a = a[0:100] + setpd(a) + + a = a[0:10] + res(sumpd(a), 0, 10) + + a = a[5:25] + res(sumpd(a), 5, 25) +} + +// call ptr fixed with ptr fixed +func testpfpf() { + var a [20]int + + setpf(&a) + res(sumpf(&a), 0, 20) +} + +// call ptr dynamic with ptr fixed from new +func testpdpf1() { + a := new([40]int) + setpd(a[0:]) + res(sumpd(a[0:]), 0, 40) + + b := (*a)[5:30] + res(sumpd(b), 5, 30) +} + +// call ptr dynamic with ptr fixed from var +func testpdpf2() { + var a [80]int + + setpd(a[0:]) + res(sumpd(a[0:]), 0, 80) +} + +// generate bounds error with ptr dynamic +func testpdfault() { + a := make([]int, 100) + + print("good\n") + for i := 0; i < 100; i++ { + a[i] = 0 + } + print("should fault\n") + a[100] = 0 + print("bad\n") +} + +// generate bounds error with ptr fixed +func testfdfault() { + var a [80]int + + print("good\n") + for i := 0; i < 80; i++ { + a[i] = 0 + } + print("should fault\n") + x := 80 + a[x] = 0 + print("bad\n") +} + +func main() { + testpdpd() + testpfpf() + testpdpf1() + testpdpf2() + // print("testpdfault\n"); testpdfault(); + // print("testfdfault\n"); testfdfault(); +} diff --git a/gcc/testsuite/go.test/test/ken/chan.go b/gcc/testsuite/go.test/test/ken/chan.go new file mode 100644 index 000000000..ef75b044d --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/chan.go @@ -0,0 +1,329 @@ +// $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 "os" +import "runtime" +import "sync" + +var randx int + +func nrand(n int) int { + randx += 10007 + if randx >= 1000000 { + randx -= 1000000 + } + return randx % n +} + +type Chan struct { + sc, rc chan int // send and recv chan + sv, rv int // send and recv seq +} + +var ( + nproc int + nprocLock sync.Mutex + cval int + end int = 10000 + totr, tots int + totLock sync.Mutex + nc *Chan +) + +func init() { + nc = new(Chan) +} + +func changeNproc(adjust int) int { + nprocLock.Lock() + nproc += adjust + ret := nproc + nprocLock.Unlock() + return ret +} + +func mkchan(c, n int) []*Chan { + ca := make([]*Chan, n) + for i := 0; i < n; i++ { + cval = cval + 100 + ch := new(Chan) + ch.sc = make(chan int, c) + ch.rc = ch.sc + ch.sv = cval + ch.rv = cval + ca[i] = ch + } + return ca +} + +func expect(v, v0 int) (newv int) { + if v == v0 { + if v%100 == 75 { + return end + } + return v + 1 + } + print("got ", v, " expected ", v0+1, "\n") + panic("fail") +} + +func (c *Chan) send() bool { + // print("send ", c.sv, "\n"); + totLock.Lock() + tots++ + totLock.Unlock() + c.sv = expect(c.sv, c.sv) + if c.sv == end { + c.sc = nil + return true + } + return false +} + +func send(c *Chan) { + for { + for r := nrand(10); r >= 0; r-- { + runtime.Gosched() + } + c.sc <- c.sv + if c.send() { + break + } + } + changeNproc(-1) +} + +func (c *Chan) recv(v int) bool { + // print("recv ", v, "\n"); + totLock.Lock() + totr++ + totLock.Unlock() + c.rv = expect(c.rv, v) + if c.rv == end { + c.rc = nil + return true + } + return false +} + +func recv(c *Chan) { + var v int + + for { + for r := nrand(10); r >= 0; r-- { + runtime.Gosched() + } + v = <-c.rc + if c.recv(v) { + break + } + } + changeNproc(-1) +} + +func sel(r0, r1, r2, r3, s0, s1, s2, s3 *Chan) { + var v int + + a := 0 // local chans running + + if r0.rc != nil { + a++ + } + if r1.rc != nil { + a++ + } + if r2.rc != nil { + a++ + } + if r3.rc != nil { + a++ + } + if s0.sc != nil { + a++ + } + if s1.sc != nil { + a++ + } + if s2.sc != nil { + a++ + } + if s3.sc != nil { + a++ + } + + for { + for r := nrand(5); r >= 0; r-- { + runtime.Gosched() + } + + select { + case v = <-r0.rc: + if r0.recv(v) { + a-- + } + case v = <-r1.rc: + if r1.recv(v) { + a-- + } + case v = <-r2.rc: + if r2.recv(v) { + a-- + } + case v = <-r3.rc: + if r3.recv(v) { + a-- + } + case s0.sc <- s0.sv: + if s0.send() { + a-- + } + case s1.sc <- s1.sv: + if s1.send() { + a-- + } + case s2.sc <- s2.sv: + if s2.send() { + a-- + } + case s3.sc <- s3.sv: + if s3.send() { + a-- + } + } + if a == 0 { + break + } + } + changeNproc(-1) +} + +// direct send to direct recv +func test1(c *Chan) { + changeNproc(2) + go send(c) + go recv(c) +} + +// direct send to select recv +func test2(c int) { + ca := mkchan(c, 4) + + changeNproc(4) + go send(ca[0]) + go send(ca[1]) + go send(ca[2]) + go send(ca[3]) + + changeNproc(1) + go sel(ca[0], ca[1], ca[2], ca[3], nc, nc, nc, nc) +} + +// select send to direct recv +func test3(c int) { + ca := mkchan(c, 4) + + changeNproc(4) + go recv(ca[0]) + go recv(ca[1]) + go recv(ca[2]) + go recv(ca[3]) + + changeNproc(1) + go sel(nc, nc, nc, nc, ca[0], ca[1], ca[2], ca[3]) +} + +// select send to select recv +func test4(c int) { + ca := mkchan(c, 4) + + changeNproc(2) + go sel(nc, nc, nc, nc, ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], nc, nc, nc, nc) +} + +func test5(c int) { + ca := mkchan(c, 8) + + changeNproc(2) + go sel(ca[4], ca[5], ca[6], ca[7], ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], ca[4], ca[5], ca[6], ca[7]) +} + +func test6(c int) { + ca := mkchan(c, 12) + + changeNproc(4) + go send(ca[4]) + go send(ca[5]) + go send(ca[6]) + go send(ca[7]) + + changeNproc(4) + go recv(ca[8]) + go recv(ca[9]) + go recv(ca[10]) + go recv(ca[11]) + + changeNproc(2) + go sel(ca[4], ca[5], ca[6], ca[7], ca[0], ca[1], ca[2], ca[3]) + go sel(ca[0], ca[1], ca[2], ca[3], ca[8], ca[9], ca[10], ca[11]) +} + +// wait for outstanding tests to finish +func wait() { + runtime.Gosched() + for changeNproc(0) != 0 { + runtime.Gosched() + } +} + +// run all tests with specified buffer size +func tests(c int) { + ca := mkchan(c, 4) + test1(ca[0]) + test1(ca[1]) + test1(ca[2]) + test1(ca[3]) + wait() + + test2(c) + wait() + + test3(c) + wait() + + test4(c) + wait() + + test5(c) + wait() + + test6(c) + wait() +} + +// run all test with 4 buffser sizes +func main() { + + tests(0) + tests(1) + tests(10) + tests(100) + + t := 4 * // buffer sizes + (4*4 + // tests 1,2,3,4 channels + 8 + // test 5 channels + 12) * // test 6 channels + 76 // sends/recvs on a channel + + if tots != t || totr != t { + print("tots=", tots, " totr=", totr, " sb=", t, "\n") + os.Exit(1) + } + os.Exit(0) +} diff --git a/gcc/testsuite/go.test/test/ken/chan1.go b/gcc/testsuite/go.test/test/ken/chan1.go new file mode 100644 index 000000000..e5fc033f3 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/chan1.go @@ -0,0 +1,53 @@ +// $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 "runtime" + +const N = 1000 // sent messages +const M = 10 // receiving goroutines +const W = 2 // channel buffering +var h [N]int // marking of send/recv + +func r(c chan int, m int) { + for { + select { + case r := <-c: + if h[r] != 1 { + println("r", + "m=", m, + "r=", r, + "h=", h[r]) + panic("fail") + } + h[r] = 2 + } + } +} + +func s(c chan int) { + for n := 0; n < N; n++ { + r := n + if h[r] != 0 { + println("s") + panic("fail") + } + h[r] = 1 + c <- r + } +} + +func main() { + c := make(chan int, W) + for m := 0; m < M; m++ { + go r(c, m) + runtime.Gosched() + } + runtime.Gosched() + runtime.Gosched() + s(c) +} diff --git a/gcc/testsuite/go.test/test/ken/complit.go b/gcc/testsuite/go.test/test/ken/complit.go new file mode 100644 index 000000000..da0a84a04 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/complit.go @@ -0,0 +1,170 @@ +// $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 + +type M map[int]int +type S struct{ a,b,c int }; +type SS struct{ aa,bb,cc S }; +type SA struct{ a,b,c [3]int }; +type SC struct{ a,b,c []int }; +type SM struct{ a,b,c M }; + +func +main() { + test("s.a", s.a); + test("s.b", s.b); + test("s.c", s.c); + + test("ss.aa.a", ss.aa.a); + test("ss.aa.b", ss.aa.b); + test("ss.aa.c", ss.aa.c); + + test("ss.bb.a", ss.bb.a); + test("ss.bb.b", ss.bb.b); + test("ss.bb.c", ss.bb.c); + + test("ss.cc.a", ss.cc.a); + test("ss.cc.b", ss.cc.b); + test("ss.cc.c", ss.cc.c); + + for i:=0; i<3; i++ { + test("a[i]", a[i]); + test("c[i]", c[i]); + test("m[i]", m[i]); + + test("as[i].a", as[i].a); + test("as[i].b", as[i].b); + test("as[i].c", as[i].c); + + test("cs[i].a", cs[i].a); + test("cs[i].b", cs[i].b); + test("cs[i].c", cs[i].c); + + test("ms[i].a", ms[i].a); + test("ms[i].b", ms[i].b); + test("ms[i].c", ms[i].c); + + test("sa.a[i]", sa.a[i]); + test("sa.b[i]", sa.b[i]); + test("sa.c[i]", sa.c[i]); + + test("sc.a[i]", sc.a[i]); + test("sc.b[i]", sc.b[i]); + test("sc.c[i]", sc.c[i]); + + test("sm.a[i]", sm.a[i]); + test("sm.b[i]", sm.b[i]); + test("sm.c[i]", sm.c[i]); + + for j:=0; j<3; j++ { + test("aa[i][j]", aa[i][j]); + test("ac[i][j]", ac[i][j]); + test("am[i][j]", am[i][j]); + test("ca[i][j]", ca[i][j]); + test("cc[i][j]", cc[i][j]); + test("cm[i][j]", cm[i][j]); + test("ma[i][j]", ma[i][j]); + test("mc[i][j]", mc[i][j]); + test("mm[i][j]", mm[i][j]); + } + } + +} + +var ref = 0; + +func +test(xs string, x int) { + + if ref >= len(answers) { + println(xs, x); + return; + } + + if x != answers[ref] { + println(xs, "is", x, "should be", answers[ref]) + } + ref++; +} + + +var a = [3]int{1001, 1002, 1003} +var s = S{1101, 1102, 1103} +var c = []int{1201, 1202, 1203} +var m = M{0:1301, 1:1302, 2:1303} + +var aa = [3][3]int{[3]int{2001,2002,2003}, [3]int{2004,2005,2006}, [3]int{2007,2008,2009}} +var as = [3]S{S{2101,2102,2103},S{2104,2105,2106},S{2107,2108,2109}} +var ac = [3][]int{[]int{2201,2202,2203}, []int{2204,2205,2206}, []int{2207,2208,2209}} +var am = [3]M{M{0:2301,1:2302,2:2303}, M{0:2304,1:2305,2:2306}, M{0:2307,1:2308,2:2309}} + +var sa = SA{[3]int{3001,3002,3003},[3]int{3004,3005,3006},[3]int{3007,3008,3009}} +var ss = SS{S{3101,3102,3103},S{3104,3105,3106},S{3107,3108,3109}} +var sc = SC{[]int{3201,3202,3203},[]int{3204,3205,3206},[]int{3207,3208,3209}} +var sm = SM{M{0:3301,1:3302,2:3303}, M{0:3304,1:3305,2:3306}, M{0:3307,1:3308,2:3309}} + +var ca = [][3]int{[3]int{4001,4002,4003}, [3]int{4004,4005,4006}, [3]int{4007,4008,4009}} +var cs = []S{S{4101,4102,4103},S{4104,4105,4106},S{4107,4108,4109}} +var cc = [][]int{[]int{4201,4202,4203}, []int{4204,4205,4206}, []int{4207,4208,4209}} +var cm = []M{M{0:4301,1:4302,2:4303}, M{0:4304,1:4305,2:4306}, M{0:4307,1:4308,2:4309}} + +var ma = map[int][3]int{0:[3]int{5001,5002,5003}, 1:[3]int{5004,5005,5006}, 2:[3]int{5007,5008,5009}} +var ms = map[int]S{0:S{5101,5102,5103},1:S{5104,5105,5106},2:S{5107,5108,5109}} +var mc = map[int][]int{0:[]int{5201,5202,5203}, 1:[]int{5204,5205,5206}, 2:[]int{5207,5208,5209}} +var mm = map[int]M{0:M{0:5301,1:5302,2:5303}, 1:M{0:5304,1:5305,2:5306}, 2:M{0:5307,1:5308,2:5309}} + +var answers = [...]int { + // s + 1101, 1102, 1103, + + // ss + 3101, 3102, 3103, + 3104, 3105, 3106, + 3107, 3108, 3109, + + // [0] + 1001, 1201, 1301, + 2101, 2102, 2103, + 4101, 4102, 4103, + 5101, 5102, 5103, + 3001, 3004, 3007, + 3201, 3204, 3207, + 3301, 3304, 3307, + + // [0][j] + 2001, 2201, 2301, 4001, 4201, 4301, 5001, 5201, 5301, + 2002, 2202, 2302, 4002, 4202, 4302, 5002, 5202, 5302, + 2003, 2203, 2303, 4003, 4203, 4303, 5003, 5203, 5303, + + // [1] + 1002, 1202, 1302, + 2104, 2105, 2106, + 4104, 4105, 4106, + 5104, 5105, 5106, + 3002, 3005, 3008, + 3202, 3205, 3208, + 3302, 3305, 3308, + + // [1][j] + 2004, 2204, 2304, 4004, 4204, 4304, 5004, 5204, 5304, + 2005, 2205, 2305, 4005, 4205, 4305, 5005, 5205, 5305, + 2006, 2206, 2306, 4006, 4206, 4306, 5006, 5206, 5306, + + // [2] + 1003, 1203, 1303, + 2107, 2108, 2109, + 4107, 4108, 4109, + 5107, 5108, 5109, + 3003, 3006, 3009, + 3203, 3206, 3209, + 3303, 3306, 3309, + + // [2][j] + 2007, 2207, 2307, 4007, 4207, 4307, 5007, 5207, 5307, + 2008, 2208, 2308, 4008, 4208, 4308, 5008, 5208, 5308, + 2009, 2209, 2309, 4009, 4209, 4309, 5009, 5209, 5309, +} diff --git a/gcc/testsuite/go.test/test/ken/cplx0.go b/gcc/testsuite/go.test/test/ken/cplx0.go new file mode 100644 index 000000000..ba1fa196f --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx0.go @@ -0,0 +1,28 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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 + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func doprint(c complex128) { println(c) } + +func main() { + + // constants + println(C1) + doprint(C1) + + // variables + c1 := C1 + println(c1) + doprint(c1) +} diff --git a/gcc/testsuite/go.test/test/ken/cplx1.go b/gcc/testsuite/go.test/test/ken/cplx1.go new file mode 100644 index 000000000..8ec7d40f5 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx1.go @@ -0,0 +1,97 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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 + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func main() { + var b bool + + // constants + b = (5 + 6i) == C1 + if !b { + println("const bool 1", b) + panic("fail") + } + + b = (5 + 6i) != C1 + if b { + println("const bool 2", b) + panic("fail") + } + + b = C1 == (5 + 6i) + if !b { + println("const bool 3", b) + panic("fail") + } + + b = C1 != (5 + 6i) + if b { + println("const bool 4", b) + panic("fail") + } + + // vars passed through parameters + booltest(5+6i, true) + booltest(5+7i, false) + booltest(6+6i, false) + booltest(6+9i, false) +} + +func booltest(a complex64, r bool) { + var b bool + + b = a == C1 + if b != r { + println("param bool 1", a, b, r) + panic("fail") + } + + b = a != C1 + if b == r { + println("param bool 2", a, b, r) + panic("fail") + } + + b = C1 == a + if b != r { + println("param bool 3", a, b, r) + panic("fail") + } + + b = C1 != a + if b == r { + println("param bool 4", a, b, r) + panic("fail") + } + + if r { + if a != C1 { + println("param bool 5", a, b, r) + panic("fail") + } + if C1 != a { + println("param bool 6", a, b, r) + panic("fail") + } + } else { + if a == C1 { + println("param bool 6", a, b, r) + panic("fail") + } + if C1 == a { + println("param bool 7", a, b, r) + panic("fail") + } + } +} diff --git a/gcc/testsuite/go.test/test/ken/cplx2.go b/gcc/testsuite/go.test/test/ken/cplx2.go new file mode 100644 index 000000000..5a66dc9a9 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx2.go @@ -0,0 +1,108 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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 + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) + C2 = R - I // SUB(5,-6) + C3 = -(R + I) // ADD(5,6) NEG(-5,-6) + C4 = -(R - I) // SUB(5,-6) NEG(-5,6) + + C5 = C1 + R // ADD(10,6) + C6 = C1 + I // ADD(5,12) + + Ca = C5 + C6 // ADD(15,18) + Cb = C5 - C6 // SUB(5,-6) + + Cc = C5 * C6 // MUL(-22,-150) + Cd = C5 / C6 // DIV(0.721893,-0.532544) + Ce = Cd * C6 // MUL(10,6) sb C5 +) + +func main() { + + r := 5 + 0i + if r != R { + println("opcode 1", r, R) + panic("fail") + } + + i := 6i + if i != I { + println("opcode 2", i, I) + panic("fail") + } + + c1 := r + i + if c1 != C1 { + println("opcode x", c1, C1) + panic("fail") + } + + c2 := r - i + if c2 != C2 { + println("opcode x", c2, C2) + panic("fail") + } + + c3 := -(r + i) + if c3 != C3 { + println("opcode x", c3, C3) + panic("fail") + } + + c4 := -(r - i) + if c4 != C4 { + println("opcode x", c4, C4) + panic("fail") + } + + c5 := c1 + r + if c5 != C5 { + println("opcode x", c5, C5) + panic("fail") + } + + c6 := c1 + i + if c6 != C6 { + println("opcode x", c6, C6) + panic("fail") + } + + ca := c5 + c6 + if ca != Ca { + println("opcode x", ca, Ca) + panic("fail") + } + + cb := c5 - c6 + if cb != Cb { + println("opcode x", cb, Cb) + panic("fail") + } + + cc := c5 * c6 + if cc != Cc { + println("opcode x", cc, Cc) + panic("fail") + } + + cd := c5 / c6 + if cd != Cd { + println("opcode x", cd, Cd) + panic("fail") + } + + ce := cd * c6 + if ce != Ce { + println("opcode x", ce, Ce) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/cplx3.go b/gcc/testsuite/go.test/test/ken/cplx3.go new file mode 100644 index 000000000..83acc15ff --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx3.go @@ -0,0 +1,33 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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" +import "reflect" + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func main() { + c0 := C1 + c0 = (c0 + c0 + c0) / (c0 + c0 + 3i) + println(c0) + + c := *(*complex128)(unsafe.Pointer(&c0)) + println(c) + + var a interface{} + switch c := reflect.NewValue(a).(type) { + case *reflect.ComplexValue: + v := c.Get() + _, _ = complex128(v), true + } +} diff --git a/gcc/testsuite/go.test/test/ken/cplx4.go b/gcc/testsuite/go.test/test/ken/cplx4.go new file mode 100644 index 000000000..8524e47ae --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx4.go @@ -0,0 +1,44 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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 "fmt" + +const ( + R = 5 + I = 6i + + C1 = R + I // ADD(5,6) +) + +func doprint(c complex128) { fmt.Printf("c = %f\n", c) } + +func main() { + + // constants + fmt.Printf("c = %f\n", -C1) + doprint(C1) + + // variables + c1 := C1 + fmt.Printf("c = %f\n", c1) + doprint(c1) + + // 128 + c2 := complex128(C1) + fmt.Printf("c = %G\n", c2) + + // real, imag, complex + c3 := complex(real(c2)+3, imag(c2)-5) + c2 + fmt.Printf("c = %G\n", c3) + + // compiler used to crash on nested divide + c4 := complex(real(c3/2), imag(c3/2)) + if c4 != c3/2 { + fmt.Printf("BUG: c3 = %G != c4 = %G\n", c3, c4) + } +} diff --git a/gcc/testsuite/go.test/test/ken/cplx5.go b/gcc/testsuite/go.test/test/ken/cplx5.go new file mode 100644 index 000000000..d425a7c4c --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/cplx5.go @@ -0,0 +1,54 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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 + +var a [12]complex128 +var s []complex128 +var c chan complex128 +var f struct { + c complex128 +} +var m map[complex128]complex128 + +func main() { + // array of complex128 + for i := 0; i < len(a); i++ { + a[i] = complex(float64(i), float64(-i)) + } + println(a[5]) + + // slice of complex128 + s = make([]complex128, len(a)) + for i := 0; i < len(s); i++ { + s[i] = a[i] + } + println(s[5]) + + // chan + c = make(chan complex128) + go chantest(c) + println(<-c) + + // pointer of complex128 + v := a[5] + pv := &v + println(*pv) + + // field of complex128 + f.c = a[5] + println(f.c) + + // map of complex128 + m = make(map[complex128]complex128) + for i := 0; i < len(s); i++ { + m[-a[i]] = a[i] + } + println(m[5i-5]) + println(m[complex(-5, 5)]) +} + +func chantest(c chan complex128) { c <- a[5] } diff --git a/gcc/testsuite/go.test/test/ken/divconst.go b/gcc/testsuite/go.test/test/ken/divconst.go new file mode 100644 index 000000000..c3b9092cd --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/divconst.go @@ -0,0 +1,632 @@ +// $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 "rand" + +const Count = 1e5 + +func i64rand() int64 { + for { + a := int64(rand.Uint32()) + a = (a << 32) | int64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i64test(a, b, c int64) { + d := a / c + if d != b { + println("i64", a, b, c, d) + panic("fail") + } +} + +func i64run() { + var a, b int64 + + for i := 0; i < Count; i++ { + a = i64rand() + + b = a / 1 + i64test(a, b, 1) + b = a / 2 + i64test(a, b, 2) + b = a / 3 + i64test(a, b, 3) + b = a / 4 + i64test(a, b, 4) + b = a / 5 + i64test(a, b, 5) + b = a / 6 + i64test(a, b, 6) + b = a / 7 + i64test(a, b, 7) + b = a / 8 + i64test(a, b, 8) + b = a / 10 + i64test(a, b, 10) + b = a / 16 + i64test(a, b, 16) + b = a / 20 + i64test(a, b, 20) + b = a / 32 + i64test(a, b, 32) + b = a / 60 + i64test(a, b, 60) + b = a / 64 + i64test(a, b, 64) + b = a / 128 + i64test(a, b, 128) + b = a / 256 + i64test(a, b, 256) + b = a / 16384 + i64test(a, b, 16384) + + b = a / -1 + i64test(a, b, -1) + b = a / -2 + i64test(a, b, -2) + b = a / -3 + i64test(a, b, -3) + b = a / -4 + i64test(a, b, -4) + b = a / -5 + i64test(a, b, -5) + b = a / -6 + i64test(a, b, -6) + b = a / -7 + i64test(a, b, -7) + b = a / -8 + i64test(a, b, -8) + b = a / -10 + i64test(a, b, -10) + b = a / -16 + i64test(a, b, -16) + b = a / -20 + i64test(a, b, -20) + b = a / -32 + i64test(a, b, -32) + b = a / -60 + i64test(a, b, -60) + b = a / -64 + i64test(a, b, -64) + b = a / -128 + i64test(a, b, -128) + b = a / -256 + i64test(a, b, -256) + b = a / -16384 + i64test(a, b, -16384) + } +} + +func u64rand() uint64 { + a := uint64(rand.Uint32()) + a = (a << 32) | uint64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + return a +} + +func u64test(a, b, c uint64) { + d := a / c + if d != b { + println("u64", a, b, c, d) + panic("fail") + } +} + +func u64run() { + var a, b uint64 + + for i := 0; i < Count; i++ { + a = u64rand() + + b = a / 1 + u64test(a, b, 1) + b = a / 2 + u64test(a, b, 2) + b = a / 3 + u64test(a, b, 3) + b = a / 4 + u64test(a, b, 4) + b = a / 5 + u64test(a, b, 5) + b = a / 6 + u64test(a, b, 6) + b = a / 7 + u64test(a, b, 7) + b = a / 8 + u64test(a, b, 8) + b = a / 10 + u64test(a, b, 10) + b = a / 16 + u64test(a, b, 16) + b = a / 20 + u64test(a, b, 20) + b = a / 32 + u64test(a, b, 32) + b = a / 60 + u64test(a, b, 60) + b = a / 64 + u64test(a, b, 64) + b = a / 128 + u64test(a, b, 128) + b = a / 256 + u64test(a, b, 256) + b = a / 16384 + u64test(a, b, 16384) + } +} + +func i32rand() int32 { + for { + a := int32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i32test(a, b, c int32) { + d := a / c + if d != b { + println("i32", a, b, c, d) + panic("fail") + } +} + +func i32run() { + var a, b int32 + + for i := 0; i < Count; i++ { + a = i32rand() + + b = a / 1 + i32test(a, b, 1) + b = a / 2 + i32test(a, b, 2) + b = a / 3 + i32test(a, b, 3) + b = a / 4 + i32test(a, b, 4) + b = a / 5 + i32test(a, b, 5) + b = a / 6 + i32test(a, b, 6) + b = a / 7 + i32test(a, b, 7) + b = a / 8 + i32test(a, b, 8) + b = a / 10 + i32test(a, b, 10) + b = a / 16 + i32test(a, b, 16) + b = a / 20 + i32test(a, b, 20) + b = a / 32 + i32test(a, b, 32) + b = a / 60 + i32test(a, b, 60) + b = a / 64 + i32test(a, b, 64) + b = a / 128 + i32test(a, b, 128) + b = a / 256 + i32test(a, b, 256) + b = a / 16384 + i32test(a, b, 16384) + + b = a / -1 + i32test(a, b, -1) + b = a / -2 + i32test(a, b, -2) + b = a / -3 + i32test(a, b, -3) + b = a / -4 + i32test(a, b, -4) + b = a / -5 + i32test(a, b, -5) + b = a / -6 + i32test(a, b, -6) + b = a / -7 + i32test(a, b, -7) + b = a / -8 + i32test(a, b, -8) + b = a / -10 + i32test(a, b, -10) + b = a / -16 + i32test(a, b, -16) + b = a / -20 + i32test(a, b, -20) + b = a / -32 + i32test(a, b, -32) + b = a / -60 + i32test(a, b, -60) + b = a / -64 + i32test(a, b, -64) + b = a / -128 + i32test(a, b, -128) + b = a / -256 + i32test(a, b, -256) + } +} + +func u32rand() uint32 { + a := uint32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + return a +} + +func u32test(a, b, c uint32) { + d := a / c + if d != b { + println("u32", a, b, c, d) + panic("fail") + } +} + +func u32run() { + var a, b uint32 + + for i := 0; i < Count; i++ { + a = u32rand() + + b = a / 1 + u32test(a, b, 1) + b = a / 2 + u32test(a, b, 2) + b = a / 3 + u32test(a, b, 3) + b = a / 4 + u32test(a, b, 4) + b = a / 5 + u32test(a, b, 5) + b = a / 6 + u32test(a, b, 6) + b = a / 7 + u32test(a, b, 7) + b = a / 8 + u32test(a, b, 8) + b = a / 10 + u32test(a, b, 10) + b = a / 16 + u32test(a, b, 16) + b = a / 20 + u32test(a, b, 20) + b = a / 32 + u32test(a, b, 32) + b = a / 60 + u32test(a, b, 60) + b = a / 64 + u32test(a, b, 64) + b = a / 128 + u32test(a, b, 128) + b = a / 256 + u32test(a, b, 256) + b = a / 16384 + u32test(a, b, 16384) + } +} + +func i16rand() int16 { + for { + a := int16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i16test(a, b, c int16) { + d := a / c + if d != b { + println("i16", a, b, c, d) + panic("fail") + } +} + +func i16run() { + var a, b int16 + + for i := 0; i < Count; i++ { + a = i16rand() + + b = a / 1 + i16test(a, b, 1) + b = a / 2 + i16test(a, b, 2) + b = a / 3 + i16test(a, b, 3) + b = a / 4 + i16test(a, b, 4) + b = a / 5 + i16test(a, b, 5) + b = a / 6 + i16test(a, b, 6) + b = a / 7 + i16test(a, b, 7) + b = a / 8 + i16test(a, b, 8) + b = a / 10 + i16test(a, b, 10) + b = a / 16 + i16test(a, b, 16) + b = a / 20 + i16test(a, b, 20) + b = a / 32 + i16test(a, b, 32) + b = a / 60 + i16test(a, b, 60) + b = a / 64 + i16test(a, b, 64) + b = a / 128 + i16test(a, b, 128) + b = a / 256 + i16test(a, b, 256) + b = a / 16384 + i16test(a, b, 16384) + + b = a / -1 + i16test(a, b, -1) + b = a / -2 + i16test(a, b, -2) + b = a / -3 + i16test(a, b, -3) + b = a / -4 + i16test(a, b, -4) + b = a / -5 + i16test(a, b, -5) + b = a / -6 + i16test(a, b, -6) + b = a / -7 + i16test(a, b, -7) + b = a / -8 + i16test(a, b, -8) + b = a / -10 + i16test(a, b, -10) + b = a / -16 + i16test(a, b, -16) + b = a / -20 + i16test(a, b, -20) + b = a / -32 + i16test(a, b, -32) + b = a / -60 + i16test(a, b, -60) + b = a / -64 + i16test(a, b, -64) + b = a / -128 + i16test(a, b, -128) + b = a / -256 + i16test(a, b, -256) + b = a / -16384 + i16test(a, b, -16384) + } +} + +func u16rand() uint16 { + a := uint16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + return a +} + +func u16test(a, b, c uint16) { + d := a / c + if d != b { + println("u16", a, b, c, d) + panic("fail") + } +} + +func u16run() { + var a, b uint16 + + for i := 0; i < Count; i++ { + a = u16rand() + + b = a / 1 + u16test(a, b, 1) + b = a / 2 + u16test(a, b, 2) + b = a / 3 + u16test(a, b, 3) + b = a / 4 + u16test(a, b, 4) + b = a / 5 + u16test(a, b, 5) + b = a / 6 + u16test(a, b, 6) + b = a / 7 + u16test(a, b, 7) + b = a / 8 + u16test(a, b, 8) + b = a / 10 + u16test(a, b, 10) + b = a / 16 + u16test(a, b, 16) + b = a / 20 + u16test(a, b, 20) + b = a / 32 + u16test(a, b, 32) + b = a / 60 + u16test(a, b, 60) + b = a / 64 + u16test(a, b, 64) + b = a / 128 + u16test(a, b, 128) + b = a / 256 + u16test(a, b, 256) + b = a / 16384 + u16test(a, b, 16384) + } +} + +func i8rand() int8 { + for { + a := int8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i8test(a, b, c int8) { + d := a / c + if d != b { + println("i8", a, b, c, d) + panic("fail") + } +} + +func i8run() { + var a, b int8 + + for i := 0; i < Count; i++ { + a = i8rand() + + b = a / 1 + i8test(a, b, 1) + b = a / 2 + i8test(a, b, 2) + b = a / 3 + i8test(a, b, 3) + b = a / 4 + i8test(a, b, 4) + b = a / 5 + i8test(a, b, 5) + b = a / 6 + i8test(a, b, 6) + b = a / 7 + i8test(a, b, 7) + b = a / 8 + i8test(a, b, 8) + b = a / 10 + i8test(a, b, 10) + b = a / 8 + i8test(a, b, 8) + b = a / 20 + i8test(a, b, 20) + b = a / 32 + i8test(a, b, 32) + b = a / 60 + i8test(a, b, 60) + b = a / 64 + i8test(a, b, 64) + b = a / 127 + i8test(a, b, 127) + + b = a / -1 + i8test(a, b, -1) + b = a / -2 + i8test(a, b, -2) + b = a / -3 + i8test(a, b, -3) + b = a / -4 + i8test(a, b, -4) + b = a / -5 + i8test(a, b, -5) + b = a / -6 + i8test(a, b, -6) + b = a / -7 + i8test(a, b, -7) + b = a / -8 + i8test(a, b, -8) + b = a / -10 + i8test(a, b, -10) + b = a / -8 + i8test(a, b, -8) + b = a / -20 + i8test(a, b, -20) + b = a / -32 + i8test(a, b, -32) + b = a / -60 + i8test(a, b, -60) + b = a / -64 + i8test(a, b, -64) + b = a / -128 + i8test(a, b, -128) + } +} + +func u8rand() uint8 { + a := uint8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + return a +} + +func u8test(a, b, c uint8) { + d := a / c + if d != b { + println("u8", a, b, c, d) + panic("fail") + } +} + +func u8run() { + var a, b uint8 + + for i := 0; i < Count; i++ { + a = u8rand() + + b = a / 1 + u8test(a, b, 1) + b = a / 2 + u8test(a, b, 2) + b = a / 3 + u8test(a, b, 3) + b = a / 4 + u8test(a, b, 4) + b = a / 5 + u8test(a, b, 5) + b = a / 6 + u8test(a, b, 6) + b = a / 7 + u8test(a, b, 7) + b = a / 8 + u8test(a, b, 8) + b = a / 10 + u8test(a, b, 10) + b = a / 8 + u8test(a, b, 8) + b = a / 20 + u8test(a, b, 20) + b = a / 32 + u8test(a, b, 32) + b = a / 60 + u8test(a, b, 60) + b = a / 64 + u8test(a, b, 64) + b = a / 128 + u8test(a, b, 128) + b = a / 184 + u8test(a, b, 184) + } +} + +func main() { + xtest() + i64run() + u64run() + i32run() + u32run() + i16run() + u16run() + i8run() + u8run() +} + +func xtest() { +} diff --git a/gcc/testsuite/go.test/test/ken/divmod.go b/gcc/testsuite/go.test/test/ken/divmod.go new file mode 100644 index 000000000..dc44ea245 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/divmod.go @@ -0,0 +1,247 @@ +// $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 + +const ( + // example from the spec + n1 = +5 + n2 = -5 + d1 = +3 + d2 = -3 + + q1 = +1 + q2 = -1 + q3 = -1 + q4 = +1 + + r1 = +2 + r2 = -2 + r3 = +2 + r4 = -2 +) + +func main() { + /* ideals */ + if n1/d1 != q1 || n1%d1 != r1 { + println("ideal-1", n1, d1, n1/d1, n1%d1) + panic("fail") + } + if n2/d1 != q2 || n2%d1 != r2 { + println("ideal-2", n2, d1, n2/d1, n2%d1) + panic("fail") + } + if n1/d2 != q3 || n1%d2 != r3 { + println("ideal-3", n1, d2, n1/d2, n1%d2) + panic("fail") + } + if n2/d2 != q4 || n2%d2 != r4 { + println("ideal-4", n2, d2, n2/d2, n2%d2) + panic("fail") + } + + /* int */ + var in1 int = +5 + var in2 int = -5 + var id1 int = +3 + var id2 int = -3 + + if in1/id1 != q1 || in1%id1 != r1 { + println("int-1", in1, id1, in1/id1, in1%id1) + panic("fail") + } + if in2/id1 != q2 || in2%id1 != r2 { + println("int-2", in2, id1, in2/id1, in2%id1) + panic("fail") + } + if in1/id2 != q3 || in1%id2 != r3 { + println("int-3", in1, id2, in1/id2, in1%id2) + panic("fail") + } + if in2/id2 != q4 || in2%id2 != r4 { + println("int-4", in2, id2, in2/id2, in2%id2) + panic("fail") + } + + /* int8 */ + var bn1 int8 = +5 + var bn2 int8 = -5 + var bd1 int8 = +3 + var bd2 int8 = -3 + + if bn1/bd1 != q1 || bn1%bd1 != r1 { + println("int8-1", bn1, bd1, bn1/bd1, bn1%bd1) + panic("fail") + } + if bn2/bd1 != q2 || bn2%bd1 != r2 { + println("int8-2", bn2, bd1, bn2/bd1, bn2%bd1) + panic("fail") + } + if bn1/bd2 != q3 || bn1%bd2 != r3 { + println("int8-3", bn1, bd2, bn1/bd2, bn1%bd2) + panic("fail") + } + if bn2/bd2 != q4 || bn2%bd2 != r4 { + println("int8-4", bn2, bd2, bn2/bd2, bn2%bd2) + panic("fail") + } + + /* int16 */ + var sn1 int16 = +5 + var sn2 int16 = -5 + var sd1 int16 = +3 + var sd2 int16 = -3 + + if sn1/sd1 != q1 || sn1%sd1 != r1 { + println("int16-1", sn1, sd1, sn1/sd1, sn1%sd1) + panic("fail") + } + if sn2/sd1 != q2 || sn2%sd1 != r2 { + println("int16-2", sn2, sd1, sn2/sd1, sn2%sd1) + panic("fail") + } + if sn1/sd2 != q3 || sn1%sd2 != r3 { + println("int16-3", sn1, sd2, sn1/sd2, sn1%sd2) + panic("fail") + } + if sn2/sd2 != q4 || sn2%sd2 != r4 { + println("int16-4", sn2, sd2, sn2/sd2, sn2%sd2) + panic("fail") + } + + /* int32 */ + var ln1 int32 = +5 + var ln2 int32 = -5 + var ld1 int32 = +3 + var ld2 int32 = -3 + + if ln1/ld1 != q1 || ln1%ld1 != r1 { + println("int32-1", ln1, ld1, ln1/ld1, ln1%ld1) + panic("fail") + } + if ln2/ld1 != q2 || ln2%ld1 != r2 { + println("int32-2", ln2, ld1, ln2/ld1, ln2%ld1) + panic("fail") + } + if ln1/ld2 != q3 || ln1%ld2 != r3 { + println("int32-3", ln1, ld2, ln1/ld2, ln1%ld2) + panic("fail") + } + if ln2/ld2 != q4 || ln2%ld2 != r4 { + println("int32-4", ln2, ld2, ln2/ld2, ln2%ld2) + panic("fail") + } + + /* int64 */ + var qn1 int64 = +5 + var qn2 int64 = -5 + var qd1 int64 = +3 + var qd2 int64 = -3 + + if qn1/qd1 != q1 || qn1%qd1 != r1 { + println("int64-1", qn1, qd1, qn1/qd1, qn1%qd1) + panic("fail") + } + if qn2/qd1 != q2 || qn2%qd1 != r2 { + println("int64-2", qn2, qd1, qn2/qd1, qn2%qd1) + panic("fail") + } + if qn1/qd2 != q3 || qn1%qd2 != r3 { + println("int64-3", qn1, qd2, qn1/qd2, qn1%qd2) + panic("fail") + } + if qn2/qd2 != q4 || qn2%qd2 != r4 { + println("int64-4", qn2, qd2, qn2/qd2, qn2%qd2) + panic("fail") + } + + if n1/qd1 != q1 || n1%qd1 != r1 { + println("mixed int64-1", n1, qd1, n1/qd1, n1%qd1) + panic("fail") + } + if n2/qd1 != q2 || n2%qd1 != r2 { + println("mixed int64-2", n2, qd1, n2/qd1, n2%qd1) + panic("fail") + } + if n1/qd2 != q3 || n1%qd2 != r3 { + println("mixed int64-3", n1, qd2, n1/qd2, n1%qd2) + panic("fail") + } + if n2/qd2 != q4 || n2%qd2 != r4 { + println("mixed int64-4", n2, qd2, n2/qd2, n2%qd2) + panic("fail") + } + + if qn1/d1 != q1 || qn1%d1 != r1 { + println("mixed int64-5", qn1, d1, qn1/d1, qn1%d1) + panic("fail") + } + if qn2/d1 != q2 || qn2%d1 != r2 { + println("mixed int64-6", qn2, d1, qn2/d1, qn2%d1) + panic("fail") + } + if qn1/d2 != q3 || qn1%d2 != r3 { + println("mixed int64-7", qn1, d2, qn1/d2, qn1%d2) + panic("fail") + } + if qn2/d2 != q4 || qn2%d2 != r4 { + println("mixed int64-8", qn2, d2, qn2/d2, qn2%d2) + panic("fail") + } + + /* uint */ + var uin1 uint = +5 + var uid1 uint = +3 + + if uin1/uid1 != q1 || uin1%uid1 != r1 { + println("uint", uin1, uid1, uin1/uid1, uin1%uid1) + panic("fail") + } + + /* uint8 */ + var ubn1 uint8 = +5 + var ubd1 uint8 = +3 + + if ubn1/ubd1 != q1 || ubn1%ubd1 != r1 { + println("uint8", ubn1, ubd1, ubn1/ubd1, ubn1%ubd1) + panic("fail") + } + + /* uint16 */ + var usn1 uint16 = +5 + var usd1 uint16 = +3 + + if usn1/usd1 != q1 || usn1%usd1 != r1 { + println("uint16", usn1, usd1, usn1/usd1, usn1%usd1) + panic("fail") + } + + /* uint32 */ + var uln1 uint32 = +5 + var uld1 uint32 = +3 + + if uln1/uld1 != q1 || uln1%uld1 != r1 { + println("uint32", uln1, uld1, uln1/uld1, uln1%uld1) + panic("fail") + } + + /* uint64 */ + var uqn1 uint64 = +5 + var uqd1 uint64 = +3 + + if uqn1/uqd1 != q1 || uqn1%uqd1 != r1 { + println("uint64", uqn1, uqd1, uqn1/uqd1, uqn1%uqd1) + panic("fail") + } + if n1/uqd1 != q1 || n1%uqd1 != r1 { + println("mixed uint64-1", n1, uqd1, n1/uqd1, n1%uqd1) + panic("fail") + } + if uqn1/d1 != q1 || uqn1%d1 != r1 { + println("mixed uint64-2", uqn1, d1, uqn1/d1, uqn1%d1) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/embed.go b/gcc/testsuite/go.test/test/ken/embed.go new file mode 100644 index 000000000..9805e479b --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/embed.go @@ -0,0 +1,317 @@ +// $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 + + +type I interface { + test1() int + test2() int + test3() int + test4() int + test5() int + test6() int + test7() int +} + +/****** + ****** + ******/ + +type SubpSubp struct { + a7 int + a int +} + +func (p *SubpSubp) test7() int { + if p.a != p.a7 { + println("SubpSubp", p, p.a7) + panic("fail") + } + return p.a +} +func (p *SubpSubp) testx() { println("SubpSubp", p, p.a7) } + +/****** + ****** + ******/ + +type SubpSub struct { + a6 int + SubpSubp + a int +} + +func (p *SubpSub) test6() int { + if p.a != p.a6 { + println("SubpSub", p, p.a6) + panic("fail") + } + return p.a +} +func (p *SubpSub) testx() { println("SubpSub", p, p.a6) } + +/****** + ****** + ******/ + +type SubSubp struct { + a5 int + a int +} + +func (p *SubSubp) test5() int { + if p.a != p.a5 { + println("SubpSub", p, p.a5) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type SubSub struct { + a4 int + a int +} + +func (p *SubSub) test4() int { + if p.a != p.a4 { + println("SubpSub", p, p.a4) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type Subp struct { + a3 int + *SubpSubp + SubpSub + a int +} + +func (p *Subp) test3() int { + if p.a != p.a3 { + println("SubpSub", p, p.a3) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type Sub struct { + a2 int + *SubSubp + SubSub + a int +} + +func (p *Sub) test2() int { + if p.a != p.a2 { + println("SubpSub", p, p.a2) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +type S struct { + a1 int + Sub + *Subp + a int +} + +func (p *S) test1() int { + if p.a != p.a1 { + println("SubpSub", p, p.a1) + panic("fail") + } + return p.a +} + +/****** + ****** + ******/ + +func main() { + var i I + var s *S + + // allocate + s = new(S) + s.Subp = new(Subp) + s.Sub.SubSubp = new(SubSubp) + s.Subp.SubpSubp = new(SubpSubp) + + // explicit assignment + s.a = 1 + s.Sub.a = 2 + s.Subp.a = 3 + s.Sub.SubSub.a = 4 + s.Sub.SubSubp.a = 5 + s.Subp.SubpSub.a = 6 + s.Subp.SubpSubp.a = 7 + + // embedded (unique) assignment + s.a1 = 1 + s.a2 = 2 + s.a3 = 3 + s.a4 = 4 + s.a5 = 5 + s.a6 = 6 + s.a7 = 7 + + // unique calls with explicit & + if s.test1() != 1 { + println("t1", 1) + panic("fail") + } + if (&s.Sub).test2() != 2 { + println("t1", 2) + panic("fail") + } + if s.Subp.test3() != 3 { + println("t1", 3) + panic("fail") + } + if (&s.Sub.SubSub).test4() != 4 { + println("t1", 4) + panic("fail") + } + if s.Sub.SubSubp.test5() != 5 { + println("t1", 5) + panic("fail") + } + if (&s.Subp.SubpSub).test6() != 6 { + println("t1", 6) + panic("fail") + } + if s.Subp.SubpSubp.test7() != 7 { + println("t1", 7) + panic("fail") + } + + // automatic & + if s.Sub.test2() != 2 { + println("t2", 2) + panic("fail") + } + if s.Sub.SubSub.test4() != 4 { + println("t2", 4) + panic("fail") + } + if s.Subp.SubpSub.test6() != 6 { + println("t2", 6) + panic("fail") + } + + // embedded calls + if s.test1() != s.a1 { + println("t3", 1) + panic("fail") + } + if s.test2() != s.a2 { + println("t3", 2) + panic("fail") + } + if s.test3() != s.a3 { + println("t3", 3) + panic("fail") + } + if s.test4() != s.a4 { + println("t3", 4) + panic("fail") + } + if s.test5() != s.a5 { + println("t3", 5) + panic("fail") + } + if s.test6() != s.a6 { + println("t3", 6) + panic("fail") + } + if s.test7() != s.a7 { + println("t3", 7) + panic("fail") + } + + // run it thru an interface + i = s + s = i.(*S) + + // same as t3 + if s.test1() != s.a1 { + println("t4", 1) + panic("fail") + } + if s.test2() != s.a2 { + println("t4", 2) + panic("fail") + } + if s.test3() != s.a3 { + println("t4", 3) + panic("fail") + } + if s.test4() != s.a4 { + println("t4", 4) + panic("fail") + } + if s.test5() != s.a5 { + println("t4", 5) + panic("fail") + } + if s.test6() != s.a6 { + println("t4", 6) + panic("fail") + } + if s.test7() != s.a7 { + println("t4", 7) + panic("fail") + } + + // call interface + if i.test1() != s.test1() { + println("t5", 1) + panic("fail") + } + if i.test2() != s.test2() { + println("t5", 2) + panic("fail") + } + if i.test3() != s.test3() { + println("t5", 3) + panic("fail") + } + if i.test4() != s.test4() { + println("t5", 4) + panic("fail") + } + if i.test5() != s.test5() { + println("t5", 5) + panic("fail") + } + if i.test6() != s.test6() { + println("t5", 6) + panic("fail") + } + if i.test7() != s.test7() { + println("t5", 7) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/for.go b/gcc/testsuite/go.test/test/ken/for.go new file mode 100644 index 000000000..176ecd749 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/for.go @@ -0,0 +1,18 @@ +// $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 + +func +main() { + var t,i int; + + for i=0; i<100; i=i+1 { + t = t+i; + } + if t != 50*99 { panic(t); } +} diff --git a/gcc/testsuite/go.test/test/ken/interbasic.go b/gcc/testsuite/go.test/test/ken/interbasic.go new file mode 100644 index 000000000..9bb50886a --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/interbasic.go @@ -0,0 +1,182 @@ +// $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 + +type myint int +type mystring string +type I0 interface{} + +func f() { + var ia, ib I0 + var i myint + var s mystring + + if ia != ib { + panic("1") + } + + i = 1 + ia = i + ib = i + if ia != ib { + panic("2") + } + if ia == nil { + panic("3") + } + + i = 2 + ia = i + if ia == ib { + panic("4") + } + + ia = nil + if ia == ib { + panic("5") + } + + ib = nil + if ia != ib { + panic("6") + } + + if ia != nil { + panic("7") + } + + s = "abc" + ia = s + ib = nil + if ia == ib { + panic("8") + } + + s = "def" + ib = s + if ia == ib { + panic("9") + } + + s = "abc" + ib = s + if ia != ib { + panic("a") + } +} + +func main() { + var ia [20]I0 + var b bool + var s string + var i8 int8 + var i16 int16 + var i32 int32 + var i64 int64 + var u8 uint8 + var u16 uint16 + var u32 uint32 + var u64 uint64 + + f() + + ia[0] = "xxx" + ia[1] = 12345 + ia[2] = true + + s = "now is" + ia[3] = s + b = false + ia[4] = b + + i8 = 29 + ia[5] = i8 + i16 = 994 + ia[6] = i16 + i32 = 3434 + ia[7] = i32 + i64 = 1234567 + ia[8] = i64 + + u8 = 12 + ia[9] = u8 + u16 = 799 + ia[10] = u16 + u32 = 4455 + ia[11] = u32 + u64 = 765432 + ia[12] = u64 + + s = ia[0].(string) + if s != "xxx" { + println(0, s) + panic("fail") + } + i32 = int32(ia[1].(int)) + if i32 != 12345 { + println(1, i32) + panic("fail") + } + b = ia[2].(bool) + if b != true { + println(2, b) + panic("fail") + } + + s = ia[3].(string) + if s != "now is" { + println(3, s) + panic("fail") + } + b = ia[4].(bool) + if b != false { + println(4, b) + panic("fail") + } + + i8 = ia[5].(int8) + if i8 != 29 { + println(5, i8) + panic("fail") + } + i16 = ia[6].(int16) + if i16 != 994 { + println(6, i16) + panic("fail") + } + i32 = ia[7].(int32) + if i32 != 3434 { + println(7, i32) + panic("fail") + } + i64 = ia[8].(int64) + if i64 != 1234567 { + println(8, i64) + panic("fail") + } + + u8 = ia[9].(uint8) + if u8 != 12 { + println(5, u8) + panic("fail") + } + u16 = ia[10].(uint16) + if u16 != 799 { + println(6, u16) + panic("fail") + } + u32 = ia[11].(uint32) + if u32 != 4455 { + println(7, u32) + panic("fail") + } + u64 = ia[12].(uint64) + if u64 != 765432 { + println(8, u64) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/interfun.go b/gcc/testsuite/go.test/test/ken/interfun.go new file mode 100644 index 000000000..94bc7eaad --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/interfun.go @@ -0,0 +1,57 @@ +// $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 + +type S struct { + a,b int; +} + +type I1 interface { + f ()int; +} + +type I2 interface { + g() int; + f() int; +} + +func (this *S) f()int { + return this.a; +} + +func (this *S) g()int { + return this.b; +} + +func +main() { + var i1 I1; + var i2 I2; + var g *S; + + s := new(S); + s.a = 5; + s.b = 6; + + // call structure + if s.f() != 5 { panic(11); } + if s.g() != 6 { panic(12); } + + i1 = s; // convert S to I1 + i2 = i1.(I2); // convert I1 to I2 + + // call interface + if i1.f() != 5 { panic(21); } + if i2.f() != 5 { panic(22); } + if i2.g() != 6 { panic(23); } + + g = i1.(*S); // convert I1 to S + if g != s { panic(31); } + + g = i2.(*S); // convert I2 to S + if g != s { panic(32); } +} diff --git a/gcc/testsuite/go.test/test/ken/intervar.go b/gcc/testsuite/go.test/test/ken/intervar.go new file mode 100644 index 000000000..c2aaaa870 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/intervar.go @@ -0,0 +1,64 @@ +// $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 + +type Iputs interface { + puts (s string); +} + +// --------- + +type Print struct { + whoami int; + put Iputs; +} + +func (p *Print) dop() { + print(" print ", p.whoami); + p.put.puts("abc"); +} + +// --------- + +type Bio struct { + whoami int; + put Iputs; +} + +func (b *Bio) puts(s string) { + print(" bio ", b.whoami); + b.put.puts(s); +} + +// --------- + +type File struct { + whoami int; + put Iputs; +} + +func (f *File) puts(s string) { + print(" file ", f.whoami, " -- ", s); +} + +func +main() { + p := new(Print); + b := new(Bio); + f := new(File); + + p.whoami = 1; + p.put = b; + + b.whoami = 2; + b.put = f; + + f.whoami = 3; + + p.dop(); + print("\n"); +} diff --git a/gcc/testsuite/go.test/test/ken/label.go b/gcc/testsuite/go.test/test/ken/label.go new file mode 100644 index 000000000..770f33e39 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/label.go @@ -0,0 +1,36 @@ +// $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 + +func +main() { + i := 0; + if false { + goto gogoloop; + } + if false { + goto gogoloop; + } + if false { + goto gogoloop; + } + goto gogoloop; + +// backward declared +loop: + i = i+1; + if i < 100 { + goto loop; + } + print(i); + print("\n"); + return; + +gogoloop: + goto loop; +} diff --git a/gcc/testsuite/go.test/test/ken/litfun.go b/gcc/testsuite/go.test/test/ken/litfun.go new file mode 100644 index 000000000..bac2bc17c --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/litfun.go @@ -0,0 +1,22 @@ +// $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 + +func +main() { + x := func(a int)int { + x := func(a int)int { + x := func(a int)int { + return a+5; + }; + return x(a)+7; + }; + return x(a)+11; + }; + if x(3) != 3+5+7+11 { panic(x(3)); } +} diff --git a/gcc/testsuite/go.test/test/ken/mfunc.go b/gcc/testsuite/go.test/test/ken/mfunc.go new file mode 100644 index 000000000..ae0bc0c58 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/mfunc.go @@ -0,0 +1,20 @@ +// $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 + +func +main() { + var x,y int; + + x,y = simple(10,20,30); + if x+y != 65 { panic(x+y); } +} + +func +simple(ia,ib,ic int) (oa,ob int) { + return ia+5, ib+ic; +} diff --git a/gcc/testsuite/go.test/test/ken/modconst.go b/gcc/testsuite/go.test/test/ken/modconst.go new file mode 100644 index 000000000..acb8831ef --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/modconst.go @@ -0,0 +1,632 @@ +// $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 "rand" + +const Count = 1e5 + +func i64rand() int64 { + for { + a := int64(rand.Uint32()) + a = (a << 32) | int64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i64test(a, b, c int64) { + d := a % c + if d != b { + println("i64", a, b, c, d) + panic("fail") + } +} + +func i64run() { + var a, b int64 + + for i := 0; i < Count; i++ { + a = i64rand() + + b = a % 1 + i64test(a, b, 1) + b = a % 2 + i64test(a, b, 2) + b = a % 3 + i64test(a, b, 3) + b = a % 4 + i64test(a, b, 4) + b = a % 5 + i64test(a, b, 5) + b = a % 6 + i64test(a, b, 6) + b = a % 7 + i64test(a, b, 7) + b = a % 8 + i64test(a, b, 8) + b = a % 10 + i64test(a, b, 10) + b = a % 16 + i64test(a, b, 16) + b = a % 20 + i64test(a, b, 20) + b = a % 32 + i64test(a, b, 32) + b = a % 60 + i64test(a, b, 60) + b = a % 64 + i64test(a, b, 64) + b = a % 128 + i64test(a, b, 128) + b = a % 256 + i64test(a, b, 256) + b = a % 16384 + i64test(a, b, 16384) + + b = a % -1 + i64test(a, b, -1) + b = a % -2 + i64test(a, b, -2) + b = a % -3 + i64test(a, b, -3) + b = a % -4 + i64test(a, b, -4) + b = a % -5 + i64test(a, b, -5) + b = a % -6 + i64test(a, b, -6) + b = a % -7 + i64test(a, b, -7) + b = a % -8 + i64test(a, b, -8) + b = a % -10 + i64test(a, b, -10) + b = a % -16 + i64test(a, b, -16) + b = a % -20 + i64test(a, b, -20) + b = a % -32 + i64test(a, b, -32) + b = a % -60 + i64test(a, b, -60) + b = a % -64 + i64test(a, b, -64) + b = a % -128 + i64test(a, b, -128) + b = a % -256 + i64test(a, b, -256) + b = a % -16384 + i64test(a, b, -16384) + } +} + +func u64rand() uint64 { + a := uint64(rand.Uint32()) + a = (a << 32) | uint64(rand.Uint32()) + a >>= uint(rand.Intn(64)) + return a +} + +func u64test(a, b, c uint64) { + d := a % c + if d != b { + println("u64", a, b, c, d) + panic("fail") + } +} + +func u64run() { + var a, b uint64 + + for i := 0; i < Count; i++ { + a = u64rand() + + b = a % 1 + u64test(a, b, 1) + b = a % 2 + u64test(a, b, 2) + b = a % 3 + u64test(a, b, 3) + b = a % 4 + u64test(a, b, 4) + b = a % 5 + u64test(a, b, 5) + b = a % 6 + u64test(a, b, 6) + b = a % 7 + u64test(a, b, 7) + b = a % 8 + u64test(a, b, 8) + b = a % 10 + u64test(a, b, 10) + b = a % 16 + u64test(a, b, 16) + b = a % 20 + u64test(a, b, 20) + b = a % 32 + u64test(a, b, 32) + b = a % 60 + u64test(a, b, 60) + b = a % 64 + u64test(a, b, 64) + b = a % 128 + u64test(a, b, 128) + b = a % 256 + u64test(a, b, 256) + b = a % 16384 + u64test(a, b, 16384) + } +} + +func i32rand() int32 { + for { + a := int32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i32test(a, b, c int32) { + d := a % c + if d != b { + println("i32", a, b, c, d) + panic("fail") + } +} + +func i32run() { + var a, b int32 + + for i := 0; i < Count; i++ { + a = i32rand() + + b = a % 1 + i32test(a, b, 1) + b = a % 2 + i32test(a, b, 2) + b = a % 3 + i32test(a, b, 3) + b = a % 4 + i32test(a, b, 4) + b = a % 5 + i32test(a, b, 5) + b = a % 6 + i32test(a, b, 6) + b = a % 7 + i32test(a, b, 7) + b = a % 8 + i32test(a, b, 8) + b = a % 10 + i32test(a, b, 10) + b = a % 16 + i32test(a, b, 16) + b = a % 20 + i32test(a, b, 20) + b = a % 32 + i32test(a, b, 32) + b = a % 60 + i32test(a, b, 60) + b = a % 64 + i32test(a, b, 64) + b = a % 128 + i32test(a, b, 128) + b = a % 256 + i32test(a, b, 256) + b = a % 16384 + i32test(a, b, 16384) + + b = a % -1 + i32test(a, b, -1) + b = a % -2 + i32test(a, b, -2) + b = a % -3 + i32test(a, b, -3) + b = a % -4 + i32test(a, b, -4) + b = a % -5 + i32test(a, b, -5) + b = a % -6 + i32test(a, b, -6) + b = a % -7 + i32test(a, b, -7) + b = a % -8 + i32test(a, b, -8) + b = a % -10 + i32test(a, b, -10) + b = a % -16 + i32test(a, b, -16) + b = a % -20 + i32test(a, b, -20) + b = a % -32 + i32test(a, b, -32) + b = a % -60 + i32test(a, b, -60) + b = a % -64 + i32test(a, b, -64) + b = a % -128 + i32test(a, b, -128) + b = a % -256 + i32test(a, b, -256) + } +} + +func u32rand() uint32 { + a := uint32(rand.Uint32()) + a >>= uint(rand.Intn(32)) + return a +} + +func u32test(a, b, c uint32) { + d := a % c + if d != b { + println("u32", a, b, c, d) + panic("fail") + } +} + +func u32run() { + var a, b uint32 + + for i := 0; i < Count; i++ { + a = u32rand() + + b = a % 1 + u32test(a, b, 1) + b = a % 2 + u32test(a, b, 2) + b = a % 3 + u32test(a, b, 3) + b = a % 4 + u32test(a, b, 4) + b = a % 5 + u32test(a, b, 5) + b = a % 6 + u32test(a, b, 6) + b = a % 7 + u32test(a, b, 7) + b = a % 8 + u32test(a, b, 8) + b = a % 10 + u32test(a, b, 10) + b = a % 16 + u32test(a, b, 16) + b = a % 20 + u32test(a, b, 20) + b = a % 32 + u32test(a, b, 32) + b = a % 60 + u32test(a, b, 60) + b = a % 64 + u32test(a, b, 64) + b = a % 128 + u32test(a, b, 128) + b = a % 256 + u32test(a, b, 256) + b = a % 16384 + u32test(a, b, 16384) + } +} + +func i16rand() int16 { + for { + a := int16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i16test(a, b, c int16) { + d := a % c + if d != b { + println("i16", a, b, c, d) + panic("fail") + } +} + +func i16run() { + var a, b int16 + + for i := 0; i < Count; i++ { + a = i16rand() + + b = a % 1 + i16test(a, b, 1) + b = a % 2 + i16test(a, b, 2) + b = a % 3 + i16test(a, b, 3) + b = a % 4 + i16test(a, b, 4) + b = a % 5 + i16test(a, b, 5) + b = a % 6 + i16test(a, b, 6) + b = a % 7 + i16test(a, b, 7) + b = a % 8 + i16test(a, b, 8) + b = a % 10 + i16test(a, b, 10) + b = a % 16 + i16test(a, b, 16) + b = a % 20 + i16test(a, b, 20) + b = a % 32 + i16test(a, b, 32) + b = a % 60 + i16test(a, b, 60) + b = a % 64 + i16test(a, b, 64) + b = a % 128 + i16test(a, b, 128) + b = a % 256 + i16test(a, b, 256) + b = a % 16384 + i16test(a, b, 16384) + + b = a % -1 + i16test(a, b, -1) + b = a % -2 + i16test(a, b, -2) + b = a % -3 + i16test(a, b, -3) + b = a % -4 + i16test(a, b, -4) + b = a % -5 + i16test(a, b, -5) + b = a % -6 + i16test(a, b, -6) + b = a % -7 + i16test(a, b, -7) + b = a % -8 + i16test(a, b, -8) + b = a % -10 + i16test(a, b, -10) + b = a % -16 + i16test(a, b, -16) + b = a % -20 + i16test(a, b, -20) + b = a % -32 + i16test(a, b, -32) + b = a % -60 + i16test(a, b, -60) + b = a % -64 + i16test(a, b, -64) + b = a % -128 + i16test(a, b, -128) + b = a % -256 + i16test(a, b, -256) + b = a % -16384 + i16test(a, b, -16384) + } +} + +func u16rand() uint16 { + a := uint16(rand.Uint32()) + a >>= uint(rand.Intn(16)) + return a +} + +func u16test(a, b, c uint16) { + d := a % c + if d != b { + println("u16", a, b, c, d) + panic("fail") + } +} + +func u16run() { + var a, b uint16 + + for i := 0; i < Count; i++ { + a = u16rand() + + b = a % 1 + u16test(a, b, 1) + b = a % 2 + u16test(a, b, 2) + b = a % 3 + u16test(a, b, 3) + b = a % 4 + u16test(a, b, 4) + b = a % 5 + u16test(a, b, 5) + b = a % 6 + u16test(a, b, 6) + b = a % 7 + u16test(a, b, 7) + b = a % 8 + u16test(a, b, 8) + b = a % 10 + u16test(a, b, 10) + b = a % 16 + u16test(a, b, 16) + b = a % 20 + u16test(a, b, 20) + b = a % 32 + u16test(a, b, 32) + b = a % 60 + u16test(a, b, 60) + b = a % 64 + u16test(a, b, 64) + b = a % 128 + u16test(a, b, 128) + b = a % 256 + u16test(a, b, 256) + b = a % 16384 + u16test(a, b, 16384) + } +} + +func i8rand() int8 { + for { + a := int8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + if -a != a { + return a + } + } + return 0 // impossible +} + +func i8test(a, b, c int8) { + d := a % c + if d != b { + println("i8", a, b, c, d) + panic("fail") + } +} + +func i8run() { + var a, b int8 + + for i := 0; i < Count; i++ { + a = i8rand() + + b = a % 1 + i8test(a, b, 1) + b = a % 2 + i8test(a, b, 2) + b = a % 3 + i8test(a, b, 3) + b = a % 4 + i8test(a, b, 4) + b = a % 5 + i8test(a, b, 5) + b = a % 6 + i8test(a, b, 6) + b = a % 7 + i8test(a, b, 7) + b = a % 8 + i8test(a, b, 8) + b = a % 10 + i8test(a, b, 10) + b = a % 8 + i8test(a, b, 8) + b = a % 20 + i8test(a, b, 20) + b = a % 32 + i8test(a, b, 32) + b = a % 60 + i8test(a, b, 60) + b = a % 64 + i8test(a, b, 64) + b = a % 127 + i8test(a, b, 127) + + b = a % -1 + i8test(a, b, -1) + b = a % -2 + i8test(a, b, -2) + b = a % -3 + i8test(a, b, -3) + b = a % -4 + i8test(a, b, -4) + b = a % -5 + i8test(a, b, -5) + b = a % -6 + i8test(a, b, -6) + b = a % -7 + i8test(a, b, -7) + b = a % -8 + i8test(a, b, -8) + b = a % -10 + i8test(a, b, -10) + b = a % -8 + i8test(a, b, -8) + b = a % -20 + i8test(a, b, -20) + b = a % -32 + i8test(a, b, -32) + b = a % -60 + i8test(a, b, -60) + b = a % -64 + i8test(a, b, -64) + b = a % -128 + i8test(a, b, -128) + b = a % -101 + i8test(a, b, -101) + } +} + +func u8rand() uint8 { + a := uint8(rand.Uint32()) + a >>= uint(rand.Intn(8)) + return a +} + +func u8test(a, b, c uint8) { + d := a % c + if d != b { + println("u8", a, b, c, d) + panic("fail") + } +} + +func u8run() { + var a, b uint8 + + for i := 0; i < Count; i++ { + a = u8rand() + + b = a % 1 + u8test(a, b, 1) + b = a % 2 + u8test(a, b, 2) + b = a % 3 + u8test(a, b, 3) + b = a % 4 + u8test(a, b, 4) + b = a % 5 + u8test(a, b, 5) + b = a % 6 + u8test(a, b, 6) + b = a % 7 + u8test(a, b, 7) + b = a % 8 + u8test(a, b, 8) + b = a % 10 + u8test(a, b, 10) + b = a % 8 + u8test(a, b, 8) + b = a % 20 + u8test(a, b, 20) + b = a % 32 + u8test(a, b, 32) + b = a % 60 + u8test(a, b, 60) + b = a % 64 + u8test(a, b, 64) + b = a % 127 + u8test(a, b, 127) + } +} + +func main() { + xtest() + i64run() + u64run() + i32run() + u32run() + i16run() + u16run() + i8run() + u8run() +} + +func xtest() { +} diff --git a/gcc/testsuite/go.test/test/ken/ptrfun.go b/gcc/testsuite/go.test/test/ken/ptrfun.go new file mode 100644 index 000000000..6739ba33a --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/ptrfun.go @@ -0,0 +1,44 @@ +// $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 + +type C struct { + a int; + x func(p *C)int; +} + +func (this *C) f()int { + return this.a; +} + +func +main() { + var v int; + var c *C; + + c = new(C); + c.a = 6; + c.x = g; + + v = g(c); + if v != 6 { panic(v); } + + v = c.x(c); + if v != 6 { panic(v); } + + v = c.f(); + if v != 6 { panic(v); } +} + +func g(p *C)int { + var v int; + + v = p.a; + if v != 6 { panic(v); } + return p.a; +} diff --git a/gcc/testsuite/go.test/test/ken/ptrvar.go b/gcc/testsuite/go.test/test/ken/ptrvar.go new file mode 100644 index 000000000..e2ddde629 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/ptrvar.go @@ -0,0 +1,53 @@ +// $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 + +type x2 struct { a,b,c int; d int; }; +var g1 x2; +var g2 struct { a,b,c int; d x2; }; + +func +main() { + var x int; + var s1 *x2; + var s2 *struct { a,b,c int; d x2; }; + + s1 = &g1; + s2 = &g2; + + s1.a = 1; + s1.b = 2; + s1.c = 3; + s1.d = 5; + + s2.a = 7; + s2.b = 11; + s2.c = 13; + s2.d.a = 17; + s2.d.b = 19; + s2.d.c = 23; + s2.d.d = 20; + + if(s2.d.c != 23) { panic(1); } + if(g2.d.c != 23) { panic(2); } + + x = s1.a + + s1.b + + s1.c + + s1.d + + + s2.a + + s2.b + + s2.c + + s2.d.a + + s2.d.b + + s2.d.c + + s2.d.d; + + if(x != 121) { panic(x); } +} diff --git a/gcc/testsuite/go.test/test/ken/range.go b/gcc/testsuite/go.test/test/ken/range.go new file mode 100644 index 000000000..9535fd497 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/range.go @@ -0,0 +1,119 @@ +// $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 + +const size = 16 + +var a [size]byte +var p []byte +var m map[int]byte + +func f(k int) byte { + return byte(k * 10007 % size) +} + +func init() { + p = make([]byte, size) + m = make(map[int]byte) + for k := 0; k < size; k++ { + v := f(k) + a[k] = v + p[k] = v + m[k] = v + } +} + +func main() { + var i int + + /* + * key only + */ + i = 0 + for k := range a { + v := a[k] + if v != f(k) { + println("key array range", k, v, a[k]) + panic("fail") + } + i++ + } + if i != size { + println("key array size", i) + panic("fail") + } + + i = 0 + for k := range p { + v := p[k] + if v != f(k) { + println("key pointer range", k, v, p[k]) + panic("fail") + } + i++ + } + if i != size { + println("key pointer size", i) + panic("fail") + } + + i = 0 + for k := range m { + v := m[k] + if v != f(k) { + println("key map range", k, v, m[k]) + panic("fail") + } + i++ + } + if i != size { + println("key map size", i) + panic("fail") + } + + /* + * key,value + */ + i = 0 + for k, v := range a { + if v != f(k) { + println("key:value array range", k, v, a[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value array size", i) + panic("fail") + } + + i = 0 + for k, v := range p { + if v != f(k) { + println("key:value pointer range", k, v, p[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value pointer size", i) + panic("fail") + } + + i = 0 + for k, v := range m { + if v != f(k) { + println("key:value map range", k, v, m[k]) + panic("fail") + } + i++ + } + if i != size { + println("key:value map size", i) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/rob1.go b/gcc/testsuite/go.test/test/ken/rob1.go new file mode 100644 index 000000000..03350662a --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/rob1.go @@ -0,0 +1,67 @@ +// $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 + +type Item interface { + Print(); +} + +type ListItem struct { + item Item; + next *ListItem; +} + +type List struct { + head *ListItem; +} + +func (list *List) Init() { + list.head = nil; +} + +func (list *List) Insert(i Item) { + item := new(ListItem); + item.item = i; + item.next = list.head; + list.head = item; +} + +func (list *List) Print() { + i := list.head; + for i != nil { + i.item.Print(); + i = i.next; + } +} + +// Something to put in a list +type Integer struct { + val int; +} + +func (this *Integer) Init(i int) *Integer { + this.val = i; + return this; +} + +func (this *Integer) Print() { + print(this.val); +} + +func +main() { + list := new(List); + list.Init(); + for i := 0; i < 10; i = i + 1 { + integer := new(Integer); + integer.Init(i); + list.Insert(integer); + } + + list.Print(); + print("\n"); +} diff --git a/gcc/testsuite/go.test/test/ken/rob2.go b/gcc/testsuite/go.test/test/ken/rob2.go new file mode 100644 index 000000000..af63e4d9f --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/rob2.go @@ -0,0 +1,272 @@ +// $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 + +const nilchar = 0; + +type Atom struct { + str string; + integer int; + next *Slist; /* in hash bucket */ +} + +type List struct { + car *Slist; + cdr*Slist; +} + +type Slist struct { + isatom bool; + isstring bool; + //union { + atom Atom; + list List; + //} u; + +} + +func (this *Slist) Car() *Slist { + return this.list.car; +} + +func (this *Slist) Cdr() *Slist { + return this.list.cdr; +} + +func (this *Slist) String() string { + return this.atom.str; +} + +func (this *Slist) Integer() int { + return this.atom.integer; +} + +func (slist *Slist) Free() { + if slist == nil { + return; + } + if slist.isatom { +// free(slist.String()); + } else { + slist.Car().Free(); + slist.Cdr().Free(); + } +// free(slist); +} + +//Slist* atom(byte *s, int i); + +var token int; +var peekc int = -1; +var lineno int32 = 1; + +var input string; +var inputindex int = 0; +var tokenbuf [100]byte; +var tokenlen int = 0; + +const EOF int = -1; + +func main() { + var list *Slist; + + OpenFile(); + for ;; { + list = Parse(); + if list == nil { + break; + } + list.Print(); + list.Free(); + break; + } +} + +func (slist *Slist) PrintOne(doparen bool) { + if slist == nil { + return; + } + if slist.isatom { + if slist.isstring { + print(slist.String()); + } else { + print(slist.Integer()); + } + } else { + if doparen { + print("(" ); + } + slist.Car().PrintOne(true); + if slist.Cdr() != nil { + print(" "); + slist.Cdr().PrintOne(false); + } + if doparen { + print(")"); + } + } +} + +func (slist *Slist) Print() { + slist.PrintOne(true); + print("\n"); +} + +func Get() int { + var c int; + + if peekc >= 0 { + c = peekc; + peekc = -1; + } else { + c = int(input[inputindex]); + inputindex++; + if c == '\n' { + lineno = lineno + 1; + } + if c == nilchar { + inputindex = inputindex - 1; + c = EOF; + } + } + return c; +} + +func WhiteSpace(c int) bool { + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +} + +func NextToken() { + var i, c int; + + tokenbuf[0] = nilchar; // clear previous token + c = Get(); + for WhiteSpace(c) { + c = Get(); + } + switch c { + case EOF: + token = EOF; + case '(', ')': + token = c; + break; + default: + for i = 0; i < 100 - 1; { // sizeof tokenbuf - 1 + tokenbuf[i] = byte(c); + i = i + 1; + c = Get(); + if c == EOF { + break; + } + if WhiteSpace(c) || c == ')' { + peekc = c; + break; + } + } + if i >= 100 - 1 { // sizeof tokenbuf - 1 + panic("atom too long\n"); + } + tokenlen = i; + tokenbuf[i] = nilchar; + if '0' <= tokenbuf[0] && tokenbuf[0] <= '9' { + token = '0'; + } else { + token = 'A'; + } + } +} + +func Expect(c int) { + if token != c { + print("parse error: expected ", c, "\n"); + panic("parse"); + } + NextToken(); +} + +// Parse a non-parenthesized list up to a closing paren or EOF +func ParseList() *Slist { + var slist, retval *Slist; + + slist = new(Slist); + slist.list.car = nil; + slist.list.cdr = nil; + slist.isatom = false; + slist.isstring = false; + + retval = slist; + for ;; { + slist.list.car = Parse(); + if token == ')' || token == EOF { // empty cdr + break; + } + slist.list.cdr = new(Slist); + slist = slist.list.cdr; + } + return retval; +} + +func atom(i int) *Slist { // BUG: uses tokenbuf; should take argument) + var slist *Slist; + + slist = new(Slist); + if token == '0' { + slist.atom.integer = i; + slist.isstring = false; + } else { + slist.atom.str = string(tokenbuf[0:tokenlen]); + slist.isstring = true; + } + slist.isatom = true; + return slist; +} + +func atoi() int { // BUG: uses tokenbuf; should take argument) + var v int = 0; + for i := 0; i < tokenlen && '0' <= tokenbuf[i] && tokenbuf[i] <= '9'; i = i + 1 { + v = 10 * v + int(tokenbuf[i] - '0'); + } + return v; +} + +func Parse() *Slist { + var slist *Slist; + + if token == EOF || token == ')' { + return nil; + } + if token == '(' { + NextToken(); + slist = ParseList(); + Expect(')'); + return slist; + } else { + // Atom + switch token { + case EOF: + return nil; + case '0': + slist = atom(atoi()); + case '"', 'A': + slist = atom(0); + default: + slist = nil; + print("unknown token: ", token, "\n"); + } + NextToken(); + return slist; + } + return nil; +} + +func OpenFile() { + input = "(defn foo (add 12 34))\n\x00"; + inputindex = 0; + peekc = -1; // BUG + NextToken(); +} diff --git a/gcc/testsuite/go.test/test/ken/robfor.go b/gcc/testsuite/go.test/test/ken/robfor.go new file mode 100644 index 000000000..05188a472 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/robfor.go @@ -0,0 +1,56 @@ +// $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 + +func assertequal(is, shouldbe int, msg string) { + if is != shouldbe { + print("assertion fail" + msg + "\n"); + panic(1); + } +} + +func main() { + var i, sum int; + + i = 0; + for { + i = i + 1; + if i > 5 { + break; + } + } + assertequal(i, 6, "break"); + + sum = 0; + for i := 0; i <= 10; i++ { + sum = sum + i; + } + assertequal(sum, 55, "all three"); + + sum = 0; + for i := 0; i <= 10; { + sum = sum + i; + i++; + } + assertequal(sum, 55, "only two"); + + sum = 0; + for sum < 100 { + sum = sum + 9; + } + assertequal(sum, 99 + 9, "only one"); + + sum = 0; + for i := 0; i <= 10; i++ { + if i % 2 == 0 { + continue; + } + sum = sum + i; + } + assertequal(sum, 1+3+5+7+9, "continue"); + +} diff --git a/gcc/testsuite/go.test/test/ken/robfunc.go b/gcc/testsuite/go.test/test/ken/robfunc.go new file mode 100644 index 000000000..6b3d4b2e4 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/robfunc.go @@ -0,0 +1,94 @@ +// $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 + +func assertequal(is, shouldbe int, msg string) { + if is != shouldbe { + print("assertion fail" + msg + "\n") + panic(1) + } +} + +func f1() { +} + +func f2(a int) { +} + +func f3(a, b int) int { + return a + b +} + +func f4(a, b int, c float64) int { + return (a+b)/2 + int(c) +} + +func f5(a int) int { + return 5 +} + +func f6(a int) (r int) { + return 6 +} + +func f7(a int) (x int, y float64) { + return 7, 7.0 +} + + +func f8(a int) (x int, y float64) { + return 8, 8.0 +} + +type T struct { + x, y int +} + +func (t *T) m10(a int, b float64) int { + return (t.x + a) * (t.y + int(b)) +} + + +func f9(a int) (in int, fl float64) { + i := 9 + f := float64(9) + return i, f +} + + +func main() { + f1() + f2(1) + r3 := f3(1, 2) + assertequal(r3, 3, "3") + r4 := f4(0, 2, 3.0) + assertequal(r4, 4, "4") + r5 := f5(1) + assertequal(r5, 5, "5") + r6 := f6(1) + assertequal(r6, 6, "6") + var r7 int + var s7 float64 + r7, s7 = f7(1) + assertequal(r7, 7, "r7") + assertequal(int(s7), 7, "s7") + var r8 int + var s8 float64 + r8, s8 = f8(1) + assertequal(r8, 8, "r8") + assertequal(int(s8), 8, "s8") + var r9 int + var s9 float64 + r9, s9 = f9(1) + assertequal(r9, 9, "r9") + assertequal(int(s9), 9, "s9") + var t *T = new(T) + t.x = 1 + t.y = 2 + r10 := t.m10(1, 3.0) + assertequal(r10, 10, "10") +} diff --git a/gcc/testsuite/go.test/test/ken/robif.go b/gcc/testsuite/go.test/test/ken/robif.go new file mode 100644 index 000000000..b6fe4e433 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/robif.go @@ -0,0 +1,97 @@ +// $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 + +func assertequal(is, shouldbe int, msg string) { + if is != shouldbe { + print("assertion fail" + msg + "\n"); + panic(1); + } +} + +func main() { + i5 := 5; + i7 := 7; + + var count int; + + count = 0; + if true { + count = count + 1; + } + assertequal(count, 1, "if true"); + + count = 0; + if false { + count = count + 1; + } + assertequal(count, 0, "if false"); + + count = 0; + if one := 1; true { + count = count + one; + } + assertequal(count, 1, "if true one"); + + count = 0; + if one := 1; false { + _ = one; + count = count + 1; + } + assertequal(count, 0, "if false one"); + + count = 0; + if { + count = count + 1; + } + assertequal(count, 1, "if empty"); + + count = 0; + if one := 1; { + count = count + one; + } + assertequal(count, 1, "if empty one"); + + count = 0; + if i5 < i7 { + count = count + 1; + } + assertequal(count, 1, "if cond"); + + count = 0; + if true { + count = count + 1; + } else + count = count - 1; + assertequal(count, 1, "if else true"); + + count = 0; + if false { + count = count + 1; + } else + count = count - 1; + assertequal(count, -1, "if else false"); + + count = 0; + if t:=1; false { + count = count + 1; + t := 7; + _ = t; + } else + count = count - t; + assertequal(count, -1, "if else false var"); + + count = 0; + t := 1; + if false { + count = count + 1; + t := 7; + _ = t; + } else + count = count - t; + assertequal(count, -1, "if else false var outside"); +} diff --git a/gcc/testsuite/go.test/test/ken/shift.go b/gcc/testsuite/go.test/test/ken/shift.go new file mode 100644 index 000000000..157a07aec --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/shift.go @@ -0,0 +1,119 @@ +// $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 + +var ians [18]int; +var uans [18]uint; +var pass string; + +func +testi(i int, t1,t2,t3 int) { + n := ((t1*3) + t2)*2 + t3; + if i != ians[n] { + print("itest ", t1,t2,t3,pass, + " is ", i, " sb ", ians[n], "\n"); + } +} + +func +index(t1,t2,t3 int) int { + return ((t1*3) + t2)*2 + t3; +} + +func +testu(u uint, t1,t2,t3 int) { + n := index(t1,t2,t3); + if u != uans[n] { + print("utest ", t1,t2,t3,pass, + " is ", u, " sb ", uans[n], "\n"); + } +} + +func +main() { + var i int; + var u,c uint; + + /* + * test constant evaluations + */ + pass = "con"; // constant part + + testi( int(1234) << 0, 0,0,0); + testi( int(1234) >> 0, 0,0,1); + testi( int(1234) << 5, 0,1,0); + testi( int(1234) >> 5, 0,1,1); + + testi(int(-1234) << 0, 1,0,0); + testi(int(-1234) >> 0, 1,0,1); + testi(int(-1234) << 5, 1,1,0); + testi(int(-1234) >> 5, 1,1,1); + + testu(uint(5678) << 0, 2,0,0); + testu(uint(5678) >> 0, 2,0,1); + testu(uint(5678) << 5, 2,1,0); + testu(uint(5678) >> 5, 2,1,1); + + /* + * test variable evaluations + */ + pass = "var"; // variable part + + for t1:=0; t1<3; t1++ { // +int, -int, uint + for t2:=0; t2<3; t2++ { // 0, +small, +large + for t3:=0; t3<2; t3++ { // <<, >> + switch t1 { + case 0: i = 1234; + case 1: i = -1234; + case 2: u = 5678; + } + switch t2 { + case 0: c = 0; + case 1: c = 5; + case 2: c = 1025; + } + switch t3 { + case 0: i <<= c; u <<= c; + case 1: i >>= c; u >>= c; + } + switch t1 { + case 0: testi(i,t1,t2,t3); + case 1: testi(i,t1,t2,t3); + case 2: testu(u,t1,t2,t3); + } + } + } + } +} + +func +init() { + /* + * set the 'correct' answer + */ + + ians[index(0,0,0)] = 1234; + ians[index(0,0,1)] = 1234; + ians[index(0,1,0)] = 39488; + ians[index(0,1,1)] = 38; + ians[index(0,2,0)] = 0; + ians[index(0,2,1)] = 0; + + ians[index(1,0,0)] = -1234; + ians[index(1,0,1)] = -1234; + ians[index(1,1,0)] = -39488; + ians[index(1,1,1)] = -39; + ians[index(1,2,0)] = 0; + ians[index(1,2,1)] = -1; + + uans[index(2,0,0)] = 5678; + uans[index(2,0,1)] = 5678; + uans[index(2,1,0)] = 181696; + uans[index(2,1,1)] = 177; + uans[index(2,2,0)] = 0; + uans[index(2,2,1)] = 0; +} diff --git a/gcc/testsuite/go.test/test/ken/simparray.go b/gcc/testsuite/go.test/test/ken/simparray.go new file mode 100644 index 000000000..1b6f245ee --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simparray.go @@ -0,0 +1,48 @@ +// $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 + +var b[10] float32; + +func +main() { + var a[10] float32; + + for i:=int16(5); i<10; i=i+1 { + a[i] = float32(i); + } + + s1 := float32(0); + for i:=5; i<10; i=i+1 { + s1 = s1 + a[i]; + } + + if s1 != 35 { panic(s1); } + + for i:=int16(5); i<10; i=i+1 { + b[i] = float32(i); + } + + s2 := float32(0); + for i:=5; i<10; i=i+1 { + s2 = s2 + b[i]; + } + + if s2 != 35 { panic(s2); } + + b := new([100]int); + for i:=0; i<100; i=i+1 { + b[i] = i; + } + + s3 := 0; + for i:=0; i<100; i=i+1 { + s3 = s3+b[i]; + } + + if s3 != 4950 { panic(s3); } +} diff --git a/gcc/testsuite/go.test/test/ken/simpbool.go b/gcc/testsuite/go.test/test/ken/simpbool.go new file mode 100644 index 000000000..dbd9c8d8b --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpbool.go @@ -0,0 +1,105 @@ +// $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 + +type s struct { + a bool; + b bool; +} + +func +main() { + var a,b bool; + + a = true; + b = false; + + if !a { panic(1); } + if b { panic(2); } + if !!!a { panic(3); } + if !!b { panic(4); } + + a = !b; + if !a { panic(5); } + if !!!a { panic(6); } + + var x *s; + x = new(s); + x.a = true; + x.b = false; + + if !x.a { panic(7); } + if x.b { panic(8); } + if !!!x.a { panic(9); } + if !!x.b { panic(10); } + + x.a = !x.b; + if !x.a { panic(11); } + if !!!x.a { panic(12); } + + /* + * test && + */ + a = true; + b = true; + if !(a && b) { panic(21); } + if a && !b { panic(22); } + if !a && b { panic(23); } + if !a && !b { panic(24); } + + a = false; + b = true; + if !(!a && b) { panic(31); } + if !a && !b { panic(32); } + if a && b { panic(33); } + if a && !b { panic(34); } + + a = true; + b = false; + if !(a && !b) { panic(41); } + if a && b { panic(41); } + if !a && !b { panic(41); } + if !a && b { panic(44); } + + a = false; + b = false; + if !(!a && !b) { panic(51); } + if !a && b { panic(52); } + if a && !b { panic(53); } + if a && b { panic(54); } + + /* + * test || + */ + a = true; + b = true; + if !(a || b) { panic(61); } + if !(a || !b) { panic(62); } + if !(!a || b) { panic(63); } + if !a || !b { panic(64); } + + a = false; + b = true; + if !(!a || b) { panic(71); } + if !(!a || !b) { panic(72); } + if !(a || b) { panic(73); } + if a || !b { panic(74); } + + a = true; + b = false; + if !(a || !b) { panic(81); } + if !(a || b) { panic(82); } + if !(!a || !b) { panic(83); } + if !a || b { panic(84); } + + a = false; + b = false; + if !(!a || !b) { panic(91); } + if !(!a || b) { panic(92); } + if !(a || !b) { panic(93); } + if a || b { panic(94); } +} diff --git a/gcc/testsuite/go.test/test/ken/simpconv.go b/gcc/testsuite/go.test/test/ken/simpconv.go new file mode 100644 index 000000000..feb85d299 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpconv.go @@ -0,0 +1,28 @@ +// $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 + +type vlong int64 +type short int16 + +func main() { + s1 := vlong(0) + for i := short(0); i < 10; i = i + 1 { + s1 = s1 + vlong(i) + } + if s1 != 45 { + panic(s1) + } + + s2 := float64(0) + for i := 0; i < 10; i = i + 1 { + s2 = s2 + float64(i) + } + if s2 != 45 { + panic(s2) + } +} diff --git a/gcc/testsuite/go.test/test/ken/simpfun.go b/gcc/testsuite/go.test/test/ken/simpfun.go new file mode 100644 index 000000000..ba9ce6f7b --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpfun.go @@ -0,0 +1,25 @@ +// $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 + +func +main() { + var x int; + + x = fun(10,20,30); + if x != 60 { panic(x); } +} + +func +fun(ia,ib,ic int)int { + var o int; + + o = ia+ib+ic; + if o != 60 { panic(o); } + return o; +} diff --git a/gcc/testsuite/go.test/test/ken/simpprint.go b/gcc/testsuite/go.test/test/ken/simpprint.go new file mode 100644 index 000000000..6077f7eb0 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpprint.go @@ -0,0 +1,13 @@ +// $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 + +func +main() { + print("hello world\n"); +} diff --git a/gcc/testsuite/go.test/test/ken/simpswitch.go b/gcc/testsuite/go.test/test/ken/simpswitch.go new file mode 100644 index 000000000..ab5dd356b --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpswitch.go @@ -0,0 +1,24 @@ +// $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 + +func +main() { + a := 3; + for i:=0; i<10; i=i+1 { + switch(i) { + case 5: + print("five"); + case a,7: + print("a"); + default: + print(i); + } + print("out", i); + } + print("\n"); +} diff --git a/gcc/testsuite/go.test/test/ken/simpvar.go b/gcc/testsuite/go.test/test/ken/simpvar.go new file mode 100644 index 000000000..fd060b0e2 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/simpvar.go @@ -0,0 +1,25 @@ +// $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 + +var x,y int; + +func +main() { + + x = 15; + y = 20; + { + var x int; + x = 25; + y = 25; + _ = x; + } + x = x+y; + if(x != 40) { panic(x); } +} diff --git a/gcc/testsuite/go.test/test/ken/slicearray.go b/gcc/testsuite/go.test/test/ken/slicearray.go new file mode 100644 index 000000000..5c31270fc --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/slicearray.go @@ -0,0 +1,210 @@ +// $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 + +var bx [10]byte +var by []byte +var fx [10]float64 +var fy []float64 +var lb, hb int +var t int + +func main() { + lb = 0 + hb = 10 + by = bx[0:] + tstb() + + lb = 0 + hb = 10 + fy = fx[0:] + tstf() + + // width 1 (byte) + lb = 0 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[:hb] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:10] + tstb() + by = bx[0:] + tstb() + by = bx[:10] + tstb() + by = bx[:] + tstb() + + lb = 2 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:10] + tstb() + by = bx[2:] + tstb() + + lb = 0 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:8] + tstb() + by = bx[:8] + tstb() + by = bx[:hb] + tstb() + + lb = 2 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:8] + tstb() + + // width 4 (float64) + lb = 0 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:10] + tstf() + fy = fx[0:] + tstf() + fy = fx[:10] + tstf() + fy = fx[:] + tstf() + + lb = 2 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:10] + tstf() + fy = fx[2:] + tstf() + + lb = 0 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:8] + tstf() + fy = fx[:8] + tstf() + + lb = 2 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:8] + tstf() +} + +func tstb() { + t++ + if len(by) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(by), "hb-lb=", hb-lb) + panic("fail") + } + if cap(by) != len(bx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(by), "len(bx)-lb=", len(bx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if bx[i] != by[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "bx[", i, "]=", bx[i], + "by[", i-lb, "]=", by[i-lb]) + panic("fail") + } + } + by = nil +} + +func tstf() { + t++ + if len(fy) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(fy), "hb-lb=", hb-lb) + panic("fail") + } + if cap(fy) != len(fx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(fy), "len(fx)-lb=", len(fx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if fx[i] != fy[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "fx[", i, "]=", fx[i], + "fy[", i-lb, "]=", fy[i-lb]) + panic("fail") + } + } + fy = nil +} + +func init() { + for i := 0; i < len(bx); i++ { + bx[i] = byte(i + 20) + } + by = nil + + for i := 0; i < len(fx); i++ { + fx[i] = float64(i + 20) + } + fy = nil +} diff --git a/gcc/testsuite/go.test/test/ken/sliceslice.go b/gcc/testsuite/go.test/test/ken/sliceslice.go new file mode 100644 index 000000000..639042128 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/sliceslice.go @@ -0,0 +1,203 @@ +// $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 + +var bx []byte +var by []byte +var fx []float64 +var fy []float64 +var lb, hb int +var t int + +func main() { + + // width 1 (byte) + lb = 0 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[:hb] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:10] + tstb() + by = bx[0:] + tstb() + by = bx[:10] + tstb() + by = bx[:] + tstb() + + lb = 2 + hb = 10 + by = bx[lb:hb] + tstb() + by = bx[lb:10] + tstb() + by = bx[lb:] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:10] + tstb() + by = bx[2:] + tstb() + + lb = 0 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[0:hb] + tstb() + by = bx[0:8] + tstb() + by = bx[:8] + tstb() + by = bx[:hb] + tstb() + + lb = 2 + hb = 8 + by = bx[lb:hb] + tstb() + by = bx[lb:8] + tstb() + by = bx[2:hb] + tstb() + by = bx[2:8] + tstb() + + // width 4 (float64) + lb = 0 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:10] + tstf() + fy = fx[0:] + tstf() + fy = fx[:10] + tstf() + fy = fx[:] + tstf() + + lb = 2 + hb = 10 + fy = fx[lb:hb] + tstf() + fy = fx[lb:10] + tstf() + fy = fx[lb:] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:10] + tstf() + fy = fx[2:] + tstf() + + lb = 0 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[:hb] + tstf() + fy = fx[0:hb] + tstf() + fy = fx[0:8] + tstf() + fy = fx[:8] + tstf() + + lb = 2 + hb = 8 + fy = fx[lb:hb] + tstf() + fy = fx[lb:8] + tstf() + fy = fx[2:hb] + tstf() + fy = fx[2:8] + tstf() +} + +func tstb() { + t++ + if len(by) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(by), "hb-lb=", hb-lb) + panic("fail") + } + if cap(by) != len(bx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(by), "len(bx)-lb=", len(bx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if bx[i] != by[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "bx[", i, "]=", bx[i], + "by[", i-lb, "]=", by[i-lb]) + panic("fail") + } + } + by = nil +} + +func tstf() { + t++ + if len(fy) != hb-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "len=", len(fy), "hb-lb=", hb-lb) + panic("fail") + } + if cap(fy) != len(fx)-lb { + println("t=", t, "lb=", lb, "hb=", hb, + "cap=", cap(fy), "len(fx)-lb=", len(fx)-lb) + panic("fail") + } + for i := lb; i < hb; i++ { + if fx[i] != fy[i-lb] { + println("t=", t, "lb=", lb, "hb=", hb, + "fx[", i, "]=", fx[i], + "fy[", i-lb, "]=", fy[i-lb]) + panic("fail") + } + } + fy = nil +} + +func init() { + bx = make([]byte, 10) + for i := 0; i < len(bx); i++ { + bx[i] = byte(i + 20) + } + by = nil + + fx = make([]float64, 10) + for i := 0; i < len(fx); i++ { + fx[i] = float64(i + 20) + } + fy = nil +} diff --git a/gcc/testsuite/go.test/test/ken/string.go b/gcc/testsuite/go.test/test/ken/string.go new file mode 100644 index 000000000..cbedad4e8 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/string.go @@ -0,0 +1,118 @@ +// $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 + +func main() { + var c string + + a := `abc` + b := `xyz` + + /* print a literal */ + print(`abc`) + + /* print a variable */ + print(b, "-") + + /* catenate literals */ + print(`abc`+`xyz`, "-") + + /* catenate variables */ + print(a+b, "-") + + /* compare literals */ + if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` { + panic("compare literals") + } + + /* compare variables */ + if a == b || a != a || a > b { + panic("compare variables") + } + + /* cat */ + c = a + b + print(c, "-") + + /* catequal */ + c = a + c += b + print(c, "-") + + /* clumsy evaluation */ + c = b + c = a + c + print(c, "-") + + /* len */ + if len(c) != 6 { + print("len ", len(c)) + panic("fail") + } + + /* index strings */ + for i := 0; i < len(c); i = i + 1 { + if c[i] != (a + b)[i] { + print("index ", i, " ", c[i], " ", (a + b)[i]) + panic("fail") + } + } + + /* slice strings */ + print(c[0:3], c[3:]) + + print("\n") + + /* create string with integer constant */ + c = string('x') + if c != "x" { + print("create int ", c) + panic("fail") + } + + /* create string with integer variable */ + v := 'x' + c = string(v) + if c != "x" { + print("create int ", c) + panic("fail") + } + + /* create string with byte array */ + var z1 [3]byte + z1[0] = 'a' + z1[1] = 'b' + z1[2] = 'c' + c = string(z1[0:]) + if c != "abc" { + print("create byte array ", c) + panic("fail") + } + + /* create string with int array */ + var z2 [3]int + z2[0] = 'a' + z2[1] = '\u1234' + z2[2] = 'c' + c = string(z2[0:]) + if c != "a\u1234c" { + print("create int array ", c) + panic("fail") + } + + /* create string with byte array pointer */ + z3 := new([3]byte) + z3[0] = 'a' + z3[1] = 'b' + z3[2] = 'c' + c = string(z3[0:]) + if c != "abc" { + print("create array pointer ", c) + panic("fail") + } +} diff --git a/gcc/testsuite/go.test/test/ken/strvar.go b/gcc/testsuite/go.test/test/ken/strvar.go new file mode 100644 index 000000000..dfaaf1213 --- /dev/null +++ b/gcc/testsuite/go.test/test/ken/strvar.go @@ -0,0 +1,78 @@ +// $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 + +type x2 struct { a,b,c int; d int; }; +var g1 x2; +var g2 struct { a,b,c int; d x2; }; + +func +main() { + var x int; + var s1 *x2; + var s2 *struct { a,b,c int; d x2; }; + var s3 struct { a,b,c int; d x2; }; + + s1 = &g1; + s2 = &g2; + + s1.a = 1; + s1.b = 2; + s1.c = 3; + s1.d = 5; + + if(s1.c != 3) { panic(s1.c); } + if(g1.c != 3) { panic(g1.c); } + + s2.a = 7; + s2.b = 11; + s2.c = 13; + s2.d.a = 17; + s2.d.b = 19; + s2.d.c = 23; + s2.d.d = 29; + + if(s2.d.c != 23) { panic(s2.d.c); } + if(g2.d.c != 23) { panic(g2.d.c); } + + x = s1.a + + s1.b + + s1.c + + s1.d + + + s2.a + + s2.b + + s2.c + + s2.d.a + + s2.d.b + + s2.d.c + + s2.d.d; + + if(x != 130) { panic(x); } + + // test an automatic struct + s3.a = 7; + s3.b = 11; + s3.c = 13; + s3.d.a = 17; + s3.d.b = 19; + s3.d.c = 23; + s3.d.d = 29; + + if(s3.d.c != 23) { panic(s3.d.c); } + + x = s3.a + + s3.b + + s3.c + + s3.d.a + + s3.d.b + + s3.d.c + + s3.d.d; + + if(x != 119) { panic(x); } +} |