See commit comment and ChangeLog for details. Ciao
Dominik ^_^ ^_^ -- Dominik Vogt IBM Germany
gcc/testsuite/ChangeLog 2014-11-04 Dominik Vogt <v...@linux.vnet.ibm.com> * go.test/test/ken/cplx2.go: Fix s390 test failures. 2014-11-04 Dominik Vogt <v...@linux.vnet.ibm.com> * go.test/test/nilptr_s390.go: Port nilptr.go to s390. * go.test/test/nilptr_s390x.go: Port nilptr.go to s390x. * go.test/test/nilptr.go: Do not run on s390/s390x. * go.test/go-test.exp: "// +build " matches complete words without whitespace. This is rnecessary to distinguish s390 from s390x. It also handles negation with the '!' prefix. 2014-11-04 Dominik Vogt <v...@linux.vnet.ibm.com> * go.test/go-test.exp (go-set-goarch): Enable tests on s390[x]. 2014-11-04 Dominik Vogt <v...@linux.vnet.ibm.com> * go.test/go-test.exp: Add handling of "// +build".
>From 5b0eaf73d005bd152fff5a1a922f5618da4be939 Mon Sep 17 00:00:00 2001 From: Dominik Vogt <v...@linux.vnet.ibm.com> Date: Tue, 4 Nov 2014 10:13:22 +0100 Subject: [PATCH 4/4] go.test: Changes required for s390[x] port. 1) Add Go architectures s390 and s390x. 2) Do not run test nilptr.go on s390 -> platform specific test. * Detects word boundaries to distinguish between s390 and s390x. (Switch to using regular expressions.) * Implement the Prefix '!' to exclude targets from build. 3) Fix go/test/ken/cplx2.go test failures. --- gcc/testsuite/go.test/go-test.exp | 6 + gcc/testsuite/go.test/test/ken/cplx2.go | 20 ++- gcc/testsuite/go.test/test/nilptr.go | 1 + gcc/testsuite/go.test/test/nilptr_s390.go | 190 +++++++++++++++++++++++++++++ gcc/testsuite/go.test/test/nilptr_s390x.go | 190 +++++++++++++++++++++++++++++ 5 files changed, 405 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/go.test/test/nilptr_s390.go create mode 100644 gcc/testsuite/go.test/test/nilptr_s390x.go diff --git a/gcc/testsuite/go.test/go-test.exp b/gcc/testsuite/go.test/go-test.exp index 71272a3..25e405b 100644 --- a/gcc/testsuite/go.test/go-test.exp +++ b/gcc/testsuite/go.test/go-test.exp @@ -244,6 +244,12 @@ proc go-set-goarch { } { set goarch "ppc64" } } + "s390-*-*" { + set goarch "s390" + } + "s390x-*-*" { + set goarch "s390x" + } "sparc*-*-*" { if [check_effective_target_ilp32] { set goarch "sparc" diff --git a/gcc/testsuite/go.test/test/ken/cplx2.go b/gcc/testsuite/go.test/test/ken/cplx2.go index eb1da7b..d11e33c 100644 --- a/gcc/testsuite/go.test/test/ken/cplx2.go +++ b/gcc/testsuite/go.test/test/ken/cplx2.go @@ -97,13 +97,29 @@ func main() { } cd := c5 / c6 - if cd != Cd { + dr := real(Cd) - real(cd) + if dr < 0 { + dr = -dr + } + di := imag(Cd) - imag(cd) + if di < 0 { + di = -di + } + if dr > .000000059604644775390625 || di > 0 { println("opcode x", cd, Cd) panic("fail") } ce := cd * c6 - if ce != Ce { + dr = real(Ce) - real(ce) + if dr < 0 { + dr = -dr + } + di = imag(Ce) - imag(ce) + if di < 0 { + di = -di + } + if dr > 0 || di > 0.00000095367431640625 { println("opcode x", ce, Ce) panic("fail") } diff --git a/gcc/testsuite/go.test/test/nilptr.go b/gcc/testsuite/go.test/test/nilptr.go index 9631d16..574d662 100644 --- a/gcc/testsuite/go.test/test/nilptr.go +++ b/gcc/testsuite/go.test/test/nilptr.go @@ -1,3 +1,4 @@ +// +build !s390 !s390x // run // Copyright 2011 The Go Authors. All rights reserved. diff --git a/gcc/testsuite/go.test/test/nilptr_s390.go b/gcc/testsuite/go.test/test/nilptr_s390.go new file mode 100644 index 0000000..d79916d --- /dev/null +++ b/gcc/testsuite/go.test/test/nilptr_s390.go @@ -0,0 +1,190 @@ +// +build s390 +// run + +// Copyright 2011 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. + +// Test that the implementation catches nil ptr indirection in a +// large address space. + +package main + +import "unsafe" + +// Having a big address space means that indexing at a large +// offset from a nil pointer might not cause a memory access +// fault. This test checks that Go is doing the correct explicit +// checks to catch these nil pointer accesses, not just relying on +// the hardware. +// +// Give us a big address space somewhere near min_bss_offset. +const in_mem_size uintptr = 256 << 20 // 256 MiB +const min_bss_offset uintptr = 1 << 22 // 0x00400000 +const maxlen uintptr = (1 << 31) - 2 // 0x7ffffffe +var dummy [in_mem_size]byte + +func main() { + // The test only tests what we intend to test if dummy + // starts near 0x0040000. Otherwise there might not be + // anything mapped at the address that might be + // accidentally dereferenced below. + if uintptr(unsafe.Pointer(&dummy)) > in_mem_size + min_bss_offset { + panic("dummy too far out") + } else if uintptr(unsafe.Pointer(&dummy)) < min_bss_offset { + panic("dummy too close") + } + + shouldPanic(p1) + shouldPanic(p2) + shouldPanic(p3) + shouldPanic(p4) + shouldPanic(p5) + shouldPanic(p6) + shouldPanic(p7) + shouldPanic(p8) + shouldPanic(p9) + shouldPanic(p10) + shouldPanic(p11) + shouldPanic(p12) + shouldPanic(p13) + shouldPanic(p14) + shouldPanic(p15) + shouldPanic(p16) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("memory reference did not panic") + } + }() + f() +} + +func p1() { + // Array index. + var p *[maxlen]byte = nil + // very likely to be inside dummy, but should panic + println(p[min_bss_offset + in_mem_size / 2]) +} + +var xb byte + +func p2() { + var p *[maxlen]byte = nil + xb = 123 + + // Array index. + println(p[uintptr(unsafe.Pointer(&xb))]) // should panic +} + +func p3() { + // Array to slice. + var p *[maxlen]byte = nil + var x []byte = p[0:] // should panic + _ = x +} + +var q *[maxlen]byte + +func p4() { + // Array to slice. + var x []byte + var y = &x + *y = q[0:] // should crash (uses arraytoslice runtime routine) +} + +func fb([]byte) { + panic("unreachable") +} + +func p5() { + // Array to slice. + var p *[maxlen]byte = nil + fb(p[0:]) // should crash +} + +func p6() { + // Array to slice. + var p *[maxlen]byte = nil + var _ []byte = p[10 : len(p)-10] // should crash +} + +type T struct { + x [in_mem_size]byte + i int +} + +func f() *T { + return nil +} + +var y *T +var x = &y + +func p7() { + // Struct field access with large offset. + println(f().i) // should crash +} + +func p8() { + // Struct field access with large offset. + println((*x).i) // should crash +} + +func p9() { + // Struct field access with large offset. + var t *T + println(&t.i) // should crash +} + +func p10() { + // Struct field access with large offset. + var t *T + println(t.i) // should crash +} + +type T1 struct { + T +} + +type T2 struct { + *T1 +} + +func p11() { + t := &T2{} + p := &t.i + println(*p) +} + +// ADDR(DOT(IND(p))) needs a check also +func p12() { + var p *T = nil + println(*(&((*p).i))) +} + +// Tests suggested in golang.org/issue/6080. + +func p13() { + var x *[10]int + y := x[:] + _ = y +} + +func p14() { + println((*[1]int)(nil)[:]) +} + +func p15() { + for i := range (*[1]int)(nil)[:] { + _ = i + } +} + +func p16() { + for i, v := range (*[1]int)(nil)[:] { + _ = i + v + } +} diff --git a/gcc/testsuite/go.test/test/nilptr_s390x.go b/gcc/testsuite/go.test/test/nilptr_s390x.go new file mode 100644 index 0000000..e5f6d56 --- /dev/null +++ b/gcc/testsuite/go.test/test/nilptr_s390x.go @@ -0,0 +1,190 @@ +// +build s390x +// run + +// Copyright 2011 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. + +// Test that the implementation catches nil ptr indirection in a +// large address space. + +package main + +import "unsafe" + +// Having a big address space means that indexing at a large +// offset from a nil pointer might not cause a memory access +// fault. This test checks that Go is doing the correct explicit +// checks to catch these nil pointer accesses, not just relying on +// the hardware. +// +// Give us a big address space somewhere near min_bss_offset. +const in_mem_size uintptr = 256 << 20 // 256 MiB +const min_bss_offset uintptr = 1 << 31 // 0x80000000 +const maxlen uintptr = (1 << 32) - 1 // 0xffffffff +var dummy [in_mem_size]byte + +func main() { + // The test only tests what we intend to test if dummy + // starts near 0x8000000. Otherwise there might not be + // anything mapped at the address that might be + // accidentally dereferenced below. + if uintptr(unsafe.Pointer(&dummy)) > in_mem_size + min_bss_offset { + panic("dummy too far out") + } else if uintptr(unsafe.Pointer(&dummy)) < min_bss_offset { + panic("dummy too close") + } + + shouldPanic(p1) + shouldPanic(p2) + shouldPanic(p3) + shouldPanic(p4) + shouldPanic(p5) + shouldPanic(p6) + shouldPanic(p7) + shouldPanic(p8) + shouldPanic(p9) + shouldPanic(p10) + shouldPanic(p11) + shouldPanic(p12) + shouldPanic(p13) + shouldPanic(p14) + shouldPanic(p15) + shouldPanic(p16) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("memory reference did not panic") + } + }() + f() +} + +func p1() { + // Array index. + var p *[maxlen]byte = nil + // very likely to be inside dummy, but should panic + println(p[min_bss_offset + in_mem_size / 2]) +} + +var xb byte + +func p2() { + var p *[maxlen]byte = nil + xb = 123 + + // Array index. + println(p[uintptr(unsafe.Pointer(&xb))]) // should panic +} + +func p3() { + // Array to slice. + var p *[maxlen]byte = nil + var x []byte = p[0:] // should panic + _ = x +} + +var q *[maxlen]byte + +func p4() { + // Array to slice. + var x []byte + var y = &x + *y = q[0:] // should crash (uses arraytoslice runtime routine) +} + +func fb([]byte) { + panic("unreachable") +} + +func p5() { + // Array to slice. + var p *[maxlen]byte = nil + fb(p[0:]) // should crash +} + +func p6() { + // Array to slice. + var p *[maxlen]byte = nil + var _ []byte = p[10 : len(p)-10] // should crash +} + +type T struct { + x [in_mem_size]byte + i int +} + +func f() *T { + return nil +} + +var y *T +var x = &y + +func p7() { + // Struct field access with large offset. + println(f().i) // should crash +} + +func p8() { + // Struct field access with large offset. + println((*x).i) // should crash +} + +func p9() { + // Struct field access with large offset. + var t *T + println(&t.i) // should crash +} + +func p10() { + // Struct field access with large offset. + var t *T + println(t.i) // should crash +} + +type T1 struct { + T +} + +type T2 struct { + *T1 +} + +func p11() { + t := &T2{} + p := &t.i + println(*p) +} + +// ADDR(DOT(IND(p))) needs a check also +func p12() { + var p *T = nil + println(*(&((*p).i))) +} + +// Tests suggested in golang.org/issue/6080. + +func p13() { + var x *[10]int + y := x[:] + _ = y +} + +func p14() { + println((*[1]int)(nil)[:]) +} + +func p15() { + for i := range (*[1]int)(nil)[:] { + _ = i + } +} + +func p16() { + for i, v := range (*[1]int)(nil)[:] { + _ = i + v + } +} -- 1.8.4.2