1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:14:41 -07:00

gc: Nicer errors before miscompiling.

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
This commit is contained in:
Luuk van Dijk 2012-01-10 11:19:22 +01:00
parent 4bcc9c6b5e
commit a6c49098bc
10 changed files with 54 additions and 15 deletions

View 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

View 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*);

View 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))

View 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*);

View 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.

View 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*);

View 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)

View 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)

View File

@ -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
}

View File

@ -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
}