Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/zerodivide.go: all expected zerodivide panic errors are skipped #18421

Closed
odeke-em opened this issue Dec 23, 2016 · 1 comment
Closed

test/zerodivide.go: all expected zerodivide panic errors are skipped #18421

odeke-em opened this issue Dec 23, 2016 · 1 comment

Comments

@odeke-em
Copy link
Member

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +8887be4 Thu Dec 22 22:43:44 2016 +0000 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/Users/emmanuelodeke/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/emmanuelodeke/go"
GORACE=""
GOROOT="/Users/emmanuelodeke/go/src/go.googlesource.com/go"
GOTOOLDIR="/Users/emmanuelodeke/go/src/go.googlesource.com/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v3/7z434qpx5v3bw0wh8h2myfpw0000gn/T/go-build810117618=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Added a test to lock in and ensure that #5790 original bug report actually panics(which is what we want) so that that issue can be closed. I was debugging the code path in the SSA backend and saw that the condition actually gets evaluated
hence we should lock this in.

To show that this zerodivide.go condition is trippy

diff --git a/test/zerodivide.go b/test/zerodivide.go
index 9ab2713..98df310 100644
--- a/test/zerodivide.go
+++ b/test/zerodivide.go
@@ -28,6 +28,8 @@ var (
 	i32, j32, k32 int32 = 0, 0, 1
 	i64, j64, k64 int64 = 0, 0, 1
 
+	bb = []int16{2, 0}
+
 	u, v, w       uint    = 0, 0, 1
 	u8, v8, w8    uint8   = 0, 0, 1
 	u16, v16, w16 uint16  = 0, 0, 1
@@ -124,6 +126,8 @@ var errorTests = []ErrorTest{
 	ErrorTest{"int32 1/0", func() { use(k32 / j32) }, "divide"},
 	ErrorTest{"int64 1/0", func() { use(k64 / j64) }, "divide"},
 
+	ErrorTest{"int16 _ = bb[1]/bb[0]", func() { _ = bb[0] / bb[1] }, "divide"},
+
 	ErrorTest{"uint 0/0", func() { use(u / v) }, "divide"},
 	ErrorTest{"uint8 0/0", func() { use(u8 / v8) }, "divide"},
 	ErrorTest{"uint16 0/0", func() { use(u16 / v16) }, "divide"},
@@ -167,7 +171,7 @@ func error_(fn func()) (error string) {
 		}
 	}()
 	fn()
-	return ""
+	return
 }
 
 type FloatTest struct {
@@ -194,11 +198,12 @@ func alike(a, b float64) bool {
 
 func main() {
 	bad := false
-	for _, t := range errorTests {
+	for i, t := range errorTests {
 		if t.err != "" {
 			continue
 		}
 		err := error_(t.fn)
+		fmt.Printf("#%d: t.name: %s err: %v\n", i, t.name, err)
 		switch {
 		case t.err == "" && err == "":
 			// fine
$ go run zerodivide.go 

What did you expect to see?

#0: t.name: int 0/0 err: runtime error: integer divide by zero
#1: t.name: int8 0/0 err: runtime error: integer divide by zero
#2: t.name: int16 0/0 err: runtime error: integer divide by zero
#3: t.name: int32 0/0 err: runtime error: integer divide by zero
#4: t.name: int64 0/0 err: runtime error: integer divide by zero
#5: t.name: int 1/0 err: runtime error: integer divide by zero
#6: t.name: int8 1/0 err: runtime error: integer divide by zero
#7: t.name: int16 1/0 err: runtime error: integer divide by zero
#8: t.name: int32 1/0 err: runtime error: integer divide by zero
#9: t.name: int64 1/0 err: runtime error: integer divide by zero
#10: t.name: int16 _ = bb[1]/bb[0] err: runtime error: integer divide by zero
#11: t.name: uint 0/0 err: runtime error: integer divide by zero
#12: t.name: uint8 0/0 err: runtime error: integer divide by zero
#13: t.name: uint16 0/0 err: runtime error: integer divide by zero
#14: t.name: uint32 0/0 err: runtime error: integer divide by zero
#15: t.name: uint64 0/0 err: runtime error: integer divide by zero
#16: t.name: uintptr 0/0 err: runtime error: integer divide by zero
#17: t.name: uint 1/0 err: runtime error: integer divide by zero
#18: t.name: uint8 1/0 err: runtime error: integer divide by zero
#19: t.name: uint16 1/0 err: runtime error: integer divide by zero
#20: t.name: uint32 1/0 err: runtime error: integer divide by zero
#21: t.name: uint64 1/0 err: runtime error: integer divide by zero
#22: t.name: uintptr 1/0 err: runtime error: integer divide by zero
#23: t.name: float64 0/0 err: 
#24: t.name: float32 0/0 err: 
#25: t.name: float64 0/0 err: 
#26: t.name: float64 1/0 err: 
#27: t.name: float32 1/0 err: 
#28: t.name: float64 1/0 err: 
#29: t.name: float64 inf/0 err: 
#30: t.name: float64 -inf/0 err: 
#31: t.name: float64 nan/0 err: 
#32: t.name: complex 0/0 err: 
#33: t.name: complex64 0/0 err: 
#34: t.name: complex128 0/0 err: 
#35: t.name: complex 1/0 err: 
#36: t.name: complex64 1/0 err: 
#37: t.name: complex128 1/0 err: 

What did you see instead?

All the tests that had expected errors were just skipped over

#23: t.name: float64 0/0 err: 
#24: t.name: float32 0/0 err: 
#25: t.name: float64 0/0 err: 
#26: t.name: float64 1/0 err: 
#27: t.name: float32 1/0 err: 
#28: t.name: float64 1/0 err: 
#29: t.name: float64 inf/0 err: 
#30: t.name: float64 -inf/0 err: 
#31: t.name: float64 nan/0 err: 
#32: t.name: complex 0/0 err: 
#33: t.name: complex64 0/0 err: 
#34: t.name: complex128 0/0 err: 
#35: t.name: complex 1/0 err: 
#36: t.name: complex64 1/0 err: 
#37: t.name: complex128 1/0 err: 

That code was last touched in 2010 with 0c54225 in which previously we skipped on nacl ie 21ff75b#diff-d76591abbcb0fcec99a03318b54ecc14R140
but then after
0c54225,
we just removed the && nacl and forgot to update the entire condition, therefore in those tests
we don't check if expected zero divides panics.

/cc @rsc

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/34712 mentions this issue.

@golang golang locked and limited conversation to collaborators Dec 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants