]> Cypherpunks repositories - gostls13.git/commitdiff
gc: Nicer errors before miscompiling.
authorLuuk van Dijk <lvd@golang.org>
Tue, 10 Jan 2012 10:19:22 +0000 (11:19 +0100)
committerLuuk van Dijk <lvd@golang.org>
Tue, 10 Jan 2012 10:19:22 +0000 (11:19 +0100)
This fixes issue 2444.

A big cleanup of all 31/32bit size boundaries i'll leave for another cl though.  (see also issue 1700).

R=rsc
CC=golang-dev
https://golang.org/cl/5484058

src/cmd/5g/cgen.c
src/cmd/5g/gg.h
src/cmd/6g/cgen.c
src/cmd/6g/gg.h
src/cmd/8g/cgen.c
src/cmd/8g/gg.h
src/cmd/gc/align.c
src/cmd/gc/pgen.c
test/fixedbugs/bug385_32.go [new file with mode: 0644]
test/fixedbugs/bug385_64.go [new file with mode: 0644]

index b0a60400338d5b13db655679ec3663ca79d8b74f..8865027dcaa1fa0b5dcdd645638f3a7d287c78f5 100644 (file)
@@ -1193,7 +1193,7 @@ stkof(Node *n)
  * NB: character copy assumed little endian architecture
  */
 void
-sgen(Node *n, Node *res, int32 w)
+sgen(Node *n, Node *res, int64 w)
 {
        Node dst, src, tmp, nend;
        int32 c, odst, osrc;
@@ -1201,14 +1201,17 @@ sgen(Node *n, Node *res, int32 w)
        Prog *p, *ploop;
 
        if(debug['g']) {
-               print("\nsgen w=%d\n", w);
+               print("\nsgen w=%lld\n", w);
                dump("r", n);
                dump("res", res);
        }
-       if(w < 0)
-               fatal("sgen copy %d", w);
+
        if(n->ullman >= UINF && res->ullman >= UINF)
                fatal("sgen UINF");
+
+       if(w < 0 || (int32)w != w)
+               fatal("sgen copy %lld", w);
+
        if(n->type == T)
                fatal("sgen: missing type");
 
@@ -1240,7 +1243,7 @@ sgen(Node *n, Node *res, int32 w)
                break;
        }
        if(w%align)
-               fatal("sgen: unaligned size %d (align=%d) for %T", w, align, n->type);
+               fatal("sgen: unaligned size %lld (align=%d) for %T", w, align, n->type);
        c = w / align;
 
        // offset on the stack
index 757ac20b2eeff7a6a0f71285c34399a02d591db6..7dbf3beecd0ce75197fd702da3f7fcf5544b82a7 100644 (file)
@@ -94,7 +94,7 @@ void  igen(Node*, Node*, Node*);
 void agenr(Node *n, Node *a, Node *res);
 vlong  fieldoffset(Type*, Node*);
 void   bgen(Node*, int, Prog*);
-void   sgen(Node*, Node*, int32);
+void   sgen(Node*, Node*, int64);
 void   gmove(Node*, Node*);
 Prog*  gins(int, Node*, Node*);
 int    samaddr(Node*, Node*);
index 308915f64dd449898a48d9a38a19e775915d6800..fd8493231402be1d849e12a0c1eece87acbe306d 100644 (file)
@@ -1023,13 +1023,13 @@ stkof(Node *n)
  *     memmove(&ns, &n, w);
  */
 void
-sgen(Node *n, Node *ns, int32 w)
+sgen(Node *n, Node *ns, int64 w)
 {
        Node nodl, nodr, oldl, oldr, cx, oldcx, tmp;
        int32 c, q, odst, osrc;
 
        if(debug['g']) {
-               print("\nsgen w=%d\n", w);
+               print("\nsgen w=%lld\n", w);
                dump("r", n);
                dump("res", ns);
        }
@@ -1038,7 +1038,7 @@ sgen(Node *n, Node *ns, int32 w)
                fatal("sgen UINF");
 
        if(w < 0)
-               fatal("sgen copy %d", w);
+               fatal("sgen copy %lld", w);
 
        if(w == 16)
                if(componentgen(n, ns))
index 0930ebd6081ae3d8cfc41df1d2eb1b003ed71a9c..47a540082b50c27a26a7d0f1941719637850307c 100644 (file)
@@ -87,7 +87,7 @@ void  agen(Node*, Node*);
 void   igen(Node*, Node*, Node*);
 vlong  fieldoffset(Type*, Node*);
 void   bgen(Node*, int, Prog*);
-void   sgen(Node*, Node*, int32);
+void   sgen(Node*, Node*, int64);
 void   gmove(Node*, Node*);
 Prog*  gins(int, Node*, Node*);
 int    samaddr(Node*, Node*);
index cf1eacde57de24f2aacbbb3870a35466e618336a..7dd3a7bb12815d8950597a4c1a3a853a172a5d52 100644 (file)
@@ -1130,21 +1130,21 @@ stkof(Node *n)
  *     memmove(&res, &n, w);
  */
 void
-sgen(Node *n, Node *res, int32 w)
+sgen(Node *n, Node *res, int64 w)
 {
        Node dst, src, tdst, tsrc;
        int32 c, q, odst, osrc;
 
        if(debug['g']) {
-               print("\nsgen w=%d\n", w);
+               print("\nsgen w=%ld\n", w);
                dump("r", n);
                dump("res", res);
        }
        if(n->ullman >= UINF && res->ullman >= UINF)
                fatal("sgen UINF");
 
-       if(w < 0)
-               fatal("sgen copy %d", w);
+       if(w < 0 || (int32)w != w)
+               fatal("sgen copy %lld", w);
 
        if(w == 0) {
                // evaluate side effects only.
index 021a943377b8d5addf4ef6118ec88cf50ec69594..0a4f0ad2d0de2fac4642688af00016287a74862c 100644 (file)
@@ -99,7 +99,7 @@ void  agenr(Node *n, Node *a, Node *res);
 void   igen(Node*, Node*, Node*);
 vlong  fieldoffset(Type*, Node*);
 void   bgen(Node*, int, Prog*);
-void   sgen(Node*, Node*, int32);
+void   sgen(Node*, Node*, int64);
 void   gmove(Node*, Node*);
 Prog*  gins(int, Node*, Node*);
 int    samaddr(Node*, Node*);
index 623006f806e31724b51dd06727cee3f2d8eb2251..6982bbe560e913ac73aa4aab14a2786cfd467f95 100644 (file)
@@ -285,6 +285,9 @@ dowidth(Type *t)
                break;
        }
 
+       if(widthptr == 4 && w != (int32)w)
+               yyerror("type %T too large", t);
+
        t->width = w;
        if(t->align == 0) {
                if(w > 8 || (w&(w-1)) != 0)
index 3c2237a2aefe8aa4678949008cb8838fdefb59ed..a54f0978252a3f494be58e58f828c7c49489c90b 100644 (file)
@@ -119,6 +119,10 @@ compile(Node *fn)
        if(0)
                print("allocauto: %lld to %lld\n", oldstksize, (vlong)stksize);
 
+       setlineno(curfn);
+       if(stksize+maxarg > (1ULL<<31))
+               yyerror("stack frame too large (>2GB)");
+
        defframe(ptxt);
 
        if(0)
diff --git a/test/fixedbugs/bug385_32.go b/test/fixedbugs/bug385_32.go
new file mode 100644 (file)
index 0000000..a009f66
--- /dev/null
@@ -0,0 +1,14 @@
+// [ $O == 6 ] || errchk $G -e $D/$F.go
+
+// Copyright 2011 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.
+
+// Issue 2444
+
+package main
+func main() {
+       var arr [1000200030]int   // ERROR "type .* too large"
+       arr_bkup := arr
+       _ = arr_bkup
+}
\ No newline at end of file
diff --git a/test/fixedbugs/bug385_64.go b/test/fixedbugs/bug385_64.go
new file mode 100644 (file)
index 0000000..701be0d
--- /dev/null
@@ -0,0 +1,15 @@
+// [ $O != 6 ]  || errchk $G -e $D/$F.go
+
+// Copyright 2011 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.
+
+// Issue 2444
+
+package main
+func main() {  // ERROR "stack frame too large"
+       var arr [1000200030]int
+       arr_bkup := arr
+       _ = arr_bkup
+}
+