]> Cypherpunks repositories - gostls13.git/commitdiff
Storing an out of range constant into a variable should
authorIan Lance Taylor <iant@golang.org>
Mon, 29 Sep 2008 18:03:21 +0000 (11:03 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 29 Sep 2008 18:03:21 +0000 (11:03 -0700)
ideally cause the compiler to give an error.  Right now 6g
warns about large shifts but does not give an error.  This CL
removes the out of range shift from shift.go, so that it will
work with gccgo, and adds a test case in bugs/ to be fixed at
a later date.

R=ken,r
DELTA=23  (9 added, 14 deleted, 0 changed)
OCL=16085
CL=16088

test/bugs/bug108.go [new file with mode: 0644]
test/golden.out
test/ken/shift.go

diff --git a/test/bugs/bug108.go b/test/bugs/bug108.go
new file mode 100644 (file)
index 0000000..b7350e7
--- /dev/null
@@ -0,0 +1,10 @@
+// errchk $G $D/$F.go
+
+// 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() {
+       v := 1 << 1025;         // ERROR "overflow"
+}
index fa3b09d65bb0dace821bd126559b33f10ddd76dc..196d854ac5c01093c23175400f6c096a60b6742e 100644 (file)
@@ -37,14 +37,6 @@ Hello World!
 =========== ken/rob2.go
 (defn foo (add 12 34))
 
-=========== ken/shift.go
-ken/shift.go:50: stupid shift: 1025
-ken/shift.go:51: stupid shift: 1025
-ken/shift.go:57: stupid shift: 1025
-ken/shift.go:58: stupid shift: 1025
-ken/shift.go:64: stupid shift: 1025
-ken/shift.go:65: stupid shift: 1025
-
 =========== ken/simpprint.go
 hello world
 
@@ -172,6 +164,10 @@ BUG: errchk: command succeeded unexpectedly:  6g bugs/bug104.go
 =========== bugs/bug107.go
 BUG: errchk: command succeeded unexpectedly:  6g bugs/bug107.go
 
+=========== bugs/bug108.go
+bugs/bug108.go:4: stupid shift: 1025
+BUG: errchk: command succeeded unexpectedly:  6g bugs/bug108.go
+
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: overflow converting constant to <uint32>UINT32
 
index 0be8da51b69e3724c37d3f1bcdaf69189cc4ecda..379f53fa42256621b89af27ca255ddcdd0d52e8c 100644 (file)
@@ -51,22 +51,16 @@ main()
        testi( int(1234) >>    0, 0,0,1);
        testi( int(1234) <<    5, 0,1,0);
        testi( int(1234) >>    5, 0,1,1);
-       testi( int(1234) << 1025, 0,2,0);
-       testi( int(1234) >> 1025, 0,2,1);
 
        testi(int(-1234) <<    0, 1,0,0);
        testi(int(-1234) >>    0, 1,0,1);
        testi(int(-1234) <<    5, 1,1,0);
        testi(int(-1234) >>    5, 1,1,1);
-       testi(int(-1234) << 1025, 1,2,0);
-       testi(int(-1234) >> 1025, 1,2,1);
 
        testu(uint(5678) <<    0, 2,0,0);
        testu(uint(5678) >>    0, 2,0,1);
        testu(uint(5678) <<    5, 2,1,0);
        testu(uint(5678) >>    5, 2,1,1);
-       testu(uint(5678) << 1025, 2,2,0);
-       testu(uint(5678) >> 1025, 2,2,1);
 
        /*
         * test variable evaluations