summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue29504.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
commitccd992355df7192993c666236047820244914598 (patch)
treef00fea65147227b7743083c6148396f74cd66935 /test/fixedbugs/issue29504.go
parentInitial commit. (diff)
downloadgolang-1.21-ccd992355df7192993c666236047820244914598.tar.xz
golang-1.21-ccd992355df7192993c666236047820244914598.zip
Adding upstream version 1.21.8.upstream/1.21.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/fixedbugs/issue29504.go')
-rw-r--r--test/fixedbugs/issue29504.go147
1 files changed, 147 insertions, 0 deletions
diff --git a/test/fixedbugs/issue29504.go b/test/fixedbugs/issue29504.go
new file mode 100644
index 0000000..e311f84
--- /dev/null
+++ b/test/fixedbugs/issue29504.go
@@ -0,0 +1,147 @@
+// run
+
+// Copyright 2019 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.
+
+// Make sure that in code involving indexing, the bounds
+// check always fails at the line number of the '[' token.
+
+package main
+
+import (
+ "fmt"
+ "runtime"
+ "strings"
+)
+
+type T struct{ a, b, c, d, e int } // unSSAable
+
+func main() {
+ shouldPanic(func() {
+ var a [1]int
+ sink = a /*line :999999:1*/ [ /*line :100:1*/ i]
+ })
+ shouldPanic(func() {
+ var a [3]int
+ sink = a /*line :999999:1*/ [ /*line :200:1*/ i]
+ })
+ shouldPanic(func() {
+ var a []int
+ sink = a /*line :999999:1*/ [ /*line :300:1*/ i]
+ })
+ shouldPanic(func() {
+ var a [1]int
+ a /*line :999999:1*/ [ /*line :400:1*/ i] = 1
+ })
+ shouldPanic(func() {
+ var a [3]int
+ a /*line :999999:1*/ [ /*line :500:1*/ i] = 1
+ })
+ shouldPanic(func() {
+ var a []int
+ a /*line :999999:1*/ [ /*line :600:1*/ i] = 1
+ })
+
+ shouldPanic(func() {
+ var a [3]T
+ sinkT = a /*line :999999:1*/ [ /*line :700:1*/ i]
+ })
+ shouldPanic(func() {
+ var a []T
+ sinkT = a /*line :999999:1*/ [ /*line :800:1*/ i]
+ })
+ shouldPanic(func() {
+ var a [3]T
+ a /*line :999999:1*/ [ /*line :900:1*/ i] = T{}
+ })
+ shouldPanic(func() {
+ var a []T
+ a /*line :999999:1*/ [ /*line :1000:1*/ i] = T{}
+ })
+
+ shouldPanic(func() {
+ var a [3]int
+ sinkS = a /*line :999999:1*/ [ /*line :1100:1*/ i:]
+ })
+ shouldPanic(func() {
+ var a []int
+ sinkS = a /*line :999999:1*/ [ /*line :1200:1*/ i:]
+ })
+ shouldPanic(func() {
+ var a [3]int
+ sinkS = a /*line :999999:1*/ [: /*line :1300:1*/ i]
+ })
+ shouldPanic(func() {
+ var a []int
+ sinkS = a /*line :999999:1*/ [: /*line :1400:1*/ i]
+ })
+
+ shouldPanic(func() {
+ var a [3]T
+ sinkST = a /*line :999999:1*/ [ /*line :1500:1*/ i:]
+ })
+ shouldPanic(func() {
+ var a []T
+ sinkST = a /*line :999999:1*/ [ /*line :1600:1*/ i:]
+ })
+ shouldPanic(func() {
+ var a [3]T
+ sinkST = a /*line :999999:1*/ [: /*line :1700:1*/ i]
+ })
+ shouldPanic(func() {
+ var a []T
+ sinkST = a /*line :999999:1*/ [: /*line :1800:1*/ i]
+ })
+
+ shouldPanic(func() {
+ s := "foo"
+ sinkB = s /*line :999999:1*/ [ /*line :1900:1*/ i]
+ })
+ shouldPanic(func() {
+ s := "foo"
+ sinkStr = s /*line :999999:1*/ [ /*line :2000:1*/ i:]
+ })
+ shouldPanic(func() {
+ s := "foo"
+ sinkStr = s /*line :999999:1*/ [: /*line :2100:1*/ i]
+ })
+
+ if bad {
+ panic("ERRORS")
+ }
+}
+
+var i = 9
+var sink int
+var sinkS []int
+var sinkT T
+var sinkST []T
+var sinkB byte
+var sinkStr string
+
+var bad = false
+
+func shouldPanic(f func()) {
+ defer func() {
+ if recover() == nil {
+ panic("did not panic")
+ }
+ var pcs [10]uintptr
+ n := runtime.Callers(1, pcs[:])
+ iter := runtime.CallersFrames(pcs[:n])
+ buf := ""
+ for {
+ frame, more := iter.Next()
+ buf += fmt.Sprintf("%s:%d %s\n", frame.File, frame.Line, frame.Function)
+ if !more {
+ break
+ }
+ }
+ if !strings.Contains(buf, "999999") {
+ fmt.Printf("could not find marker line in traceback:\n%s\n", buf)
+ bad = true
+ }
+ }()
+ f()
+}