]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/nilptr.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / nilptr.go
index b784914e590af5124570bb5f53f6f85fa4e15b0d..7f42e930bdee7e95f13d28b8a3ccea4818501241 100644 (file)
@@ -1,12 +1,15 @@
 // run
 
-// Copyright 2011 The Go Authors.  All rights reserved.
+// 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.
 
+// Address space starts at 1<<32 on AIX and on darwin/arm64 and on windows/arm64, so dummy is too far.
+//go:build !aix && (!darwin || !arm64) && (!windows || !arm64)
+
 package main
 
 import "unsafe"
@@ -38,6 +41,12 @@ func main() {
        shouldPanic(p8)
        shouldPanic(p9)
        shouldPanic(p10)
+       shouldPanic(p11)
+       shouldPanic(p12)
+       shouldPanic(p13)
+       shouldPanic(p14)
+       shouldPanic(p15)
+       shouldPanic(p16)
 }
 
 func shouldPanic(f func()) {
@@ -130,3 +139,47 @@ func p10() {
        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
+       }
+}