diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-22 14:46:12 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-22 14:46:12 +0000 |
commit | c016fd32fe7da1a8c97f96f7e9767e4e300b3d28 (patch) | |
tree | 60dae3998cda620358797eb5bf0fff80691fc09e | |
parent | 3b0ddadf74ec9c7aa404765ec50bb55d255dbec7 (diff) | |
download | gcc-c016fd32fe7da1a8c97f96f7e9767e4e300b3d28.zip gcc-c016fd32fe7da1a8c97f96f7e9767e4e300b3d28.tar.gz gcc-c016fd32fe7da1a8c97f96f7e9767e4e300b3d28.tar.bz2 |
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
From-SVN: r249562
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | libgo/go/runtime/testdata/testprog/crash.go | 5 | ||||
-rw-r--r-- | libgo/go/runtime/testdata/testprogcgo/crash.go | 5 |
3 files changed, 7 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 942752b..296cd0f 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -b5c9fe259ec43f8079581c3bea0f1d12d85213a7 +8804c912363320e0c229c5a471fb6f4b9e5965e6 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. 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 @@ 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 4d83132..ed4ae7f 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") } |