diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-06-22 14:46:12 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-06-22 14:46:12 +0000 |
commit | 6103480c5d816349b9c9f86d186254b6122ac0f8 (patch) | |
tree | 60dae3998cda620358797eb5bf0fff80691fc09e /libgo | |
parent | 2386202283cf3daa799f87f01f30f4bafdca79c6 (diff) | |
download | gcc-6103480c5d816349b9c9f86d186254b6122ac0f8.tar.gz |
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.
Reviewed-on: https://go-review.googlesource.com/46450
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249562 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/go/runtime/testdata/testprog/crash.go | 5 | ||||
-rw-r--r-- | libgo/go/runtime/testdata/testprogcgo/crash.go | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/libgo/go/runtime/testdata/testprog/crash.go b/libgo/go/runtime/testdata/testprog/crash.go index 4d83132198d..ed4ae7fcdbc 100644 --- a/libgo/go/runtime/testdata/testprog/crash.go +++ b/libgo/go/runtime/testdata/testprog/crash.go @@ -13,6 +13,8 @@ func init() { register("Crash", Crash) } +var NilPointer *string + func test(name string) { defer func() { if x := recover(); x != nil { @@ -21,8 +23,7 @@ func test(name string) { 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 4d83132198d..ed4ae7fcdbc 100644 --- a/libgo/go/runtime/testdata/testprogcgo/crash.go +++ b/libgo/go/runtime/testdata/testprogcgo/crash.go @@ -13,6 +13,8 @@ func init() { register("Crash", Crash) } +var NilPointer *string + func test(name string) { defer func() { if x := recover(); x != nil { @@ -21,8 +23,7 @@ func test(name string) { fmt.Printf(" done\n") }() fmt.Printf("%s:", name) - var s *string - _ = *s + *NilPointer = name fmt.Print("SHOULD NOT BE HERE") } |