Commit e3977f0d authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/gc: warn about slice indexes larger than int in typecheck pass

Fixes GOARCH=386 build.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6810098
parent 3e2a8887
...@@ -828,6 +828,10 @@ reswitch: ...@@ -828,6 +828,10 @@ reswitch:
yyerror("invalid %s index %N (index must be non-negative)", why, n->right); yyerror("invalid %s index %N (index must be non-negative)", why, n->right);
} else if(isfixedarray(t) && t->bound > 0 && mpgetfix(n->right->val.u.xval) >= t->bound) } else if(isfixedarray(t) && t->bound > 0 && mpgetfix(n->right->val.u.xval) >= t->bound)
yyerror("invalid array index %N (out of bounds for %d-element array)", n->right, t->bound); yyerror("invalid array index %N (out of bounds for %d-element array)", n->right, t->bound);
else if(mpcmpfixfix(n->right->val.u.xval, maxintval[TINT]) > 0) {
why = isfixedarray(t) ? "array" : "slice";
yyerror("invalid %s index %N (index too large)", why, n->right);
}
} }
break; break;
...@@ -947,6 +951,8 @@ reswitch: ...@@ -947,6 +951,8 @@ reswitch:
yyerror("invalid slice index %N (index must be non-negative)", n->right->left); yyerror("invalid slice index %N (index must be non-negative)", n->right->left);
else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->left->val.u.xval) > tp->bound) else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->left->val.u.xval) > tp->bound)
yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->left, tp->bound); yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->left, tp->bound);
else if(mpcmpfixfix(n->right->left->val.u.xval, maxintval[TINT]) > 0)
yyerror("invalid slice index %N (index too large)", n->right->left);
} }
} }
if(n->right->right != N) { if(n->right->right != N) {
...@@ -961,6 +967,8 @@ reswitch: ...@@ -961,6 +967,8 @@ reswitch:
yyerror("invalid slice index %N (index must be non-negative)", n->right->right); yyerror("invalid slice index %N (index must be non-negative)", n->right->right);
else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->right->val.u.xval) > tp->bound) else if(tp != nil && tp->bound > 0 && mpgetfix(n->right->right->val.u.xval) > tp->bound)
yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->right, tp->bound); yyerror("invalid slice index %N (out of bounds for %d-element array)", n->right->right, tp->bound);
else if(mpcmpfixfix(n->right->right->val.u.xval, maxintval[TINT]) > 0)
yyerror("invalid slice index %N (index too large)", n->right->right);
} }
} }
goto ret; goto ret;
......
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