runtime: don't assume that _ = *s will panic if s is nil
With the gc toolchain apparently
var s *string
_ = *s
is enough to panic with a nil pointer dereference. The gccgo compiler
will simply discard the dereference, which I think is a reasonable and
acceptable optimization. Change the tests to use an exported variable
instead. The tests are not currently run, but they will be with a
later patch to gotools.
Change-Id: I94e6a52c8832ab34aa1c7653d0ab9fce6126bf8a
Reviewed-on: https://go-review.googlesource.com/46450
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/libgo/go/runtime/testdata/testprog/crash.go b/libgo/go/runtime/testdata/testprog/crash.go
index 4d83132..ed4ae7f 100644
--- a/libgo/go/runtime/testdata/testprog/crash.go
+++ b/libgo/go/runtime/testdata/testprog/crash.go
@@ -13,6 +13,8 @@
register("Crash", Crash)
}
+var NilPointer *string
+
func test(name string) {
defer func() {
if x := recover(); x != nil {
@@ -21,8 +23,7 @@
fmt.Printf(" done\n")
}()
fmt.Printf("%s:", name)
- var s *string
- _ = *s
+ *NilPointer = name
fmt.Print("SHOULD NOT BE HERE")
}
diff --git a/libgo/go/runtime/testdata/testprogcgo/crash.go b/libgo/go/runtime/testdata/testprogcgo/crash.go
index 4d83132..ed4ae7f 100644
--- a/libgo/go/runtime/testdata/testprogcgo/crash.go
+++ b/libgo/go/runtime/testdata/testprogcgo/crash.go
@@ -13,6 +13,8 @@
register("Crash", Crash)
}
+var NilPointer *string
+
func test(name string) {
defer func() {
if x := recover(); x != nil {
@@ -21,8 +23,7 @@
fmt.Printf(" done\n")
}()
fmt.Printf("%s:", name)
- var s *string
- _ = *s
+ *NilPointer = name
fmt.Print("SHOULD NOT BE HERE")
}