diff options
author | Ken Thompson <ken@golang.org> | 2010-06-29 12:48:24 -0700 |
---|---|---|
committer | Ken Thompson <ken@golang.org> | 2010-06-29 12:48:24 -0700 |
commit | 90dfbd4d0a94f639df519aeb4767ffd84772b0fc (patch) | |
tree | 9e8bdf7944bb23a2dd2cfdeb53c933a97a772181 /src | |
parent | 3dca3636339e1c559c6e54aac02572a078d3acb2 (diff) | |
download | golang-90dfbd4d0a94f639df519aeb4767ffd84772b0fc.tar.gz |
code gen bug in len(nil) and cap(nil)
fixes issue 892
R=rsc
CC=golang-dev
http://codereview.appspot.com/1745042
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/5g/gsubr.c | 4 | ||||
-rw-r--r-- | src/cmd/6g/gsubr.c | 4 | ||||
-rw-r--r-- | src/cmd/8g/gsubr.c | 4 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd/5g/gsubr.c b/src/cmd/5g/gsubr.c index ea6ab1d70..700602c35 100644 --- a/src/cmd/5g/gsubr.c +++ b/src/cmd/5g/gsubr.c @@ -1137,6 +1137,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OLEN: // len of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // len(nil) a->offset += Array_nel; if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) checkoffset(a, canemitcode); @@ -1145,6 +1147,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OCAP: // cap of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // cap(nil) a->offset += Array_cap; if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero) checkoffset(a, canemitcode); diff --git a/src/cmd/6g/gsubr.c b/src/cmd/6g/gsubr.c index 1c11b14ae..52ff6fdea 100644 --- a/src/cmd/6g/gsubr.c +++ b/src/cmd/6g/gsubr.c @@ -1079,6 +1079,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OLEN: // len of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // len(nil) a->etype = TUINT; a->offset += Array_nel; if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) @@ -1088,6 +1090,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OCAP: // cap of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // cap(nil) a->etype = TUINT; a->offset += Array_cap; if(a->offset >= unmappedzero && a->offset-Array_cap < unmappedzero) diff --git a/src/cmd/8g/gsubr.c b/src/cmd/8g/gsubr.c index 3e85b7e30..6890c683e 100644 --- a/src/cmd/8g/gsubr.c +++ b/src/cmd/8g/gsubr.c @@ -1789,6 +1789,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OLEN: // len of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // len(nil) a->etype = TUINT; a->offset += Array_nel; if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) @@ -1798,6 +1800,8 @@ naddr(Node *n, Addr *a, int canemitcode) case OCAP: // cap of string or slice naddr(n->left, a, canemitcode); + if(a->type == D_CONST && a->offset == 0) + break; // cap(nil) a->etype = TUINT; a->offset += Array_cap; if(a->offset >= unmappedzero && a->offset-Array_nel < unmappedzero) |