From 9f032217e78085cabbc4d065f3ab2a8a8c74cee7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 16 Oct 2008 15:59:31 -0700 Subject: diagnose various conversion problems R=ken OCL=17320 CL=17320 --- src/cmd/gc/const.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/cmd/gc/const.c') diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index b624e2aba..9ee33ad11 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -8,7 +8,7 @@ void convlit(Node *n, Type *t) { - int et; + int et, wt; if(n == N || t == T) return; @@ -25,18 +25,10 @@ convlit(Node *n, Type *t) } et = t->etype; - switch(et) { - case TARRAY: - case TFUNC: - case TCHAN: - case TMAP: - case TSTRUCT: -// case TPTR32: -// case TPTR64: - return; - } - switch(whatis(n)) { + wt = whatis(n); + + switch(wt) { default: goto bad1; @@ -125,6 +117,8 @@ convlit(Node *n, Type *t) goto bad2; if(mpcmpfltfix(fv, maxintval[et]) > 0) goto bad2; + if(floor(mpgetflt(fv)) != mpgetflt(fv)) + goto bad3; n->val.u.xval = mal(sizeof(*n->val.u.xval)); mpmovefltfix(n->val.u.xval, fv); n->val.ctype = CTINT; @@ -144,12 +138,16 @@ convlit(Node *n, Type *t) return; bad1: - yyerror("illegal conversion of constant to %T", t); + yyerror("illegal conversion of %W to %T", wt, t); return; bad2: yyerror("overflow converting constant to %T", t); return; + +bad3: + yyerror("cannot convert non-integer constant to %T", t); + return; } void @@ -212,7 +210,7 @@ evconst(Node *n) nl->val.ctype = CTFLT; wl = whatis(nl); } else { - yyerror("illegal combination of literals %E %E", nl->etype, nr->etype); + yyerror("illegal combination of literals %O %E, %E", n->op, wl, wr); return; } } @@ -230,7 +228,7 @@ evconst(Node *n) switch(TUP(n->op, wl)) { default: - yyerror("illegal combination of literals %O %E", n->op, nl->etype); + yyerror("illegal literal %O %E", n->op, wl); return; case TUP(OADD, Wlitint): -- cgit v1.2.3