Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / nilptr / arrayindex.go
blobc564bce3404971f2855e30faba5d72cae4306963
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)
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.
9 package main
11 import "unsafe"
13 var x byte
15 func main() {
16 var p *[1<<30]byte = nil
17 x = 123
19 // The problem here is not the use of unsafe:
20 // it is that indexing into p[] with a large
21 // enough index jumps out of the unmapped section
22 // at the beginning of memory and into valid memory.
23 // Pointer offsets and array indices, if they are
24 // very large, need to dereference the base pointer
25 // to trigger a trap.
26 println(p[uintptr(unsafe.Pointer(&x))]) // should crash