]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/go.test/test/nilptr/arraytoslice.go
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / gcc / testsuite / go.test / test / nilptr / arraytoslice.go
1 // [ $GOOS != nacl ] || exit 0 # do not bother on NaCl
2 // $G $D/$F.go && $L $F.$A &&
3 // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
4
5 // Copyright 2009 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 package main
10
11 import "unsafe"
12
13 func f([]byte) {
14 panic("unreachable")
15 }
16
17 var dummy [512<<20]byte // give us a big address space
18 func main() {
19 // the test only tests what we intend to test
20 // if dummy starts in the first 256 MB of memory.
21 // otherwise there might not be anything mapped
22 // at the address that might be accidentally
23 // dereferenced below.
24 if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
25 panic("dummy too far out")
26 }
27
28 // The problem here is that indexing into p[] with a large
29 // enough index can jump out of the unmapped section
30 // at the beginning of memory and into valid memory.
31 //
32 // To avoid needing a check on every slice beyond the
33 // usual len and cap, we require the *array -> slice
34 // conversion to do the check.
35 var p *[1<<30]byte = nil
36 f(p[0:]) // should crash
37 }