]> Cypherpunks repositories - gostls13.git/commitdiff
64-bit integer math bugs
authorRuss Cox <rsc@golang.org>
Fri, 29 May 2009 20:46:43 +0000 (13:46 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 29 May 2009 20:46:43 +0000 (13:46 -0700)
R=r
DELTA=46  (46 added, 0 deleted, 0 changed)
OCL=29569
CL=29614

test/bugs/bug155.go [new file with mode: 0644]
test/bugs/bug156.go [new file with mode: 0644]
test/golden.out

diff --git a/test/bugs/bug155.go b/test/bugs/bug155.go
new file mode 100644 (file)
index 0000000..312c8e6
--- /dev/null
@@ -0,0 +1,23 @@
+// $G $D/$F.go && $L $F.$A || echo BUG: bug155
+
+// Copyright 2009 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 big uint64 = 1<<63
+
+func f(a uint64) uint64 {
+       return a << big
+}
+
+func main() {
+       f(1)
+}
+
+/*
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+*/
diff --git a/test/bugs/bug156.go b/test/bugs/bug156.go
new file mode 100644 (file)
index 0000000..0b77a72
--- /dev/null
@@ -0,0 +1,21 @@
+// $G $D/$F.go || echo BUG: bug156
+
+// Copyright 2009 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
+
+func f(a int64) int64 {
+       const b int64 = 0;
+       n := a &^ b;
+       return n;
+}
+
+func main() {
+       f(1)
+}
+
+/*
+bug156.go:7: constant 18446744073709551615 overflows int64
+*/
index b5dbddffe62148ed9bdc8144bd8d87d63cbc7e5f..98348e753a676552b243257586712cab488e31d2 100644 (file)
@@ -104,6 +104,16 @@ BUG should compile
 5 7
 BUG: should crash
 
+=========== bugs/bug155.go
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+main·f: doasm: notfound from=75 to=13 (82)    SHLQ    $-9223372036854775808,BX
+BUG: bug155
+
+=========== bugs/bug156.go
+bugs/bug156.go:7: constant 18446744073709551615 overflows int64
+BUG: bug156
+
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: constant -3 overflows uint