Commit 674458e1 authored by Russ Cox's avatar Russ Cox

gc: bug246

R=ken2
CC=golang-dev
https://golang.org/cl/198057
parent b13b80e5
...@@ -410,6 +410,7 @@ typeinit(void) ...@@ -410,6 +410,7 @@ typeinit(void)
okforarith[i] = 1; okforarith[i] = 1;
okforadd[i] = 1; okforadd[i] = 1;
okforand[i] = 1; okforand[i] = 1;
okforconst[i] = 1;
issimple[i] = 1; issimple[i] = 1;
minintval[i] = mal(sizeof(*minintval[i])); minintval[i] = mal(sizeof(*minintval[i]));
maxintval[i] = mal(sizeof(*maxintval[i])); maxintval[i] = mal(sizeof(*maxintval[i]));
...@@ -419,6 +420,7 @@ typeinit(void) ...@@ -419,6 +420,7 @@ typeinit(void)
okforcmp[i] = 1; okforcmp[i] = 1;
okforadd[i] = 1; okforadd[i] = 1;
okforarith[i] = 1; okforarith[i] = 1;
okforconst[i] = 1;
issimple[i] = 1; issimple[i] = 1;
minfltval[i] = mal(sizeof(*minfltval[i])); minfltval[i] = mal(sizeof(*minfltval[i]));
maxfltval[i] = mal(sizeof(*maxfltval[i])); maxfltval[i] = mal(sizeof(*maxfltval[i]));
...@@ -434,6 +436,9 @@ typeinit(void) ...@@ -434,6 +436,9 @@ typeinit(void)
okforcap[TARRAY] = 1; okforcap[TARRAY] = 1;
okforcap[TCHAN] = 1; okforcap[TCHAN] = 1;
okforconst[TBOOL] = 1;
okforconst[TSTRING] = 1;
okforlen[TARRAY] = 1; okforlen[TARRAY] = 1;
okforlen[TCHAN] = 1; okforlen[TCHAN] = 1;
okforlen[TMAP] = 1; okforlen[TMAP] = 1;
......
...@@ -93,6 +93,9 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -93,6 +93,9 @@ convlit1(Node **np, Type *t, int explicit)
} }
return; return;
case OLITERAL: case OLITERAL:
// target is invalid type for a constant? leave alone.
if(!okforconst[t->etype] && n->type->etype != TNIL)
return;
break; break;
case OLSH: case OLSH:
case ORSH: case ORSH:
...@@ -105,6 +108,7 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -105,6 +108,7 @@ convlit1(Node **np, Type *t, int explicit)
n->type = t; n->type = t;
return; return;
} }
// avoided repeated calculations, errors // avoided repeated calculations, errors
if(cvttype(n->type, t) == 1) { if(cvttype(n->type, t) == 1) {
n->type = t; n->type = t;
...@@ -345,7 +349,6 @@ evconst(Node *n) ...@@ -345,7 +349,6 @@ evconst(Node *n)
case OANDNOT: case OANDNOT:
case OARRAYBYTESTR: case OARRAYBYTESTR:
case OCOM: case OCOM:
case OCONV:
case ODIV: case ODIV:
case OEQ: case OEQ:
case OGE: case OGE:
...@@ -365,6 +368,12 @@ evconst(Node *n) ...@@ -365,6 +368,12 @@ evconst(Node *n)
case OSUB: case OSUB:
case OXOR: case OXOR:
break; break;
case OCONV:
if(n->type == T)
return;
if(!okforconst[n->type->etype] && n->type->etype != TNIL)
return;
break;
} }
nl = n->left; nl = n->left;
......
...@@ -680,6 +680,7 @@ EXTERN uchar okforbool[NTYPE]; ...@@ -680,6 +680,7 @@ EXTERN uchar okforbool[NTYPE];
EXTERN uchar okforcap[NTYPE]; EXTERN uchar okforcap[NTYPE];
EXTERN uchar okforlen[NTYPE]; EXTERN uchar okforlen[NTYPE];
EXTERN uchar okforarith[NTYPE]; EXTERN uchar okforarith[NTYPE];
EXTERN uchar okforconst[NTYPE];
EXTERN uchar* okfor[OEND]; EXTERN uchar* okfor[OEND];
EXTERN uchar iscmp[OEND]; EXTERN uchar iscmp[OEND];
......
...@@ -182,7 +182,7 @@ walkdef(Node *n) ...@@ -182,7 +182,7 @@ walkdef(Node *n)
t = n->type; t = n->type;
if(t != T) { if(t != T) {
convlit(&e, t); convlit(&e, t);
if(!isint[t->etype] && !isfloat[t->etype] && t->etype != TSTRING && t->etype != TBOOL) if(!okforconst[t->etype])
yyerror("invalid constant type %T", t); yyerror("invalid constant type %T", t);
} }
n->val = e->val; n->val = e->val;
......
// $G $D/$F.go || echo BUG: bug246 // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug246
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
...@@ -10,9 +10,13 @@ import "unsafe" ...@@ -10,9 +10,13 @@ import "unsafe"
func main() { func main() {
// works // works
addr := uintptr(0) addr := uintptr(0x234)
_ = (*int)(unsafe.Pointer(addr)) x1 := (*int)(unsafe.Pointer(addr))
// fails // fails
_ = (*int)(unsafe.Pointer(uintptr(0))) x2 := (*int)(unsafe.Pointer(uintptr(0x234)))
if x1 != x2 {
panicln("mismatch", x1, x2)
}
} }
...@@ -150,8 +150,3 @@ throw: interface conversion ...@@ -150,8 +150,3 @@ throw: interface conversion
panic PC=xxx panic PC=xxx
== bugs/ == bugs/
=========== bugs/bug246.go
bugs/bug246.go:17: cannot convert 0 to type unsafe.Pointer
bugs/bug246.go:17: cannot convert 0 (type uintptr) to type *int in conversion
BUG: bug246
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment