drop check in range over array.
drop check in [256]array indexed by byte.
R=ken2
https://golang.org/cl/163088
v = mpgetfix(nr->val.u.xval);
if(isslice(nl->type)) {
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
n1 = n3;
n1.op = OINDREG;
n1.type = types[tptr];
gmove(&n1, &n2);
regfree(&n1);
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
// check bounds
regalloc(&n4, types[TUINT32], N);
if(isslice(nl->type)) {
v = mpgetfix(r->val.u.xval);
if(o & ODynam) {
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
n1 = *reg;
n1.op = OINDREG;
n1.type = types[tptr];
v = mpgetfix(nr->val.u.xval);
if(isslice(nl->type)) {
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
n1 = n3;
n1.op = OINDREG;
n1.type = types[tptr];
gmove(&n1, &n2);
regfree(&n1);
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
// check bounds
if(isslice(nl->type)) {
n1 = n3;
agen(l, reg);
}
+ if(!(o & ODynam) && l->type->width >= unmappedzero && l->op == OIND) {
+ // cannot rely on page protections to
+ // catch array ptr == 0, so dereference.
+ n2 = *reg;
+ n2.op = OINDREG;
+ n2.type = types[TUINT8];
+ n2.xoffset = 0;
+ gins(ATESTB, nodintconst(0), &n2);
+ }
+
// check bounds
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
if(o & ODynam) {
n2 = *reg;
n2.op = OINDREG;
n2.type = types[tptr];
n2.xoffset = Array_nel;
} else {
- if(l->type->width >= unmappedzero && l->op == OIND) {
- // cannot rely on page protections to
- // catch array ptr == 0, so dereference.
- n2 = *reg;
- n2.op = OINDREG;
- n2.type = types[TUINT8];
- n2.xoffset = 0;
- gins(ATESTB, nodintconst(0), &n2);
- }
nodconst(&n2, types[TUINT64], l->type->bound);
}
gins(optoas(OCMP, types[TUINT32]), reg1, &n2);
v = mpgetfix(r->val.u.xval);
if(o & ODynam) {
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
n1 = *reg;
n1.op = OINDREG;
n1.type = types[tptr];
v = mpgetfix(nr->val.u.xval);
if(isslice(nl->type)) {
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
n1 = n3;
n1.op = OINDREG;
n1.type = types[tptr];
n1.xoffset = Array_array;
gmove(&n1, &n3);
} else
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
if(v < 0)
yyerror("out of bounds on array");
else
gmove(&n1, &n2);
regfree(&n1);
- if(!debug['B']) {
+ if(!debug['B'] && !n->etype) {
// check bounds
if(isslice(nl->type)) {
n1 = n3;
Node *ohv1, *hv1, *hv2; // hidden (old) val 1, 2
Node *ha, *hit; // hidden aggregate, iterator
Node *a, *v1, *v2; // not hidden aggregate, val 1, 2
- Node *fn;
+ Node *fn, *tmp;
NodeList *body, *init;
Type *th, *t;
n->nincr = nod(OASOP, hv1, nodintconst(1));
n->nincr->etype = OADD;
body = list1(nod(OAS, v1, hv1));
- if(v2)
- body = list(body, nod(OAS, v2, nod(OINDEX, ha, hv1)));
+ if(v2) {
+ tmp = nod(OINDEX, ha, hv1);
+ tmp->etype = 1; // no bounds check
+ body = list(body, nod(OAS, v2, tmp));
+ }
break;
case TMAP:
case OINDEX:
walkexpr(&n->left, init);
walkexpr(&n->right, init);
+
+ // if range of type cannot exceed static array bound,
+ // disable bounds check
+ if(!isslice(n->left->type))
+ if(n->right->type->width < 4)
+ if((1<<(8*n->right->type->width)) <= n->left->type->bound)
+ n->etype = 1;
+
goto ret;
case OINDEXMAP: