OSDN Git Service

compiler: Error if type switch case can not implement switch value.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / go.test / test / nilptr / structfield1.go
1 // $G $D/$F.go && $L $F.$A &&
2 //      ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail)
3
4 // Copyright 2009 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
7
8 package main
9
10 import "unsafe"
11
12 var dummy [512<<20]byte // give us a big address space
13 type T struct {
14         x [256<<20] byte
15         i int
16 }
17
18 func f() *T {
19         return nil
20 }
21
22 func main() {
23         // the test only tests what we intend to test
24         // if dummy starts in the first 256 MB of memory.
25         // otherwise there might not be anything mapped
26         // at the address that might be accidentally
27         // dereferenced below.
28         if uintptr(unsafe.Pointer(&dummy)) > 256<<20 {
29                 panic("dummy too far out")
30         }
31
32         // The problem here is that indexing into t with a large
33         // enough index can jump out of the unmapped section
34         // at the beginning of memory and into valid memory.
35         // We require the pointer dereference to check.
36         println(f().i)  // should crash
37 }