1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -07:00

code gen bug in len(nil) and cap(nil)

fixes #892

R=rsc
CC=golang-dev
https://golang.org/cl/1745042
This commit is contained in:
Ken Thompson 2010-06-29 12:48:24 -07:00
parent 00ad47f906
commit 1246ad8390
3 changed files with 12 additions and 0 deletions

View File

@ -1137,6 +1137,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OLEN: case OLEN:
// len of string or slice // len of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // len(nil)
a->offset += Array_nel; a->offset += Array_nel;
if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero)
checkoffset(a, canemitcode); checkoffset(a, canemitcode);
@ -1145,6 +1147,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OCAP: case OCAP:
// cap of string or slice // cap of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // cap(nil)
a->offset += Array_cap; a->offset += Array_cap;
if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero)
checkoffset(a, canemitcode); checkoffset(a, canemitcode);

View File

@ -1079,6 +1079,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OLEN: case OLEN:
// len of string or slice // len of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // len(nil)
a->etype = TUINT; a->etype = TUINT;
a->offset += Array_nel; a->offset += Array_nel;
if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero)
@ -1088,6 +1090,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OCAP: case OCAP:
// cap of string or slice // cap of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // cap(nil)
a->etype = TUINT; a->etype = TUINT;
a->offset += Array_cap; a->offset += Array_cap;
if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero)

View File

@ -1789,6 +1789,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OLEN: case OLEN:
// len of string or slice // len of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // len(nil)
a->etype = TUINT; a->etype = TUINT;
a->offset += Array_nel; a->offset += Array_nel;
if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero)
@ -1798,6 +1800,8 @@ naddr(Node *n, Addr *a, int canemitcode)
case OCAP: case OCAP:
// cap of string or slice // cap of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0)
break; // cap(nil)
a->etype = TUINT; a->etype = TUINT;
a->offset += Array_cap; a->offset += Array_cap;
if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero)