From: Shenghou Ma Date: Sun, 23 Feb 2014 21:31:48 +0000 (-0500) Subject: cmd/gc: diagnose "make([]T, non-integer)" correctly. X-Git-Tag: go1.3beta1~625 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e33e47e844cdce5a5dedfd0c1c72e480f12db6f1;p=gostls13.git cmd/gc: diagnose "make([]T, non-integer)" correctly. Fixes #7223. LGTM=rsc R=golang-codereviews, gobot, rsc CC=golang-codereviews https://golang.org/cl/63040043 --- diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index ac2e8a4559..05efab4040 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -3231,29 +3231,38 @@ static int checkmake(Type *t, char *arg, Node *n) { if(n->op == OLITERAL) { - n->val = toint(n->val); - if(mpcmpfixc(n->val.u.xval, 0) < 0) { - yyerror("negative %s argument in make(%T)", arg, t); - return -1; - } - if(mpcmpfixfix(n->val.u.xval, maxintval[TINT]) > 0) { - yyerror("%s argument too large in make(%T)", arg, t); - return -1; + switch(n->val.ctype) { + case CTINT: + case CTRUNE: + case CTFLT: + case CTCPLX: + n->val = toint(n->val); + if(mpcmpfixc(n->val.u.xval, 0) < 0) { + yyerror("negative %s argument in make(%T)", arg, t); + return -1; + } + if(mpcmpfixfix(n->val.u.xval, maxintval[TINT]) > 0) { + yyerror("%s argument too large in make(%T)", arg, t); + return -1; + } + + // Delay defaultlit until after we've checked range, to avoid + // a redundant "constant NNN overflows int" error. + defaultlit(&n, types[TINT]); + return 0; + default: + break; } - - // Delay defaultlit until after we've checked range, to avoid - // a redundant "constant NNN overflows int" error. - defaultlit(&n, types[TINT]); - return 0; } - - // Defaultlit still necessary for non-constant: n might be 1<type->etype]) { + if(!isint[n->type->etype] && n->type->etype != TIDEAL) { yyerror("non-integer %s argument in make(%T) - %T", arg, t, n->type); return -1; } + + // Defaultlit still necessary for non-constant: n might be 1<