]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: avoid spurious div-zero errors
authorRobert Griesemer <gri@golang.org>
Tue, 21 Apr 2015 17:39:21 +0000 (10:39 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 13 May 2015 17:38:13 +0000 (17:38 +0000)
Set overflowing integer constants to 1 rather than 0 to avoid
spurious div-zero errors in subsequent constant expressions.

Also: Exclude new test case from go/types test since it's
running too long (go/types doesn't have an upper constant
size limit at the moment).

Fixes #7746.

Change-Id: I3768488ad9909a3cf995247b81ee78a8eb5a1e41
Reviewed-on: https://go-review.googlesource.com/9165
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/gc/const.go
src/cmd/internal/gc/mparith2.go
src/go/types/stdlib_test.go
test/fixedbugs/issue7746.go [new file with mode: 0644]

index 5ec54bdffb1728349b879104fbaebe2b10d595db..84b133769c6f49206db22cbee75f51efc2c7c068 100644 (file)
@@ -774,7 +774,7 @@ func evconst(n *Node) {
                ODIV<<16 | CTRUNE:
                if mpcmpfixc(rv.U.Xval, 0) == 0 {
                        Yyerror("division by zero")
-                       Mpmovecfix(v.U.Xval, 1)
+                       mpsetovf(v.U.Xval)
                        break
                }
 
@@ -784,7 +784,7 @@ func evconst(n *Node) {
                OMOD<<16 | CTRUNE:
                if mpcmpfixc(rv.U.Xval, 0) == 0 {
                        Yyerror("division by zero")
-                       Mpmovecfix(v.U.Xval, 1)
+                       mpsetovf(v.U.Xval)
                        break
                }
 
index de96e97809a7230ae9cbe415e201ceb19be95de2..2456dbf60a69c7dc57720a2522fda106d1a2dee7 100644 (file)
@@ -13,7 +13,7 @@ import (
 /// implements fix arithmetic
 
 func mpsetovf(a *Mpint) {
-       a.Val.SetUint64(0)
+       a.Val.SetUint64(1) // avoid spurious div-zero errors
        a.Ovf = true
 }
 
index d04dd71e4feee5ae05ce24d68132ce4230dc8bf5..28a66cebe3abc9129b77bb6cdf3db2e5c8db445a 100644 (file)
@@ -146,6 +146,7 @@ func TestStdFixed(t *testing.T) {
                "bug459.go",    // possibly incorrect test - see issue 6703 (pending spec clarification)
                "issue3924.go", // possibly incorrect test - see issue 6671 (pending spec clarification)
                "issue6889.go", // gc-specific test
+               "issue7746.go", // large constants - consumes too much memory
        )
 }
 
diff --git a/test/fixedbugs/issue7746.go b/test/fixedbugs/issue7746.go
new file mode 100644 (file)
index 0000000..0dc119d
--- /dev/null
@@ -0,0 +1,133 @@
+// errorcheck
+
+// Copyright 2015 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.
+
+package main
+
+const (
+       c0   = 1 << 100
+       c1   = c0 * c0
+       c2   = c1 * c1
+       c3   = c2 * c2 // ERROR "overflow"
+       c4   = c3 * c3
+       c5   = c4 * c4
+       c6   = c5 * c5
+       c7   = c6 * c6
+       c8   = c7 * c7
+       c9   = c8 * c8
+       c10  = c9 * c9
+       c11  = c10 * c10
+       c12  = c11 * c11
+       c13  = c12 * c12
+       c14  = c13 * c13
+       c15  = c14 * c14
+       c16  = c15 * c15
+       c17  = c16 * c16
+       c18  = c17 * c17
+       c19  = c18 * c18
+       c20  = c19 * c19
+       c21  = c20 * c20
+       c22  = c21 * c21
+       c23  = c22 * c22
+       c24  = c23 * c23
+       c25  = c24 * c24
+       c26  = c25 * c25
+       c27  = c26 * c26
+       c28  = c27 * c27
+       c29  = c28 * c28
+       c30  = c29 * c29
+       c31  = c30 * c30
+       c32  = c31 * c31
+       c33  = c32 * c32
+       c34  = c33 * c33
+       c35  = c34 * c34
+       c36  = c35 * c35
+       c37  = c36 * c36
+       c38  = c37 * c37
+       c39  = c38 * c38
+       c40  = c39 * c39
+       c41  = c40 * c40
+       c42  = c41 * c41
+       c43  = c42 * c42
+       c44  = c43 * c43
+       c45  = c44 * c44
+       c46  = c45 * c45
+       c47  = c46 * c46
+       c48  = c47 * c47
+       c49  = c48 * c48
+       c50  = c49 * c49
+       c51  = c50 * c50
+       c52  = c51 * c51
+       c53  = c52 * c52
+       c54  = c53 * c53
+       c55  = c54 * c54
+       c56  = c55 * c55
+       c57  = c56 * c56
+       c58  = c57 * c57
+       c59  = c58 * c58
+       c60  = c59 * c59
+       c61  = c60 * c60
+       c62  = c61 * c61
+       c63  = c62 * c62
+       c64  = c63 * c63
+       c65  = c64 * c64
+       c66  = c65 * c65
+       c67  = c66 * c66
+       c68  = c67 * c67
+       c69  = c68 * c68
+       c70  = c69 * c69
+       c71  = c70 * c70
+       c72  = c71 * c71
+       c73  = c72 * c72
+       c74  = c73 * c73
+       c75  = c74 * c74
+       c76  = c75 * c75
+       c77  = c76 * c76
+       c78  = c77 * c77
+       c79  = c78 * c78
+       c80  = c79 * c79
+       c81  = c80 * c80
+       c82  = c81 * c81
+       c83  = c82 * c82
+       c84  = c83 * c83
+       c85  = c84 * c84
+       c86  = c85 * c85
+       c87  = c86 * c86
+       c88  = c87 * c87
+       c89  = c88 * c88
+       c90  = c89 * c89
+       c91  = c90 * c90
+       c92  = c91 * c91
+       c93  = c92 * c92
+       c94  = c93 * c93
+       c95  = c94 * c94
+       c96  = c95 * c95
+       c97  = c96 * c96
+       c98  = c97 * c97
+       c99  = c98 * c98
+       c100 = c99 * c99
+)
+
+func main() {
+       println(c1 / c1)
+       println(c2 / c2)
+       println(c3 / c3)
+       println(c4 / c4)
+       println(c5 / c5)
+       println(c6 / c6)
+       println(c7 / c7)
+       println(c8 / c8)
+       println(c9 / c9)
+       println(c10 / c10)
+       println(c20 / c20)
+       println(c30 / c30)
+       println(c40 / c40)
+       println(c50 / c50)
+       println(c60 / c60)
+       println(c70 / c70)
+       println(c80 / c80)
+       println(c90 / c90)
+       println(c100 / c100)
+}