tree.c (80284) | tree.c (91592) |
---|---|
1/* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ | 1/* $NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $ */ |
2 3/* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 | 2 3/* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 16 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 |
34#ifndef lint 35static const char rcsid[] = 36 "$FreeBSD: head/usr.bin/xlint/lint1/tree.c 80284 2001-07-24 14:02:07Z obrien $"; | 34#include <sys/cdefs.h> 35#if defined(__RCSID) && !defined(lint) 36__RCSID("$NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $"); |
37#endif | 37#endif |
38__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/tree.c 91592 2002-03-03 15:12:50Z markm $"); |
|
38 39#include <stdlib.h> 40#include <string.h> 41#include <float.h> 42#include <limits.h> 43#include <math.h> 44 45#include "lint1.h" | 39 40#include <stdlib.h> 41#include <string.h> 42#include <float.h> 43#include <limits.h> 44#include <math.h> 45 46#include "lint1.h" |
46#include "y.tab.h" | 47#include "cgram.h" |
47 48/* Various flags for each operator. */ 49static mod_t modtab[NOPS]; 50 | 48 49/* Various flags for each operator. */ 50static mod_t modtab[NOPS]; 51 |
51static tnode_t *getinode __P((tspec_t, quad_t)); 52static void ptrcmpok __P((op_t, tnode_t *, tnode_t *)); 53static int asgntypok __P((op_t, int, tnode_t *, tnode_t *)); 54static void chkbeop __P((op_t, tnode_t *, tnode_t *)); 55static void chkeop2 __P((op_t, int, tnode_t *, tnode_t *)); 56static void chkeop1 __P((op_t, int, tnode_t *, tnode_t *)); 57static tnode_t *mktnode __P((op_t, type_t *, tnode_t *, tnode_t *)); 58static void balance __P((op_t, tnode_t **, tnode_t **)); 59static void incompat __P((op_t, tspec_t, tspec_t)); 60static void illptrc __P((mod_t *, type_t *, type_t *)); 61static void mrgqual __P((type_t **, type_t *, type_t *)); 62static int conmemb __P((type_t *)); 63static void ptconv __P((int, tspec_t, tspec_t, type_t *, tnode_t *)); 64static void iiconv __P((op_t, int, tspec_t, tspec_t, type_t *, tnode_t *)); 65static void piconv __P((op_t, tspec_t, type_t *, tnode_t *)); 66static void ppconv __P((op_t, tnode_t *, type_t *)); 67static tnode_t *bldstr __P((op_t, tnode_t *, tnode_t *)); 68static tnode_t *bldincdec __P((op_t, tnode_t *)); 69static tnode_t *bldamper __P((tnode_t *, int)); 70static tnode_t *bldplmi __P((op_t, tnode_t *, tnode_t *)); 71static tnode_t *bldshft __P((op_t, tnode_t *, tnode_t *)); 72static tnode_t *bldcol __P((tnode_t *, tnode_t *)); 73static tnode_t *bldasgn __P((op_t, tnode_t *, tnode_t *)); 74static tnode_t *plength __P((type_t *)); 75static tnode_t *fold __P((tnode_t *)); 76static tnode_t *foldtst __P((tnode_t *)); 77static tnode_t *foldflt __P((tnode_t *)); 78static tnode_t *chkfarg __P((type_t *, tnode_t *)); 79static tnode_t *parg __P((int, type_t *, tnode_t *)); 80static void nulleff __P((tnode_t *)); 81static void displexpr __P((tnode_t *, int)); 82static void chkaidx __P((tnode_t *, int)); 83static void chkcomp __P((op_t, tnode_t *, tnode_t *)); 84static void precconf __P((tnode_t *)); | 52static tnode_t *getinode(tspec_t, int64_t); 53static void ptrcmpok(op_t, tnode_t *, tnode_t *); 54static int asgntypok(op_t, int, tnode_t *, tnode_t *); 55static void chkbeop(op_t, tnode_t *, tnode_t *); 56static void chkeop2(op_t, int, tnode_t *, tnode_t *); 57static void chkeop1(op_t, int, tnode_t *, tnode_t *); 58static tnode_t *mktnode(op_t, type_t *, tnode_t *, tnode_t *); 59static void balance(op_t, tnode_t **, tnode_t **); 60static void incompat(op_t, tspec_t, tspec_t); 61static void illptrc(mod_t *, type_t *, type_t *); 62static void mrgqual(type_t **, type_t *, type_t *); 63static int conmemb(type_t *); 64static void ptconv(int, tspec_t, tspec_t, type_t *, tnode_t *); 65static void iiconv(op_t, int, tspec_t, tspec_t, type_t *, tnode_t *); 66static void piconv(op_t, tspec_t, type_t *, tnode_t *); 67static void ppconv(op_t, tnode_t *, type_t *); 68static tnode_t *bldstr(op_t, tnode_t *, tnode_t *); 69static tnode_t *bldincdec(op_t, tnode_t *); 70static tnode_t *bldamper(tnode_t *, int); 71static tnode_t *bldplmi(op_t, tnode_t *, tnode_t *); 72static tnode_t *bldshft(op_t, tnode_t *, tnode_t *); 73static tnode_t *bldcol(tnode_t *, tnode_t *); 74static tnode_t *bldasgn(op_t, tnode_t *, tnode_t *); 75static tnode_t *plength(type_t *); 76static tnode_t *fold(tnode_t *); 77static tnode_t *foldtst(tnode_t *); 78static tnode_t *foldflt(tnode_t *); 79static tnode_t *chkfarg(type_t *, tnode_t *); 80static tnode_t *parg(int, type_t *, tnode_t *); 81static void nulleff(tnode_t *); 82static void displexpr(tnode_t *, int); 83static void chkaidx(tnode_t *, int); 84static void chkcomp(op_t, tnode_t *, tnode_t *); 85static void precconf(tnode_t *); |
85 86/* 87 * Initialize mods of operators. 88 */ 89void | 86 87/* 88 * Initialize mods of operators. 89 */ 90void |
90initmtab() | 91initmtab(void) |
91{ 92 static struct { 93 op_t op; 94 mod_t m; 95 } imods[] = { 96 { ARROW, { 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0, 97 "->" } }, 98 { POINT, { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, --- 114 unchanged lines hidden (view full) --- 213 STRUCT_ASSIGN(modtab[imods[i].op], imods[i].m); 214} 215 216/* 217 * Increase degree of reference. 218 * This is most often used to change type "T" in type "pointer to T". 219 */ 220type_t * | 92{ 93 static struct { 94 op_t op; 95 mod_t m; 96 } imods[] = { 97 { ARROW, { 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0, 98 "->" } }, 99 { POINT, { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, --- 114 unchanged lines hidden (view full) --- 214 STRUCT_ASSIGN(modtab[imods[i].op], imods[i].m); 215} 216 217/* 218 * Increase degree of reference. 219 * This is most often used to change type "T" in type "pointer to T". 220 */ 221type_t * |
221incref(tp, t) 222 type_t *tp; 223 tspec_t t; | 222incref(type_t *tp, tspec_t t) |
224{ 225 type_t *tp2; 226 227 tp2 = getblk(sizeof (type_t)); 228 tp2->t_tspec = t; 229 tp2->t_subt = tp; 230 return (tp2); 231} 232 233/* 234 * same for use in expressions 235 */ 236type_t * | 223{ 224 type_t *tp2; 225 226 tp2 = getblk(sizeof (type_t)); 227 tp2->t_tspec = t; 228 tp2->t_subt = tp; 229 return (tp2); 230} 231 232/* 233 * same for use in expressions 234 */ 235type_t * |
237tincref(tp, t) 238 type_t *tp; 239 tspec_t t; | 236tincref(type_t *tp, tspec_t t) |
240{ 241 type_t *tp2; 242 243 tp2 = tgetblk(sizeof (type_t)); 244 tp2->t_tspec = t; 245 tp2->t_subt = tp; 246 return (tp2); 247} 248 249/* 250 * Create a node for a constant. 251 */ 252tnode_t * | 237{ 238 type_t *tp2; 239 240 tp2 = tgetblk(sizeof (type_t)); 241 tp2->t_tspec = t; 242 tp2->t_subt = tp; 243 return (tp2); 244} 245 246/* 247 * Create a node for a constant. 248 */ 249tnode_t * |
253getcnode(tp, v) 254 type_t *tp; 255 val_t *v; | 250getcnode(type_t *tp, val_t *v) |
256{ 257 tnode_t *n; 258 259 n = getnode(); 260 n->tn_op = CON; 261 n->tn_type = tp; 262 n->tn_val = tgetblk(sizeof (val_t)); 263 n->tn_val->v_tspec = tp->t_tspec; 264 n->tn_val->v_ansiu = v->v_ansiu; 265 n->tn_val->v_u = v->v_u; 266 free(v); 267 return (n); 268} 269 270/* 271 * Create a node for a integer constant. 272 */ 273static tnode_t * | 251{ 252 tnode_t *n; 253 254 n = getnode(); 255 n->tn_op = CON; 256 n->tn_type = tp; 257 n->tn_val = tgetblk(sizeof (val_t)); 258 n->tn_val->v_tspec = tp->t_tspec; 259 n->tn_val->v_ansiu = v->v_ansiu; 260 n->tn_val->v_u = v->v_u; 261 free(v); 262 return (n); 263} 264 265/* 266 * Create a node for a integer constant. 267 */ 268static tnode_t * |
274getinode(t, q) 275 tspec_t t; 276 quad_t q; | 269getinode(tspec_t t, int64_t q) |
277{ 278 tnode_t *n; 279 280 n = getnode(); 281 n->tn_op = CON; 282 n->tn_type = gettyp(t); 283 n->tn_val = tgetblk(sizeof (val_t)); 284 n->tn_val->v_tspec = t; 285 n->tn_val->v_quad = q; 286 return (n); 287} 288 289/* 290 * Create a node for a name (symbol table entry). 291 * ntok is the token which follows the name. 292 */ 293tnode_t * | 270{ 271 tnode_t *n; 272 273 n = getnode(); 274 n->tn_op = CON; 275 n->tn_type = gettyp(t); 276 n->tn_val = tgetblk(sizeof (val_t)); 277 n->tn_val->v_tspec = t; 278 n->tn_val->v_quad = q; 279 return (n); 280} 281 282/* 283 * Create a node for a name (symbol table entry). 284 * ntok is the token which follows the name. 285 */ 286tnode_t * |
294getnnode(sym, ntok) 295 sym_t *sym; 296 int ntok; | 287getnnode(sym_t *sym, int ntok) |
297{ 298 tnode_t *n; 299 300 if (sym->s_scl == NOSCL) { 301 sym->s_scl = EXTERN; 302 sym->s_def = DECL; 303 if (ntok == T_LPARN) { 304 if (sflag) { --- 29 unchanged lines hidden (view full) --- 334 335 return (n); 336} 337 338/* 339 * Create a node for a string. 340 */ 341tnode_t * | 288{ 289 tnode_t *n; 290 291 if (sym->s_scl == NOSCL) { 292 sym->s_scl = EXTERN; 293 sym->s_def = DECL; 294 if (ntok == T_LPARN) { 295 if (sflag) { --- 29 unchanged lines hidden (view full) --- 325 326 return (n); 327} 328 329/* 330 * Create a node for a string. 331 */ 332tnode_t * |
342getsnode(strg) 343 strg_t *strg; | 333getsnode(strg_t *strg) |
344{ 345 size_t len; 346 tnode_t *n; 347 348 len = strg->st_len; 349 350 n = getnode(); 351 --- 21 unchanged lines hidden (view full) --- 373 return (n); 374} 375 376/* 377 * Returns a symbol which has the same name as the msym argument and is a 378 * member of the struct or union specified by the tn argument. 379 */ 380sym_t * | 334{ 335 size_t len; 336 tnode_t *n; 337 338 len = strg->st_len; 339 340 n = getnode(); 341 --- 21 unchanged lines hidden (view full) --- 363 return (n); 364} 365 366/* 367 * Returns a symbol which has the same name as the msym argument and is a 368 * member of the struct or union specified by the tn argument. 369 */ 370sym_t * |
381strmemb(tn, op, msym) 382 tnode_t *tn; 383 op_t op; 384 sym_t *msym; | 371strmemb(tnode_t *tn, op_t op, sym_t *msym) |
385{ 386 str_t *str; 387 type_t *tp; 388 sym_t *sym, *csym; 389 int eq; 390 tspec_t t; 391 392 /* --- 140 unchanged lines hidden (view full) --- 533 * Create a tree node. Called for most operands except function calls, 534 * sizeof and casts. 535 * 536 * op operator 537 * ln left operand 538 * rn if not NULL, right operand 539 */ 540tnode_t * | 372{ 373 str_t *str; 374 type_t *tp; 375 sym_t *sym, *csym; 376 int eq; 377 tspec_t t; 378 379 /* --- 140 unchanged lines hidden (view full) --- 520 * Create a tree node. Called for most operands except function calls, 521 * sizeof and casts. 522 * 523 * op operator 524 * ln left operand 525 * rn if not NULL, right operand 526 */ 527tnode_t * |
541build(op, ln, rn) 542 op_t op; 543 tnode_t *ln, *rn; | 528build(op_t op, tnode_t *ln, tnode_t *rn) |
544{ 545 mod_t *mp; 546 tnode_t *ntn; 547 type_t *rtp; 548 549 mp = &modtab[op]; 550 551 /* If there was an error in one of the operands, return. */ --- 114 unchanged lines hidden (view full) --- 666 default: 667 rtp = mp->m_logop ? gettyp(INT) : ln->tn_type; 668 if (!mp->m_binary && rn != NULL) 669 lerror("build() 1"); 670 ntn = mktnode(op, rtp, ln, rn); 671 break; 672 } 673 | 529{ 530 mod_t *mp; 531 tnode_t *ntn; 532 type_t *rtp; 533 534 mp = &modtab[op]; 535 536 /* If there was an error in one of the operands, return. */ --- 114 unchanged lines hidden (view full) --- 651 default: 652 rtp = mp->m_logop ? gettyp(INT) : ln->tn_type; 653 if (!mp->m_binary && rn != NULL) 654 lerror("build() 1"); 655 ntn = mktnode(op, rtp, ln, rn); 656 break; 657 } 658 |
674 /* Return if an error occured. */ | 659 /* Return if an error occurred. */ |
675 if (ntn == NULL) 676 return (NULL); 677 678 /* Print a warning if precedence confusion is possible */ 679 if (mp->m_tpconf) 680 precconf(ntn); 681 682 /* --- 30 unchanged lines hidden (view full) --- 713/* 714 * Perform class conversions. 715 * 716 * Arrays of type T are converted into pointers to type T. 717 * Functions are converted to pointers to functions. 718 * Lvalues are converted to rvalues. 719 */ 720tnode_t * | 660 if (ntn == NULL) 661 return (NULL); 662 663 /* Print a warning if precedence confusion is possible */ 664 if (mp->m_tpconf) 665 precconf(ntn); 666 667 /* --- 30 unchanged lines hidden (view full) --- 698/* 699 * Perform class conversions. 700 * 701 * Arrays of type T are converted into pointers to type T. 702 * Functions are converted to pointers to functions. 703 * Lvalues are converted to rvalues. 704 */ 705tnode_t * |
721cconv(tn) 722 tnode_t *tn; | 706cconv(tnode_t *tn) |
723{ 724 type_t *tp; 725 726 /* 727 * Array-lvalue (array of type T) is converted into rvalue 728 * (pointer to type T) 729 */ 730 if (tn->tn_type->t_tspec == ARRAY) { --- 27 unchanged lines hidden (view full) --- 758/* 759 * Perform most type checks. First the types are checked using 760 * informations from modtab[]. After that it is done by hand for 761 * more complicated operators and type combinations. 762 * 763 * If the types are ok, typeok() returns 1, otherwise 0. 764 */ 765int | 707{ 708 type_t *tp; 709 710 /* 711 * Array-lvalue (array of type T) is converted into rvalue 712 * (pointer to type T) 713 */ 714 if (tn->tn_type->t_tspec == ARRAY) { --- 27 unchanged lines hidden (view full) --- 742/* 743 * Perform most type checks. First the types are checked using 744 * informations from modtab[]. After that it is done by hand for 745 * more complicated operators and type combinations. 746 * 747 * If the types are ok, typeok() returns 1, otherwise 0. 748 */ 749int |
766typeok(op, arg, ln, rn) 767 op_t op; 768 int arg; 769 tnode_t *ln, *rn; | 750typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn) |
770{ 771 mod_t *mp; | 751{ 752 mod_t *mp; |
772 tspec_t lt, rt, lst, rst, olt, ort; 773 type_t *ltp, *rtp, *lstp, *rstp; | 753 tspec_t lt, rt = NOTSPEC, lst = NOTSPEC, rst = NOTSPEC, olt = NOTSPEC, 754 ort = NOTSPEC; 755 type_t *ltp, *rtp = NULL, *lstp = NULL, *rstp = NULL; |
774 tnode_t *tn; 775 776 mp = &modtab[op]; 777 778 if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR) 779 lst = (lstp = ltp->t_subt)->t_tspec; 780 if (mp->m_binary) { 781 if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR) --- 20 unchanged lines hidden (view full) --- 802 } 803 } 804 805 if (op == SHL || op == SHR || op == SHLASS || op == SHRASS) { 806 /* 807 * For these operations we need the types before promotion 808 * and balancing. 809 */ | 756 tnode_t *tn; 757 758 mp = &modtab[op]; 759 760 if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR) 761 lst = (lstp = ltp->t_subt)->t_tspec; 762 if (mp->m_binary) { 763 if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR) --- 20 unchanged lines hidden (view full) --- 784 } 785 } 786 787 if (op == SHL || op == SHR || op == SHLASS || op == SHRASS) { 788 /* 789 * For these operations we need the types before promotion 790 * and balancing. 791 */ |
810 for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) ; | 792 for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) 793 continue; |
811 olt = tn->tn_type->t_tspec; | 794 olt = tn->tn_type->t_tspec; |
812 for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) ; | 795 for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) 796 continue; |
813 ort = tn->tn_type->t_tspec; 814 } | 797 ort = tn->tn_type->t_tspec; 798 } |
815 | 799 |
816 switch (op) { 817 case POINT: 818 /* 819 * Most errors required by ANSI C are reported in strmemb(). 820 * Here we only must check for totaly wrong things. 821 */ 822 if (lt == FUNC || lt == VOID || ltp->t_isfield || 823 ((lt != STRUCT && lt != UNION) && !ln->tn_lvalue)) { --- 150 unchanged lines hidden (view full) --- 974 /* semantics of %s change in ANSI C; use ... */ 975 warning(118, mp->m_name); 976 } 977 shift: 978 if (rn->tn_op == CON) { 979 if (!isutyp(rt) && rn->tn_val->v_quad < 0) { 980 /* negative shift */ 981 warning(121); | 800 switch (op) { 801 case POINT: 802 /* 803 * Most errors required by ANSI C are reported in strmemb(). 804 * Here we only must check for totaly wrong things. 805 */ 806 if (lt == FUNC || lt == VOID || ltp->t_isfield || 807 ((lt != STRUCT && lt != UNION) && !ln->tn_lvalue)) { --- 150 unchanged lines hidden (view full) --- 958 /* semantics of %s change in ANSI C; use ... */ 959 warning(118, mp->m_name); 960 } 961 shift: 962 if (rn->tn_op == CON) { 963 if (!isutyp(rt) && rn->tn_val->v_quad < 0) { 964 /* negative shift */ 965 warning(121); |
982 } else if ((u_quad_t)rn->tn_val->v_quad == size(lt)) { | 966 } else if ((uint64_t)rn->tn_val->v_quad == size(lt)) { |
983 /* shift equal to size fo object */ 984 warning(267); | 967 /* shift equal to size fo object */ 968 warning(267); |
985 } else if ((u_quad_t)rn->tn_val->v_quad > size(lt)) { | 969 } else if ((uint64_t)rn->tn_val->v_quad > size(lt)) { |
986 /* shift greater than size of object */ 987 warning(122); 988 } 989 } 990 break; 991 case EQ: 992 case NE: 993 /* --- 135 unchanged lines hidden (view full) --- 1129 warning(115, "left ", mp->m_name); 1130 } 1131 break; 1132 case COMMA: 1133 if (!modtab[ln->tn_op].m_sideeff) 1134 nulleff(ln); 1135 break; 1136 /* LINTED (enumeration values not handled in switch) */ | 970 /* shift greater than size of object */ 971 warning(122); 972 } 973 } 974 break; 975 case EQ: 976 case NE: 977 /* --- 135 unchanged lines hidden (view full) --- 1113 warning(115, "left ", mp->m_name); 1114 } 1115 break; 1116 case COMMA: 1117 if (!modtab[ln->tn_op].m_sideeff) 1118 nulleff(ln); 1119 break; 1120 /* LINTED (enumeration values not handled in switch) */ |
1137 default: | 1121 case CON: 1122 case CASE: 1123 case PUSH: 1124 case LOAD: 1125 case ICALL: 1126 case CVT: 1127 case CALL: 1128 case FSEL: 1129 case STRING: 1130 case NAME: 1131 case LOGOR: 1132 case LOGAND: 1133 case OR: 1134 case XOR: 1135 case AND: 1136 case MOD: 1137 case DIV: 1138 case MULT: 1139 case UMINUS: 1140 case UPLUS: 1141 case DEC: 1142 case INC: 1143 case COMPL: 1144 case NOT: 1145 case NOOP: 1146 break; |
1138 } 1139 1140 if (mp->m_badeop && 1141 (ltp->t_isenum || (mp->m_binary && rtp->t_isenum))) { 1142 chkbeop(op, ln, rn); 1143 } else if (mp->m_enumop && (ltp->t_isenum && rtp->t_isenum)) { 1144 chkeop2(op, arg, ln, rn); 1145 } else if (mp->m_enumop && (ltp->t_isenum || rtp->t_isenum)) { 1146 chkeop1(op, arg, ln, rn); 1147 } 1148 1149 return (1); 1150} 1151 1152static void | 1147 } 1148 1149 if (mp->m_badeop && 1150 (ltp->t_isenum || (mp->m_binary && rtp->t_isenum))) { 1151 chkbeop(op, ln, rn); 1152 } else if (mp->m_enumop && (ltp->t_isenum && rtp->t_isenum)) { 1153 chkeop2(op, arg, ln, rn); 1154 } else if (mp->m_enumop && (ltp->t_isenum || rtp->t_isenum)) { 1155 chkeop1(op, arg, ln, rn); 1156 } 1157 1158 return (1); 1159} 1160 1161static void |
1153ptrcmpok(op, ln, rn) 1154 op_t op; 1155 tnode_t *ln, *rn; | 1162ptrcmpok(op_t op, tnode_t *ln, tnode_t *rn) |
1156{ 1157 type_t *ltp, *rtp; 1158 tspec_t lt, rt; 1159 const char *lts, *rts; 1160 1161 lt = (ltp = ln->tn_type)->t_subt->t_tspec; 1162 rt = (rtp = rn->tn_type)->t_subt->t_tspec; 1163 --- 21 unchanged lines hidden (view full) --- 1185} 1186 1187/* 1188 * Checks type compatibility for ASSIGN, INIT, FARG and RETURN 1189 * and prints warnings/errors if necessary. 1190 * If the types are (almost) compatible, 1 is returned, otherwise 0. 1191 */ 1192static int | 1163{ 1164 type_t *ltp, *rtp; 1165 tspec_t lt, rt; 1166 const char *lts, *rts; 1167 1168 lt = (ltp = ln->tn_type)->t_subt->t_tspec; 1169 rt = (rtp = rn->tn_type)->t_subt->t_tspec; 1170 --- 21 unchanged lines hidden (view full) --- 1192} 1193 1194/* 1195 * Checks type compatibility for ASSIGN, INIT, FARG and RETURN 1196 * and prints warnings/errors if necessary. 1197 * If the types are (almost) compatible, 1 is returned, otherwise 0. 1198 */ 1199static int |
1193asgntypok(op, arg, ln, rn) 1194 op_t op; 1195 int arg; 1196 tnode_t *ln, *rn; | 1200asgntypok(op_t op, int arg, tnode_t *ln, tnode_t *rn) |
1197{ | 1201{ |
1198 tspec_t lt, rt, lst, rst; 1199 type_t *ltp, *rtp, *lstp, *rstp; | 1202 tspec_t lt, rt, lst = NOTSPEC, rst = NOTSPEC; 1203 type_t *ltp, *rtp, *lstp = NULL, *rstp = NULL; |
1200 mod_t *mp; 1201 const char *lts, *rts; 1202 1203 if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR) 1204 lst = (lstp = ltp->t_subt)->t_tspec; 1205 if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR) 1206 rst = (rstp = rtp->t_subt)->t_tspec; 1207 mp = &modtab[op]; --- 118 unchanged lines hidden (view full) --- 1326 return (0); 1327} 1328 1329/* 1330 * Prints a warning if an operator, which should be senseless for an 1331 * enum type, is applied to an enum type. 1332 */ 1333static void | 1204 mod_t *mp; 1205 const char *lts, *rts; 1206 1207 if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR) 1208 lst = (lstp = ltp->t_subt)->t_tspec; 1209 if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR) 1210 rst = (rstp = rtp->t_subt)->t_tspec; 1211 mp = &modtab[op]; --- 118 unchanged lines hidden (view full) --- 1330 return (0); 1331} 1332 1333/* 1334 * Prints a warning if an operator, which should be senseless for an 1335 * enum type, is applied to an enum type. 1336 */ 1337static void |
1334chkbeop(op, ln, rn) 1335 op_t op; 1336 tnode_t *ln, *rn; | 1338chkbeop(op_t op, tnode_t *ln, tnode_t *rn) |
1337{ 1338 mod_t *mp; 1339 1340 if (!eflag) 1341 return; 1342 1343 mp = &modtab[op]; 1344 --- 16 unchanged lines hidden (view full) --- 1361 warning(241, mp->m_name); 1362 1363} 1364 1365/* 1366 * Prints a warning if an operator is applied to two different enum types. 1367 */ 1368static void | 1339{ 1340 mod_t *mp; 1341 1342 if (!eflag) 1343 return; 1344 1345 mp = &modtab[op]; 1346 --- 16 unchanged lines hidden (view full) --- 1363 warning(241, mp->m_name); 1364 1365} 1366 1367/* 1368 * Prints a warning if an operator is applied to two different enum types. 1369 */ 1370static void |
1369chkeop2(op, arg, ln, rn) 1370 op_t op; 1371 int arg; 1372 tnode_t *ln, *rn; | 1371chkeop2(op_t op, int arg, tnode_t *ln, tnode_t *rn) |
1373{ 1374 mod_t *mp; 1375 1376 mp = &modtab[op]; 1377 1378 if (ln->tn_type->t_enum != rn->tn_type->t_enum) { 1379 switch (op) { 1380 case INIT: --- 22 unchanged lines hidden (view full) --- 1403 } 1404} 1405 1406/* 1407 * Prints a warning if an operator has both enum end other integer 1408 * types. 1409 */ 1410static void | 1372{ 1373 mod_t *mp; 1374 1375 mp = &modtab[op]; 1376 1377 if (ln->tn_type->t_enum != rn->tn_type->t_enum) { 1378 switch (op) { 1379 case INIT: --- 22 unchanged lines hidden (view full) --- 1402 } 1403} 1404 1405/* 1406 * Prints a warning if an operator has both enum end other integer 1407 * types. 1408 */ 1409static void |
1411chkeop1(op, arg, ln, rn) 1412 op_t op; 1413 int arg; 1414 tnode_t *ln, *rn; | 1410chkeop1(op_t op, int arg, tnode_t *ln, tnode_t *rn) |
1415{ | 1411{ |
1412 |
|
1416 if (!eflag) 1417 return; 1418 1419 switch (op) { 1420 case INIT: 1421 /* 1422 * Initializations with 0 should be allowed. Otherwise, 1423 * we should complain about all uninitialized enums, --- 21 unchanged lines hidden (view full) --- 1445 break; 1446 } 1447} 1448 1449/* 1450 * Build and initialize a new node. 1451 */ 1452static tnode_t * | 1413 if (!eflag) 1414 return; 1415 1416 switch (op) { 1417 case INIT: 1418 /* 1419 * Initializations with 0 should be allowed. Otherwise, 1420 * we should complain about all uninitialized enums, --- 21 unchanged lines hidden (view full) --- 1442 break; 1443 } 1444} 1445 1446/* 1447 * Build and initialize a new node. 1448 */ 1449static tnode_t * |
1453mktnode(op, type, ln, rn) 1454 op_t op; 1455 type_t *type; 1456 tnode_t *ln, *rn; | 1450mktnode(op_t op, type_t *type, tnode_t *ln, tnode_t *rn) |
1457{ 1458 tnode_t *ntn; 1459 tspec_t t; 1460 1461 ntn = getnode(); 1462 1463 ntn->tn_op = op; 1464 ntn->tn_type = type; --- 16 unchanged lines hidden (view full) --- 1481/* 1482 * Performs usual conversion of operands to (unsigned) int. 1483 * 1484 * If tflag is set or the operand is a function argument with no 1485 * type information (no prototype or variable # of args), convert 1486 * float to double. 1487 */ 1488tnode_t * | 1451{ 1452 tnode_t *ntn; 1453 tspec_t t; 1454 1455 ntn = getnode(); 1456 1457 ntn->tn_op = op; 1458 ntn->tn_type = type; --- 16 unchanged lines hidden (view full) --- 1475/* 1476 * Performs usual conversion of operands to (unsigned) int. 1477 * 1478 * If tflag is set or the operand is a function argument with no 1479 * type information (no prototype or variable # of args), convert 1480 * float to double. 1481 */ 1482tnode_t * |
1489promote(op, farg, tn) 1490 op_t op; 1491 int farg; 1492 tnode_t *tn; | 1483promote(op_t op, int farg, tnode_t *tn) |
1493{ 1494 tspec_t t; 1495 type_t *ntp; 1496 int len; 1497 1498 t = tn->tn_type->t_tspec; 1499 1500 if (!isatyp(t)) --- 58 unchanged lines hidden (view full) --- 1559 return (tn); 1560} 1561 1562/* 1563 * Insert conversions which are necessary to give both operands the same 1564 * type. This is done in different ways for traditional C and ANIS C. 1565 */ 1566static void | 1484{ 1485 tspec_t t; 1486 type_t *ntp; 1487 int len; 1488 1489 t = tn->tn_type->t_tspec; 1490 1491 if (!isatyp(t)) --- 58 unchanged lines hidden (view full) --- 1550 return (tn); 1551} 1552 1553/* 1554 * Insert conversions which are necessary to give both operands the same 1555 * type. This is done in different ways for traditional C and ANIS C. 1556 */ 1557static void |
1567balance(op, lnp, rnp) 1568 op_t op; 1569 tnode_t **lnp, **rnp; | 1558balance(op_t op, tnode_t **lnp, tnode_t **rnp) |
1570{ 1571 tspec_t lt, rt, t; 1572 int i, u; 1573 type_t *ntp; 1574 static tspec_t tl[] = { 1575 LDOUBLE, DOUBLE, FLOAT, UQUAD, QUAD, ULONG, LONG, UINT, INT, 1576 }; 1577 --- 58 unchanged lines hidden (view full) --- 1636} 1637 1638/* 1639 * Insert a conversion operator, which converts the type of the node 1640 * to another given type. 1641 * If op is FARG, arg is the number of the argument (used for warnings). 1642 */ 1643tnode_t * | 1559{ 1560 tspec_t lt, rt, t; 1561 int i, u; 1562 type_t *ntp; 1563 static tspec_t tl[] = { 1564 LDOUBLE, DOUBLE, FLOAT, UQUAD, QUAD, ULONG, LONG, UINT, INT, 1565 }; 1566 --- 58 unchanged lines hidden (view full) --- 1625} 1626 1627/* 1628 * Insert a conversion operator, which converts the type of the node 1629 * to another given type. 1630 * If op is FARG, arg is the number of the argument (used for warnings). 1631 */ 1632tnode_t * |
1644convert(op, arg, tp, tn) 1645 op_t op; 1646 int arg; 1647 type_t *tp; 1648 tnode_t *tn; | 1633convert(op_t op, int arg, type_t *tp, tnode_t *tn) |
1649{ 1650 tnode_t *ntn; | 1634{ 1635 tnode_t *ntn; |
1651 tspec_t nt, ot, ost; | 1636 tspec_t nt, ot, ost = NOTSPEC; |
1652 1653 if (tn->tn_lvalue) 1654 lerror("convert() 1"); 1655 1656 nt = tp->t_tspec; 1657 if ((ot = tn->tn_type->t_tspec) == PTR) 1658 ost = tn->tn_type->t_subt->t_tspec; 1659 --- 29 unchanged lines hidden (view full) --- 1689 * Print a warning if a prototype causes a type conversion that is 1690 * different from what would happen to the same argument in the 1691 * absence of a prototype. 1692 * 1693 * Errors/Warnings about illegal type combinations are already printed 1694 * in asgntypok(). 1695 */ 1696static void | 1637 1638 if (tn->tn_lvalue) 1639 lerror("convert() 1"); 1640 1641 nt = tp->t_tspec; 1642 if ((ot = tn->tn_type->t_tspec) == PTR) 1643 ost = tn->tn_type->t_subt->t_tspec; 1644 --- 29 unchanged lines hidden (view full) --- 1674 * Print a warning if a prototype causes a type conversion that is 1675 * different from what would happen to the same argument in the 1676 * absence of a prototype. 1677 * 1678 * Errors/Warnings about illegal type combinations are already printed 1679 * in asgntypok(). 1680 */ 1681static void |
1697ptconv(arg, nt, ot, tp, tn) 1698 int arg; 1699 tspec_t nt, ot; 1700 type_t *tp; 1701 tnode_t *tn; | 1682ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) |
1702{ 1703 tnode_t *ptn; 1704 1705 if (!isatyp(nt) || !isatyp(ot)) 1706 return; 1707 1708 /* 1709 * If the type of the formal parameter is char/short, a warning --- 35 unchanged lines hidden (view full) --- 1745} 1746 1747/* 1748 * Print warnings for conversions of integer types which my cause 1749 * problems. 1750 */ 1751/* ARGSUSED */ 1752static void | 1683{ 1684 tnode_t *ptn; 1685 1686 if (!isatyp(nt) || !isatyp(ot)) 1687 return; 1688 1689 /* 1690 * If the type of the formal parameter is char/short, a warning --- 35 unchanged lines hidden (view full) --- 1726} 1727 1728/* 1729 * Print warnings for conversions of integer types which my cause 1730 * problems. 1731 */ 1732/* ARGSUSED */ 1733static void |
1753iiconv(op, arg, nt, ot, tp, tn) 1754 op_t op; 1755 int arg; 1756 tspec_t nt, ot; 1757 type_t *tp; 1758 tnode_t *tn; | 1734iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) |
1759{ 1760 if (tn->tn_op == CON) 1761 return; 1762 1763 if (op == CVT) 1764 return; 1765 1766#if 0 --- 14 unchanged lines hidden (view full) --- 1781 aflag > 1)) { 1782 /* conversion from '%s' may lose accuracy */ 1783 if (aflag) { 1784 if (op == FARG) { 1785 warning(298, tyname(tn->tn_type), arg); 1786 } else { 1787 warning(132, tyname(tn->tn_type)); 1788 } | 1735{ 1736 if (tn->tn_op == CON) 1737 return; 1738 1739 if (op == CVT) 1740 return; 1741 1742#if 0 --- 14 unchanged lines hidden (view full) --- 1757 aflag > 1)) { 1758 /* conversion from '%s' may lose accuracy */ 1759 if (aflag) { 1760 if (op == FARG) { 1761 warning(298, tyname(tn->tn_type), arg); 1762 } else { 1763 warning(132, tyname(tn->tn_type)); 1764 } |
1789 } | 1765 } |
1790 } 1791} 1792 1793/* 1794 * Print warnings for dubious conversions of pointer to integer. 1795 */ 1796static void | 1766 } 1767} 1768 1769/* 1770 * Print warnings for dubious conversions of pointer to integer. 1771 */ 1772static void |
1797piconv(op, nt, tp, tn) 1798 op_t op; 1799 tspec_t nt; 1800 type_t *tp; 1801 tnode_t *tn; | 1773piconv(op_t op, tspec_t nt, type_t *tp, tnode_t *tn) |
1802{ | 1774{ |
1775 |
|
1803 if (tn->tn_op == CON) 1804 return; 1805 1806 if (op != CVT) { 1807 /* We got already an error. */ 1808 return; 1809 } 1810 --- 7 unchanged lines hidden (view full) --- 1818 } 1819 } 1820} 1821 1822/* 1823 * Print warnings for questionable pointer conversions. 1824 */ 1825static void | 1776 if (tn->tn_op == CON) 1777 return; 1778 1779 if (op != CVT) { 1780 /* We got already an error. */ 1781 return; 1782 } 1783 --- 7 unchanged lines hidden (view full) --- 1791 } 1792 } 1793} 1794 1795/* 1796 * Print warnings for questionable pointer conversions. 1797 */ 1798static void |
1826ppconv(op, tn, tp) 1827 op_t op; 1828 tnode_t *tn; 1829 type_t *tp; | 1799ppconv(op_t op, tnode_t *tn, type_t *tp) |
1830{ 1831 tspec_t nt, ot; 1832 const char *nts, *ots; 1833 1834 /* 1835 * We got already an error (pointers of different types 1836 * without a cast) or we will not get a warning. 1837 */ --- 14 unchanged lines hidden (view full) --- 1852 return; 1853 } else if (nt == FUNC && ot == FUNC) { 1854 return; 1855 } else if (nt == FUNC || ot == FUNC) { 1856 /* questionable conversion of function pointer */ 1857 warning(229); 1858 return; 1859 } | 1800{ 1801 tspec_t nt, ot; 1802 const char *nts, *ots; 1803 1804 /* 1805 * We got already an error (pointers of different types 1806 * without a cast) or we will not get a warning. 1807 */ --- 14 unchanged lines hidden (view full) --- 1822 return; 1823 } else if (nt == FUNC && ot == FUNC) { 1824 return; 1825 } else if (nt == FUNC || ot == FUNC) { 1826 /* questionable conversion of function pointer */ 1827 warning(229); 1828 return; 1829 } |
1860 | 1830 |
1861 if (getbound(tp->t_subt) > getbound(tn->tn_type->t_subt)) { 1862 if (hflag) 1863 /* possible pointer alignment problem */ 1864 warning(135); 1865 } 1866 if (((nt == STRUCT || nt == UNION) && 1867 tp->t_subt->t_str != tn->tn_type->t_subt->t_str) || 1868 psize(nt) != psize(ot)) { --- 9 unchanged lines hidden (view full) --- 1878 * 1879 * op operator which requires conversion 1880 * arg if op is FARG, # of argument 1881 * tp type in which to convert the constant 1882 * nv new constant 1883 * v old constant 1884 */ 1885void | 1831 if (getbound(tp->t_subt) > getbound(tn->tn_type->t_subt)) { 1832 if (hflag) 1833 /* possible pointer alignment problem */ 1834 warning(135); 1835 } 1836 if (((nt == STRUCT || nt == UNION) && 1837 tp->t_subt->t_str != tn->tn_type->t_subt->t_str) || 1838 psize(nt) != psize(ot)) { --- 9 unchanged lines hidden (view full) --- 1848 * 1849 * op operator which requires conversion 1850 * arg if op is FARG, # of argument 1851 * tp type in which to convert the constant 1852 * nv new constant 1853 * v old constant 1854 */ 1855void |
1886cvtcon(op, arg, tp, nv, v) 1887 op_t op; 1888 int arg; 1889 type_t *tp; 1890 val_t *nv, *v; | 1856cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v) |
1891{ 1892 tspec_t ot, nt; | 1857{ 1858 tspec_t ot, nt; |
1893 ldbl_t max, min; | 1859 ldbl_t max = 0.0, min = 0.0; |
1894 int sz, rchk; | 1860 int sz, rchk; |
1895 quad_t xmask, xmsk1; | 1861 int64_t xmask, xmsk1; |
1896 int osz, nsz; 1897 1898 ot = v->v_tspec; 1899 nt = nv->v_tspec = tp->t_tspec; 1900 rchk = 0; 1901 1902 if (ot == FLOAT || ot == DOUBLE || ot == LDOUBLE) { 1903 switch (nt) { --- 14 unchanged lines hidden (view full) --- 1918 max = (u_int)UINT_MAX; min = 0; break; 1919 case LONG: 1920 max = LONG_MAX; min = LONG_MIN; break; 1921 case ULONG: 1922 max = (u_long)ULONG_MAX; min = 0; break; 1923 case QUAD: 1924 max = QUAD_MAX; min = QUAD_MIN; break; 1925 case UQUAD: | 1862 int osz, nsz; 1863 1864 ot = v->v_tspec; 1865 nt = nv->v_tspec = tp->t_tspec; 1866 rchk = 0; 1867 1868 if (ot == FLOAT || ot == DOUBLE || ot == LDOUBLE) { 1869 switch (nt) { --- 14 unchanged lines hidden (view full) --- 1884 max = (u_int)UINT_MAX; min = 0; break; 1885 case LONG: 1886 max = LONG_MAX; min = LONG_MIN; break; 1887 case ULONG: 1888 max = (u_long)ULONG_MAX; min = 0; break; 1889 case QUAD: 1890 max = QUAD_MAX; min = QUAD_MIN; break; 1891 case UQUAD: |
1926 max = (u_quad_t)UQUAD_MAX; min = 0; break; | 1892 max = (uint64_t)UQUAD_MAX; min = 0; break; |
1927 case FLOAT: 1928 max = FLT_MAX; min = -FLT_MAX; break; 1929 case DOUBLE: 1930 max = DBL_MAX; min = -DBL_MAX; break; 1931 case PTR: 1932 /* Got already an error because of float --> ptr */ 1933 case LDOUBLE: 1934 max = LDBL_MAX; min = -LDBL_MAX; break; --- 16 unchanged lines hidden (view full) --- 1951 if (nt == FLOAT) { 1952 nv->v_ldbl = (float)v->v_ldbl; 1953 } else if (nt == DOUBLE) { 1954 nv->v_ldbl = (double)v->v_ldbl; 1955 } else if (nt == LDOUBLE) { 1956 nv->v_ldbl = v->v_ldbl; 1957 } else { 1958 nv->v_quad = (nt == PTR || isutyp(nt)) ? | 1893 case FLOAT: 1894 max = FLT_MAX; min = -FLT_MAX; break; 1895 case DOUBLE: 1896 max = DBL_MAX; min = -DBL_MAX; break; 1897 case PTR: 1898 /* Got already an error because of float --> ptr */ 1899 case LDOUBLE: 1900 max = LDBL_MAX; min = -LDBL_MAX; break; --- 16 unchanged lines hidden (view full) --- 1917 if (nt == FLOAT) { 1918 nv->v_ldbl = (float)v->v_ldbl; 1919 } else if (nt == DOUBLE) { 1920 nv->v_ldbl = (double)v->v_ldbl; 1921 } else if (nt == LDOUBLE) { 1922 nv->v_ldbl = v->v_ldbl; 1923 } else { 1924 nv->v_quad = (nt == PTR || isutyp(nt)) ? |
1959 (u_quad_t)v->v_ldbl : (quad_t)v->v_ldbl; | 1925 (uint64_t)v->v_ldbl : (int64_t)v->v_ldbl; |
1960 } 1961 } else { 1962 if (nt == FLOAT) { 1963 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? | 1926 } 1927 } else { 1928 if (nt == FLOAT) { 1929 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? |
1964 (float)(u_quad_t)v->v_quad : (float)v->v_quad; | 1930 (float)(uint64_t)v->v_quad : (float)v->v_quad; |
1965 } else if (nt == DOUBLE) { 1966 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? | 1931 } else if (nt == DOUBLE) { 1932 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? |
1967 (double)(u_quad_t)v->v_quad : (double)v->v_quad; | 1933 (double)(uint64_t)v->v_quad : (double)v->v_quad; |
1968 } else if (nt == LDOUBLE) { 1969 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? | 1934 } else if (nt == LDOUBLE) { 1935 nv->v_ldbl = (ot == PTR || isutyp(ot)) ? |
1970 (ldbl_t)(u_quad_t)v->v_quad : (ldbl_t)v->v_quad; | 1936 (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; |
1971 } else { 1972 rchk = 1; /* Check for lost precision. */ 1973 nv->v_quad = v->v_quad; 1974 } 1975 } 1976 1977 if (v->v_ansiu && isftyp(nt)) { 1978 /* ANSI C treats constant as unsigned */ --- 5 unchanged lines hidden (view full) --- 1984 warning(157); 1985 v->v_ansiu = 0; 1986 } 1987 1988 if (nt != FLOAT && nt != DOUBLE && nt != LDOUBLE) { 1989 sz = tp->t_isfield ? tp->t_flen : size(nt); 1990 nv->v_quad = xsign(nv->v_quad, nt, sz); 1991 } | 1937 } else { 1938 rchk = 1; /* Check for lost precision. */ 1939 nv->v_quad = v->v_quad; 1940 } 1941 } 1942 1943 if (v->v_ansiu && isftyp(nt)) { 1944 /* ANSI C treats constant as unsigned */ --- 5 unchanged lines hidden (view full) --- 1950 warning(157); 1951 v->v_ansiu = 0; 1952 } 1953 1954 if (nt != FLOAT && nt != DOUBLE && nt != LDOUBLE) { 1955 sz = tp->t_isfield ? tp->t_flen : size(nt); 1956 nv->v_quad = xsign(nv->v_quad, nt, sz); 1957 } |
1992 | 1958 |
1993 if (rchk && op != CVT) { 1994 osz = size(ot); 1995 nsz = tp->t_isfield ? tp->t_flen : size(nt); 1996 xmask = qlmasks[nsz] ^ qlmasks[osz]; 1997 xmsk1 = qlmasks[nsz] ^ qlmasks[osz - 1]; 1998 /* 1999 * For bitwise operations we are not interested in the 2000 * value, but in the bits itself. --- 110 unchanged lines hidden (view full) --- 2111 } 2112} 2113 2114/* 2115 * Called if incompatible types were detected. 2116 * Prints a appropriate warning. 2117 */ 2118static void | 1959 if (rchk && op != CVT) { 1960 osz = size(ot); 1961 nsz = tp->t_isfield ? tp->t_flen : size(nt); 1962 xmask = qlmasks[nsz] ^ qlmasks[osz]; 1963 xmsk1 = qlmasks[nsz] ^ qlmasks[osz - 1]; 1964 /* 1965 * For bitwise operations we are not interested in the 1966 * value, but in the bits itself. --- 110 unchanged lines hidden (view full) --- 2077 } 2078} 2079 2080/* 2081 * Called if incompatible types were detected. 2082 * Prints a appropriate warning. 2083 */ 2084static void |
2119incompat(op, lt, rt) 2120 op_t op; 2121 tspec_t lt, rt; | 2085incompat(op_t op, tspec_t lt, tspec_t rt) |
2122{ 2123 mod_t *mp; 2124 2125 mp = &modtab[op]; 2126 2127 if (lt == VOID || (mp->m_binary && rt == VOID)) { 2128 /* void type illegal in expression */ 2129 error(109); --- 15 unchanged lines hidden (view full) --- 2145 } 2146} 2147 2148/* 2149 * Called if incompatible pointer types are detected. 2150 * Print an appropriate warning. 2151 */ 2152static void | 2086{ 2087 mod_t *mp; 2088 2089 mp = &modtab[op]; 2090 2091 if (lt == VOID || (mp->m_binary && rt == VOID)) { 2092 /* void type illegal in expression */ 2093 error(109); --- 15 unchanged lines hidden (view full) --- 2109 } 2110} 2111 2112/* 2113 * Called if incompatible pointer types are detected. 2114 * Print an appropriate warning. 2115 */ 2116static void |
2153illptrc(mp, ltp, rtp) 2154 mod_t *mp; 2155 type_t *ltp, *rtp; | 2117illptrc(mod_t *mp, type_t *ltp, type_t *rtp) |
2156{ 2157 tspec_t lt, rt; 2158 2159 if (ltp->t_tspec != PTR || rtp->t_tspec != PTR) 2160 lerror("illptrc() 1"); 2161 2162 lt = ltp->t_subt->t_tspec; 2163 rt = rtp->t_subt->t_tspec; --- 17 unchanged lines hidden (view full) --- 2181 } 2182} 2183 2184/* 2185 * Make sure type (*tpp)->t_subt has at least the qualifiers 2186 * of tp1->t_subt and tp2->t_subt. 2187 */ 2188static void | 2118{ 2119 tspec_t lt, rt; 2120 2121 if (ltp->t_tspec != PTR || rtp->t_tspec != PTR) 2122 lerror("illptrc() 1"); 2123 2124 lt = ltp->t_subt->t_tspec; 2125 rt = rtp->t_subt->t_tspec; --- 17 unchanged lines hidden (view full) --- 2143 } 2144} 2145 2146/* 2147 * Make sure type (*tpp)->t_subt has at least the qualifiers 2148 * of tp1->t_subt and tp2->t_subt. 2149 */ 2150static void |
2189mrgqual(tpp, tp1, tp2) 2190 type_t **tpp, *tp1, *tp2; | 2151mrgqual(type_t **tpp, type_t *tp1, type_t *tp2) |
2191{ | 2152{ |
2153 |
|
2192 if ((*tpp)->t_tspec != PTR || 2193 tp1->t_tspec != PTR || tp2->t_tspec != PTR) { 2194 lerror("mrgqual()"); 2195 } 2196 2197 if ((*tpp)->t_subt->t_const == 2198 (tp1->t_subt->t_const | tp2->t_subt->t_const) && 2199 (*tpp)->t_subt->t_volatile == --- 9 unchanged lines hidden (view full) --- 2209 tp1->t_subt->t_volatile | tp2->t_subt->t_volatile; 2210} 2211 2212/* 2213 * Returns 1 if the given structure or union has a constant member 2214 * (maybe recursively). 2215 */ 2216static int | 2154 if ((*tpp)->t_tspec != PTR || 2155 tp1->t_tspec != PTR || tp2->t_tspec != PTR) { 2156 lerror("mrgqual()"); 2157 } 2158 2159 if ((*tpp)->t_subt->t_const == 2160 (tp1->t_subt->t_const | tp2->t_subt->t_const) && 2161 (*tpp)->t_subt->t_volatile == --- 9 unchanged lines hidden (view full) --- 2171 tp1->t_subt->t_volatile | tp2->t_subt->t_volatile; 2172} 2173 2174/* 2175 * Returns 1 if the given structure or union has a constant member 2176 * (maybe recursively). 2177 */ 2178static int |
2217conmemb(tp) 2218 type_t *tp; | 2179conmemb(type_t *tp) |
2219{ 2220 sym_t *m; 2221 tspec_t t; 2222 2223 if ((t = tp->t_tspec) != STRUCT && t != UNION) 2224 lerror("conmemb()"); 2225 for (m = tp->t_str->memb; m != NULL; m = m->s_nxt) { 2226 tp = m->s_type; 2227 if (tp->t_const) 2228 return (1); 2229 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 2230 if (conmemb(m->s_type)) 2231 return (1); 2232 } 2233 } 2234 return (0); 2235} 2236 2237const char * | 2180{ 2181 sym_t *m; 2182 tspec_t t; 2183 2184 if ((t = tp->t_tspec) != STRUCT && t != UNION) 2185 lerror("conmemb()"); 2186 for (m = tp->t_str->memb; m != NULL; m = m->s_nxt) { 2187 tp = m->s_type; 2188 if (tp->t_const) 2189 return (1); 2190 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 2191 if (conmemb(m->s_type)) 2192 return (1); 2193 } 2194 } 2195 return (0); 2196} 2197 2198const char * |
2238tyname(tp) 2239 type_t *tp; | 2199tyname(type_t *tp) |
2240{ 2241 tspec_t t; 2242 const char *s; 2243 2244 if ((t = tp->t_tspec) == INT && tp->t_isenum) 2245 t = ENUM; 2246 2247 switch (t) { --- 22 unchanged lines hidden (view full) --- 2270 } 2271 return (s); 2272} 2273 2274/* 2275 * Create a new node for one of the operators POINT and ARROW. 2276 */ 2277static tnode_t * | 2200{ 2201 tspec_t t; 2202 const char *s; 2203 2204 if ((t = tp->t_tspec) == INT && tp->t_isenum) 2205 t = ENUM; 2206 2207 switch (t) { --- 22 unchanged lines hidden (view full) --- 2230 } 2231 return (s); 2232} 2233 2234/* 2235 * Create a new node for one of the operators POINT and ARROW. 2236 */ 2237static tnode_t * |
2278bldstr(op, ln, rn) 2279 op_t op; 2280 tnode_t *ln, *rn; | 2238bldstr(op_t op, tnode_t *ln, tnode_t *rn) |
2281{ 2282 tnode_t *ntn, *ctn; 2283 int nolval; 2284 2285 if (rn->tn_op != NAME) 2286 lerror("bldstr() 1"); 2287 if (rn->tn_sym->s_value.v_tspec != INT) 2288 lerror("bldstr() 2"); --- 35 unchanged lines hidden (view full) --- 2324 2325 return (ntn); 2326} 2327 2328/* 2329 * Create a node for INCAFT, INCBEF, DECAFT and DECBEF. 2330 */ 2331static tnode_t * | 2239{ 2240 tnode_t *ntn, *ctn; 2241 int nolval; 2242 2243 if (rn->tn_op != NAME) 2244 lerror("bldstr() 1"); 2245 if (rn->tn_sym->s_value.v_tspec != INT) 2246 lerror("bldstr() 2"); --- 35 unchanged lines hidden (view full) --- 2282 2283 return (ntn); 2284} 2285 2286/* 2287 * Create a node for INCAFT, INCBEF, DECAFT and DECBEF. 2288 */ 2289static tnode_t * |
2332bldincdec(op, ln) 2333 op_t op; 2334 tnode_t *ln; | 2290bldincdec(op_t op, tnode_t *ln) |
2335{ 2336 tnode_t *cn, *ntn; 2337 2338 if (ln == NULL) 2339 lerror("bldincdec() 1"); 2340 2341 if (ln->tn_type->t_tspec == PTR) { 2342 cn = plength(ln->tn_type); 2343 } else { | 2291{ 2292 tnode_t *cn, *ntn; 2293 2294 if (ln == NULL) 2295 lerror("bldincdec() 1"); 2296 2297 if (ln->tn_type->t_tspec == PTR) { 2298 cn = plength(ln->tn_type); 2299 } else { |
2344 cn = getinode(INT, (quad_t)1); | 2300 cn = getinode(INT, (int64_t)1); |
2345 } 2346 ntn = mktnode(op, ln->tn_type, ln, cn); 2347 2348 return (ntn); 2349} 2350 2351/* 2352 * Create a tree node for the & operator 2353 */ 2354static tnode_t * | 2301 } 2302 ntn = mktnode(op, ln->tn_type, ln, cn); 2303 2304 return (ntn); 2305} 2306 2307/* 2308 * Create a tree node for the & operator 2309 */ 2310static tnode_t * |
2355bldamper(tn, noign) 2356 tnode_t *tn; 2357 int noign; | 2311bldamper(tnode_t *tn, int noign) |
2358{ 2359 tnode_t *ntn; 2360 tspec_t t; | 2312{ 2313 tnode_t *ntn; 2314 tspec_t t; |
2361 | 2315 |
2362 if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { 2363 /* & before array or function: ignored */ 2364 if (tflag) 2365 warning(127); 2366 return (tn); 2367 } 2368 2369 /* eliminate &* */ 2370 if (tn->tn_op == STAR && 2371 tn->tn_left->tn_type->t_tspec == PTR && 2372 tn->tn_left->tn_type->t_subt == tn->tn_type) { 2373 return (tn->tn_left); 2374 } | 2316 if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { 2317 /* & before array or function: ignored */ 2318 if (tflag) 2319 warning(127); 2320 return (tn); 2321 } 2322 2323 /* eliminate &* */ 2324 if (tn->tn_op == STAR && 2325 tn->tn_left->tn_type->t_tspec == PTR && 2326 tn->tn_left->tn_type->t_subt == tn->tn_type) { 2327 return (tn->tn_left); 2328 } |
2375 | 2329 |
2376 ntn = mktnode(AMPER, tincref(tn->tn_type, PTR), tn, NULL); 2377 2378 return (ntn); 2379} 2380 2381/* 2382 * Create a node for operators PLUS and MINUS. 2383 */ 2384static tnode_t * | 2330 ntn = mktnode(AMPER, tincref(tn->tn_type, PTR), tn, NULL); 2331 2332 return (ntn); 2333} 2334 2335/* 2336 * Create a node for operators PLUS and MINUS. 2337 */ 2338static tnode_t * |
2385bldplmi(op, ln, rn) 2386 op_t op; 2387 tnode_t *ln, *rn; | 2339bldplmi(op_t op, tnode_t *ln, tnode_t *rn) |
2388{ 2389 tnode_t *ntn, *ctn; 2390 type_t *tp; 2391 2392 /* If pointer and integer, then pointer to the lhs. */ 2393 if (rn->tn_type->t_tspec == PTR && isityp(ln->tn_type->t_tspec)) { 2394 ntn = ln; 2395 ln = rn; --- 36 unchanged lines hidden (view full) --- 2432 } 2433 return (ntn); 2434} 2435 2436/* 2437 * Create a node for operators SHL and SHR. 2438 */ 2439static tnode_t * | 2340{ 2341 tnode_t *ntn, *ctn; 2342 type_t *tp; 2343 2344 /* If pointer and integer, then pointer to the lhs. */ 2345 if (rn->tn_type->t_tspec == PTR && isityp(ln->tn_type->t_tspec)) { 2346 ntn = ln; 2347 ln = rn; --- 36 unchanged lines hidden (view full) --- 2384 } 2385 return (ntn); 2386} 2387 2388/* 2389 * Create a node for operators SHL and SHR. 2390 */ 2391static tnode_t * |
2440bldshft(op, ln, rn) 2441 op_t op; 2442 tnode_t *ln, *rn; | 2392bldshft(op_t op, tnode_t *ln, tnode_t *rn) |
2443{ 2444 tspec_t t; 2445 tnode_t *ntn; 2446 2447 if ((t = rn->tn_type->t_tspec) != INT && t != UINT) 2448 rn = convert(CVT, 0, gettyp(INT), rn); 2449 ntn = mktnode(op, ln->tn_type, ln, rn); 2450 return (ntn); 2451} 2452 2453/* 2454 * Create a node for COLON. 2455 */ 2456static tnode_t * | 2393{ 2394 tspec_t t; 2395 tnode_t *ntn; 2396 2397 if ((t = rn->tn_type->t_tspec) != INT && t != UINT) 2398 rn = convert(CVT, 0, gettyp(INT), rn); 2399 ntn = mktnode(op, ln->tn_type, ln, rn); 2400 return (ntn); 2401} 2402 2403/* 2404 * Create a node for COLON. 2405 */ 2406static tnode_t * |
2457bldcol(ln, rn) 2458 tnode_t *ln, *rn; | 2407bldcol(tnode_t *ln, tnode_t *rn) |
2459{ 2460 tspec_t lt, rt, pdt; 2461 type_t *rtp; 2462 tnode_t *ntn; 2463 2464 lt = ln->tn_type->t_tspec; 2465 rt = rn->tn_type->t_tspec; 2466#if PTRDIFF_IS_LONG --- 61 unchanged lines hidden (view full) --- 2528 2529 return (ntn); 2530} 2531 2532/* 2533 * Create a node for an assignment operator (both = and op= ). 2534 */ 2535static tnode_t * | 2408{ 2409 tspec_t lt, rt, pdt; 2410 type_t *rtp; 2411 tnode_t *ntn; 2412 2413 lt = ln->tn_type->t_tspec; 2414 rt = rn->tn_type->t_tspec; 2415#if PTRDIFF_IS_LONG --- 61 unchanged lines hidden (view full) --- 2477 2478 return (ntn); 2479} 2480 2481/* 2482 * Create a node for an assignment operator (both = and op= ). 2483 */ 2484static tnode_t * |
2536bldasgn(op, ln, rn) 2537 op_t op; 2538 tnode_t *ln, *rn; | 2485bldasgn(op_t op, tnode_t *ln, tnode_t *rn) |
2539{ 2540 tspec_t lt, rt; 2541 tnode_t *ntn, *ctn; 2542 2543 if (ln == NULL || rn == NULL) 2544 lerror("bldasgn() 1"); 2545 2546 lt = ln->tn_type->t_tspec; --- 44 unchanged lines hidden (view full) --- 2591 2592 return (ntn); 2593} 2594 2595/* 2596 * Get length of type tp->t_subt. 2597 */ 2598static tnode_t * | 2486{ 2487 tspec_t lt, rt; 2488 tnode_t *ntn, *ctn; 2489 2490 if (ln == NULL || rn == NULL) 2491 lerror("bldasgn() 1"); 2492 2493 lt = ln->tn_type->t_tspec; --- 44 unchanged lines hidden (view full) --- 2538 2539 return (ntn); 2540} 2541 2542/* 2543 * Get length of type tp->t_subt. 2544 */ 2545static tnode_t * |
2599plength(tp) 2600 type_t *tp; | 2546plength(type_t *tp) |
2601{ 2602 int elem, elsz; 2603 tspec_t st; 2604 2605 if (tp->t_tspec != PTR) 2606 lerror("plength() 1"); 2607 tp = tp->t_subt; 2608 --- 45 unchanged lines hidden (view full) --- 2654 elsz = CHAR_BIT; 2655 2656#if PTRDIFF_IS_LONG 2657 st = LONG; 2658#else 2659 st = INT; 2660#endif 2661 | 2547{ 2548 int elem, elsz; 2549 tspec_t st; 2550 2551 if (tp->t_tspec != PTR) 2552 lerror("plength() 1"); 2553 tp = tp->t_subt; 2554 --- 45 unchanged lines hidden (view full) --- 2600 elsz = CHAR_BIT; 2601 2602#if PTRDIFF_IS_LONG 2603 st = LONG; 2604#else 2605 st = INT; 2606#endif 2607 |
2662 return (getinode(st, (quad_t)(elem * elsz / CHAR_BIT))); | 2608 return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT))); |
2663} 2664 | 2609} 2610 |
2665#ifdef XXX_BROKEN_GCC 2666static int 2667quad_t_eq(x, y) 2668 quad_t x, y; 2669{ 2670 return (x == y); 2671} 2672 2673static int 2674u_quad_t_eq(x, y) 2675 u_quad_t x, y; 2676{ 2677 return (x == y); 2678} 2679#endif 2680 | |
2681/* | 2611/* |
2612 * XXX 2613 * Note: There appear to be a number of bugs in detecting overflow in 2614 * this function. An audit and a set of proper regression tests are needed. 2615 * --Perry Metzger, Nov. 16, 2001 2616 */ 2617/* |
|
2682 * Do only as much as necessary to compute constant expressions. 2683 * Called only if the operator allows folding and (both) operands 2684 * are constants. 2685 */ 2686static tnode_t * | 2618 * Do only as much as necessary to compute constant expressions. 2619 * Called only if the operator allows folding and (both) operands 2620 * are constants. 2621 */ 2622static tnode_t * |
2687fold(tn) 2688 tnode_t *tn; | 2623fold(tnode_t *tn) |
2689{ 2690 val_t *v; 2691 tspec_t t; 2692 int utyp, ovfl; | 2624{ 2625 val_t *v; 2626 tspec_t t; 2627 int utyp, ovfl; |
2693 quad_t sl, sr, q, mask; 2694 u_quad_t ul, ur; | 2628 int64_t sl, sr = 0, q = 0, mask; 2629 uint64_t ul, ur = 0; |
2695 tnode_t *cn; 2696 2697 if ((v = calloc(1, sizeof (val_t))) == NULL) 2698 nomem(); 2699 v->v_tspec = t = tn->tn_type->t_tspec; 2700 2701 utyp = t == PTR || isutyp(t); 2702 ul = sl = tn->tn_left->tn_val->v_quad; 2703 if (modtab[tn->tn_op].m_binary) 2704 ur = sr = tn->tn_right->tn_val->v_quad; 2705 | 2630 tnode_t *cn; 2631 2632 if ((v = calloc(1, sizeof (val_t))) == NULL) 2633 nomem(); 2634 v->v_tspec = t = tn->tn_type->t_tspec; 2635 2636 utyp = t == PTR || isutyp(t); 2637 ul = sl = tn->tn_left->tn_val->v_quad; 2638 if (modtab[tn->tn_op].m_binary) 2639 ur = sr = tn->tn_right->tn_val->v_quad; 2640 |
2641 mask = qlmasks[size(t)]; |
|
2706 ovfl = 0; 2707 2708 switch (tn->tn_op) { 2709 case UPLUS: 2710 q = sl; 2711 break; 2712 case UMINUS: 2713 q = -sl; 2714 if (msb(q, t, -1) == msb(sl, t, -1)) 2715 ovfl = 1; 2716 break; 2717 case COMPL: 2718 q = ~sl; 2719 break; 2720 case MULT: | 2642 ovfl = 0; 2643 2644 switch (tn->tn_op) { 2645 case UPLUS: 2646 q = sl; 2647 break; 2648 case UMINUS: 2649 q = -sl; 2650 if (msb(q, t, -1) == msb(sl, t, -1)) 2651 ovfl = 1; 2652 break; 2653 case COMPL: 2654 q = ~sl; 2655 break; 2656 case MULT: |
2721 q = utyp ? ul * ur : sl * sr; 2722 if (msb(q, t, -1) != (msb(sl, t, -1) ^ msb(sr, t, -1))) 2723 ovfl = 1; | 2657 if (utyp) { 2658 q = ul * ur; 2659 if (q != (q & mask)) 2660 ovfl = 1; 2661 else if ((ul != 0) && ((q / ul) != ur)) 2662 ovfl = 1; 2663 } else { 2664 q = sl * sr; 2665 if (msb(q, t, -1) != (msb(sl, t, -1) ^ msb(sr, t, -1))) 2666 ovfl = 1; 2667 } |
2724 break; 2725 case DIV: 2726 if (sr == 0) { 2727 /* division by 0 */ 2728 error(139); 2729 q = utyp ? UQUAD_MAX : QUAD_MAX; 2730 } else { 2731 q = utyp ? ul / ur : sl / sr; --- 28 unchanged lines hidden (view full) --- 2760 ovfl = 1; 2761 } 2762 break; 2763 case SHL: 2764 q = utyp ? ul << sr : sl << sr; 2765 break; 2766 case SHR: 2767 /* | 2668 break; 2669 case DIV: 2670 if (sr == 0) { 2671 /* division by 0 */ 2672 error(139); 2673 q = utyp ? UQUAD_MAX : QUAD_MAX; 2674 } else { 2675 q = utyp ? ul / ur : sl / sr; --- 28 unchanged lines hidden (view full) --- 2704 ovfl = 1; 2705 } 2706 break; 2707 case SHL: 2708 q = utyp ? ul << sr : sl << sr; 2709 break; 2710 case SHR: 2711 /* |
2768 * The sign must be explizitly extended because | 2712 * The sign must be explicitly extended because |
2769 * shifts of signed values are implementation dependent. 2770 */ 2771 q = ul >> sr; 2772 q = xsign(q, t, size(t) - (int)sr); 2773 break; 2774 case LT: 2775 q = utyp ? ul < ur : sl < sr; 2776 break; 2777 case LE: 2778 q = utyp ? ul <= ur : sl <= sr; 2779 break; 2780 case GE: 2781 q = utyp ? ul >= ur : sl >= sr; 2782 break; 2783 case GT: 2784 q = utyp ? ul > ur : sl > sr; 2785 break; 2786 case EQ: | 2713 * shifts of signed values are implementation dependent. 2714 */ 2715 q = ul >> sr; 2716 q = xsign(q, t, size(t) - (int)sr); 2717 break; 2718 case LT: 2719 q = utyp ? ul < ur : sl < sr; 2720 break; 2721 case LE: 2722 q = utyp ? ul <= ur : sl <= sr; 2723 break; 2724 case GE: 2725 q = utyp ? ul >= ur : sl >= sr; 2726 break; 2727 case GT: 2728 q = utyp ? ul > ur : sl > sr; 2729 break; 2730 case EQ: |
2787#ifdef XXX_BROKEN_GCC 2788 q = utyp ? u_quad_t_eq(ul, ur) : quad_t_eq(sl, sr); 2789#else | |
2790 q = utyp ? ul == ur : sl == sr; | 2731 q = utyp ? ul == ur : sl == sr; |
2791#endif | |
2792 break; 2793 case NE: 2794 q = utyp ? ul != ur : sl != sr; 2795 break; 2796 case AND: 2797 q = utyp ? ul & ur : sl & sr; 2798 break; 2799 case XOR: 2800 q = utyp ? ul ^ ur : sl ^ sr; 2801 break; 2802 case OR: 2803 q = utyp ? ul | ur : sl | sr; 2804 break; 2805 default: 2806 lerror("fold() 5"); 2807 } 2808 | 2732 break; 2733 case NE: 2734 q = utyp ? ul != ur : sl != sr; 2735 break; 2736 case AND: 2737 q = utyp ? ul & ur : sl & sr; 2738 break; 2739 case XOR: 2740 q = utyp ? ul ^ ur : sl ^ sr; 2741 break; 2742 case OR: 2743 q = utyp ? ul | ur : sl | sr; 2744 break; 2745 default: 2746 lerror("fold() 5"); 2747 } 2748 |
2809 mask = qlmasks[size(t)]; 2810 | |
2811 /* XXX does not work for quads. */ | 2749 /* XXX does not work for quads. */ |
2812 if (ovfl || ((q | mask) != ~(u_quad_t)0 && (q & ~mask) != 0)) { | 2750 if (ovfl || ((q | mask) != ~(uint64_t)0 && (q & ~mask) != 0)) { |
2813 if (hflag) 2814 /* integer overflow detected, op %s */ 2815 warning(141, modtab[tn->tn_op].m_name); 2816 } 2817 2818 v->v_quad = xsign(q, t, -1); 2819 2820 cn = getcnode(tn->tn_type, v); 2821 2822 return (cn); 2823} 2824 | 2751 if (hflag) 2752 /* integer overflow detected, op %s */ 2753 warning(141, modtab[tn->tn_op].m_name); 2754 } 2755 2756 v->v_quad = xsign(q, t, -1); 2757 2758 cn = getcnode(tn->tn_type, v); 2759 2760 return (cn); 2761} 2762 |
2825#ifdef XXX_BROKEN_GCC 2826int 2827ldbl_t_neq(x, y) 2828 ldbl_t x, y; 2829{ 2830 return (x != y); 2831} 2832#endif 2833 | |
2834/* 2835 * Same for operators whose operands are compared with 0 (test context). 2836 */ 2837static tnode_t * | 2763/* 2764 * Same for operators whose operands are compared with 0 (test context). 2765 */ 2766static tnode_t * |
2838foldtst(tn) 2839 tnode_t *tn; | 2767foldtst(tnode_t *tn) |
2840{ | 2768{ |
2841 int l, r; | 2769 int l, r = 0; |
2842 val_t *v; 2843 2844 if ((v = calloc(1, sizeof (val_t))) == NULL) 2845 nomem(); 2846 v->v_tspec = tn->tn_type->t_tspec; 2847 if (tn->tn_type->t_tspec != INT) 2848 lerror("foldtst() 1"); 2849 2850 if (isftyp(tn->tn_left->tn_type->t_tspec)) { | 2770 val_t *v; 2771 2772 if ((v = calloc(1, sizeof (val_t))) == NULL) 2773 nomem(); 2774 v->v_tspec = tn->tn_type->t_tspec; 2775 if (tn->tn_type->t_tspec != INT) 2776 lerror("foldtst() 1"); 2777 2778 if (isftyp(tn->tn_left->tn_type->t_tspec)) { |
2851#ifdef XXX_BROKEN_GCC 2852 l = ldbl_t_neq(tn->tn_left->tn_val->v_ldbl, 0.0); 2853#else | |
2854 l = tn->tn_left->tn_val->v_ldbl != 0.0; | 2779 l = tn->tn_left->tn_val->v_ldbl != 0.0; |
2855#endif | |
2856 } else { 2857 l = tn->tn_left->tn_val->v_quad != 0; 2858 } 2859 2860 if (modtab[tn->tn_op].m_binary) { 2861 if (isftyp(tn->tn_right->tn_type->t_tspec)) { | 2780 } else { 2781 l = tn->tn_left->tn_val->v_quad != 0; 2782 } 2783 2784 if (modtab[tn->tn_op].m_binary) { 2785 if (isftyp(tn->tn_right->tn_type->t_tspec)) { |
2862#ifdef XXX_BROKEN_GCC 2863 r = ldbl_t_neq(tn->tn_right->tn_val->v_ldbl, 0.0); 2864#else | |
2865 r = tn->tn_right->tn_val->v_ldbl != 0.0; | 2786 r = tn->tn_right->tn_val->v_ldbl != 0.0; |
2866#endif | |
2867 } else { 2868 r = tn->tn_right->tn_val->v_quad != 0; 2869 } 2870 } 2871 2872 switch (tn->tn_op) { 2873 case NOT: 2874 if (hflag) --- 13 unchanged lines hidden (view full) --- 2888 2889 return (getcnode(tn->tn_type, v)); 2890} 2891 2892/* 2893 * Same for operands with floating point type. 2894 */ 2895static tnode_t * | 2787 } else { 2788 r = tn->tn_right->tn_val->v_quad != 0; 2789 } 2790 } 2791 2792 switch (tn->tn_op) { 2793 case NOT: 2794 if (hflag) --- 13 unchanged lines hidden (view full) --- 2808 2809 return (getcnode(tn->tn_type, v)); 2810} 2811 2812/* 2813 * Same for operands with floating point type. 2814 */ 2815static tnode_t * |
2896foldflt(tn) 2897 tnode_t *tn; | 2816foldflt(tnode_t *tn) |
2898{ 2899 val_t *v; 2900 tspec_t t; | 2817{ 2818 val_t *v; 2819 tspec_t t; |
2901 ldbl_t l, r; | 2820 ldbl_t l, r = 0; |
2902 2903 if ((v = calloc(1, sizeof (val_t))) == NULL) 2904 nomem(); 2905 v->v_tspec = t = tn->tn_type->t_tspec; 2906 2907 if (!isftyp(t)) 2908 lerror("foldflt() 1"); 2909 --- 56 unchanged lines hidden (view full) --- 2966 v->v_quad = l != r; 2967 break; 2968 default: 2969 lerror("foldflt() 4"); 2970 } 2971 2972 if (isnan((double)v->v_ldbl)) 2973 lerror("foldflt() 5"); | 2821 2822 if ((v = calloc(1, sizeof (val_t))) == NULL) 2823 nomem(); 2824 v->v_tspec = t = tn->tn_type->t_tspec; 2825 2826 if (!isftyp(t)) 2827 lerror("foldflt() 1"); 2828 --- 56 unchanged lines hidden (view full) --- 2885 v->v_quad = l != r; 2886 break; 2887 default: 2888 lerror("foldflt() 4"); 2889 } 2890 2891 if (isnan((double)v->v_ldbl)) 2892 lerror("foldflt() 5"); |
2974 if (isinf((double)v->v_ldbl) || | 2893 if (!finite((double)v->v_ldbl) || |
2975 (t == FLOAT && 2976 (v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) || 2977 (t == DOUBLE && 2978 (v->v_ldbl > DBL_MAX || v->v_ldbl < -DBL_MAX))) { 2979 /* floating point overflow detected, op %s */ 2980 warning(142, modtab[tn->tn_op].m_name); 2981 if (t == FLOAT) { 2982 v->v_ldbl = v->v_ldbl < 0 ? -FLT_MAX : FLT_MAX; --- 6 unchanged lines hidden (view full) --- 2989 2990 return (getcnode(tn->tn_type, v)); 2991} 2992 2993/* 2994 * Create a constant node for sizeof. 2995 */ 2996tnode_t * | 2894 (t == FLOAT && 2895 (v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) || 2896 (t == DOUBLE && 2897 (v->v_ldbl > DBL_MAX || v->v_ldbl < -DBL_MAX))) { 2898 /* floating point overflow detected, op %s */ 2899 warning(142, modtab[tn->tn_op].m_name); 2900 if (t == FLOAT) { 2901 v->v_ldbl = v->v_ldbl < 0 ? -FLT_MAX : FLT_MAX; --- 6 unchanged lines hidden (view full) --- 2908 2909 return (getcnode(tn->tn_type, v)); 2910} 2911 2912/* 2913 * Create a constant node for sizeof. 2914 */ 2915tnode_t * |
2997bldszof(tp) 2998 type_t *tp; | 2916bldszof(type_t *tp) |
2999{ 3000 int elem, elsz; 3001 tspec_t st; 3002 3003 elem = 1; 3004 while (tp->t_tspec == ARRAY) { 3005 elem *= tp->t_dim; 3006 tp = tp->t_subt; --- 43 unchanged lines hidden (view full) --- 3050 } 3051 3052#if SIZEOF_IS_ULONG 3053 st = ULONG; 3054#else 3055 st = UINT; 3056#endif 3057 | 2917{ 2918 int elem, elsz; 2919 tspec_t st; 2920 2921 elem = 1; 2922 while (tp->t_tspec == ARRAY) { 2923 elem *= tp->t_dim; 2924 tp = tp->t_subt; --- 43 unchanged lines hidden (view full) --- 2968 } 2969 2970#if SIZEOF_IS_ULONG 2971 st = ULONG; 2972#else 2973 st = UINT; 2974#endif 2975 |
3058 return (getinode(st, (quad_t)(elem * elsz / CHAR_BIT))); | 2976 return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT))); |
3059} 3060 3061/* 3062 * Type casts. 3063 */ 3064tnode_t * | 2977} 2978 2979/* 2980 * Type casts. 2981 */ 2982tnode_t * |
3065cast(tn, tp) 3066 tnode_t *tn; 3067 type_t *tp; | 2983cast(tnode_t *tn, type_t *tp) |
3068{ 3069 tspec_t nt, ot; 3070 3071 if (tn == NULL) 3072 return (NULL); 3073 3074 tn = cconv(tn); 3075 --- 42 unchanged lines hidden (view full) --- 3118} 3119 3120/* 3121 * Create the node for a function argument. 3122 * All necessary conversions and type checks are done in funccall(), because 3123 * in funcarg() we have no information about expected argument types. 3124 */ 3125tnode_t * | 2984{ 2985 tspec_t nt, ot; 2986 2987 if (tn == NULL) 2988 return (NULL); 2989 2990 tn = cconv(tn); 2991 --- 42 unchanged lines hidden (view full) --- 3034} 3035 3036/* 3037 * Create the node for a function argument. 3038 * All necessary conversions and type checks are done in funccall(), because 3039 * in funcarg() we have no information about expected argument types. 3040 */ 3041tnode_t * |
3126funcarg(args, arg) 3127 tnode_t *args, *arg; | 3042funcarg(tnode_t *args, tnode_t *arg) |
3128{ 3129 tnode_t *ntn; 3130 3131 /* 3132 * If there was a serious error in the expression for the argument, 3133 * create a dummy argument so the positions of the remaining arguments 3134 * will not change. 3135 */ 3136 if (arg == NULL) | 3043{ 3044 tnode_t *ntn; 3045 3046 /* 3047 * If there was a serious error in the expression for the argument, 3048 * create a dummy argument so the positions of the remaining arguments 3049 * will not change. 3050 */ 3051 if (arg == NULL) |
3137 arg = getinode(INT, (quad_t)0); | 3052 arg = getinode(INT, (int64_t)0); |
3138 3139 ntn = mktnode(PUSH, arg->tn_type, arg, args); 3140 3141 return (ntn); 3142} 3143 3144/* 3145 * Create the node for a function call. Also check types of 3146 * function arguments and insert conversions, if necessary. 3147 */ 3148tnode_t * | 3053 3054 ntn = mktnode(PUSH, arg->tn_type, arg, args); 3055 3056 return (ntn); 3057} 3058 3059/* 3060 * Create the node for a function call. Also check types of 3061 * function arguments and insert conversions, if necessary. 3062 */ 3063tnode_t * |
3149funccall(func, args) 3150 tnode_t *func, *args; | 3064funccall(tnode_t *func, tnode_t *args) |
3151{ 3152 tnode_t *ntn; 3153 op_t fcop; 3154 3155 if (func == NULL) 3156 return (NULL); 3157 3158 if (func->tn_op == NAME && func->tn_type->t_tspec == FUNC) { --- 22 unchanged lines hidden (view full) --- 3181 return (ntn); 3182} 3183 3184/* 3185 * Check types of all function arguments and insert conversions, 3186 * if necessary. 3187 */ 3188static tnode_t * | 3065{ 3066 tnode_t *ntn; 3067 op_t fcop; 3068 3069 if (func == NULL) 3070 return (NULL); 3071 3072 if (func->tn_op == NAME && func->tn_type->t_tspec == FUNC) { --- 22 unchanged lines hidden (view full) --- 3095 return (ntn); 3096} 3097 3098/* 3099 * Check types of all function arguments and insert conversions, 3100 * if necessary. 3101 */ 3102static tnode_t * |
3189chkfarg(ftp, args) 3190 type_t *ftp; /* type of called function */ 3191 tnode_t *args; /* arguments */ | 3103chkfarg(type_t *ftp, tnode_t *args) |
3192{ 3193 tnode_t *arg; 3194 sym_t *asym; 3195 tspec_t at; 3196 int narg, npar, n, i; 3197 3198 /* get # of args in the prototype */ 3199 npar = 0; --- 6 unchanged lines hidden (view full) --- 3206 narg++; 3207 3208 asym = ftp->t_args; 3209 if (ftp->t_proto && npar != narg && !(ftp->t_vararg && npar < narg)) { 3210 /* argument mismatch: %d arg%s passed, %d expected */ 3211 error(150, narg, narg > 1 ? "s" : "", npar); 3212 asym = NULL; 3213 } | 3104{ 3105 tnode_t *arg; 3106 sym_t *asym; 3107 tspec_t at; 3108 int narg, npar, n, i; 3109 3110 /* get # of args in the prototype */ 3111 npar = 0; --- 6 unchanged lines hidden (view full) --- 3118 narg++; 3119 3120 asym = ftp->t_args; 3121 if (ftp->t_proto && npar != narg && !(ftp->t_vararg && npar < narg)) { 3122 /* argument mismatch: %d arg%s passed, %d expected */ 3123 error(150, narg, narg > 1 ? "s" : "", npar); 3124 asym = NULL; 3125 } |
3214 | 3126 |
3215 for (n = 1; n <= narg; n++) { 3216 3217 /* 3218 * The rightmost argument is at the top of the argument 3219 * subtree. 3220 */ | 3127 for (n = 1; n <= narg; n++) { 3128 3129 /* 3130 * The rightmost argument is at the top of the argument 3131 * subtree. 3132 */ |
3221 for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ; | 3133 for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) 3134 continue; |
3222 3223 /* some things which are always not allowd */ 3224 if ((at = arg->tn_left->tn_type->t_tspec) == VOID) { 3225 /* void expressions may not be arguments, arg #%d */ 3226 error(151, n); 3227 return (NULL); 3228 } else if ((at == STRUCT || at == UNION) && 3229 incompl(arg->tn_left->tn_type)) { --- 25 unchanged lines hidden (view full) --- 3255 3256/* 3257 * Compare the type of an argument with the corresponding type of a 3258 * prototype parameter. If it is a valid combination, but both types 3259 * are not the same, insert a conversion to convert the argument into 3260 * the type of the parameter. 3261 */ 3262static tnode_t * | 3135 3136 /* some things which are always not allowd */ 3137 if ((at = arg->tn_left->tn_type->t_tspec) == VOID) { 3138 /* void expressions may not be arguments, arg #%d */ 3139 error(151, n); 3140 return (NULL); 3141 } else if ((at == STRUCT || at == UNION) && 3142 incompl(arg->tn_left->tn_type)) { --- 25 unchanged lines hidden (view full) --- 3168 3169/* 3170 * Compare the type of an argument with the corresponding type of a 3171 * prototype parameter. If it is a valid combination, but both types 3172 * are not the same, insert a conversion to convert the argument into 3173 * the type of the parameter. 3174 */ 3175static tnode_t * |
3263parg(n, tp, tn) 3264 int n; /* pos of arg */ 3265 type_t *tp; /* expected type (from prototype) */ 3266 tnode_t *tn; /* argument */ | 3176parg( int n, /* pos of arg */ 3177 type_t *tp, /* expected type (from prototype) */ 3178 tnode_t *tn) /* argument */ |
3267{ 3268 tnode_t *ln; 3269 int warn; 3270 3271 if ((ln = calloc(1, sizeof (tnode_t))) == NULL) 3272 nomem(); 3273 ln->tn_type = tduptyp(tp); 3274 ln->tn_type->t_const = 0; --- 7 unchanged lines hidden (view full) --- 3282} 3283 3284/* 3285 * Return the value of an integral constant expression. 3286 * If the expression is not constant or its type is not an integer 3287 * type, an error message is printed. 3288 */ 3289val_t * | 3179{ 3180 tnode_t *ln; 3181 int warn; 3182 3183 if ((ln = calloc(1, sizeof (tnode_t))) == NULL) 3184 nomem(); 3185 ln->tn_type = tduptyp(tp); 3186 ln->tn_type->t_const = 0; --- 7 unchanged lines hidden (view full) --- 3194} 3195 3196/* 3197 * Return the value of an integral constant expression. 3198 * If the expression is not constant or its type is not an integer 3199 * type, an error message is printed. 3200 */ 3201val_t * |
3290constant(tn) 3291 tnode_t *tn; | 3202constant(tnode_t *tn) |
3292{ 3293 val_t *v; 3294 3295 if (tn != NULL) 3296 tn = cconv(tn); 3297 if (tn != NULL) 3298 tn = promote(NOOP, 0, tn); 3299 --- 36 unchanged lines hidden (view full) --- 3336 * Perform some tests on expressions which can't be done in build() and 3337 * functions called by build(). These tests must be done here because 3338 * we need some information about the context in which the operations 3339 * are performed. 3340 * After all tests are performed, expr() frees the memory which is used 3341 * for the expression. 3342 */ 3343void | 3203{ 3204 val_t *v; 3205 3206 if (tn != NULL) 3207 tn = cconv(tn); 3208 if (tn != NULL) 3209 tn = promote(NOOP, 0, tn); 3210 --- 36 unchanged lines hidden (view full) --- 3247 * Perform some tests on expressions which can't be done in build() and 3248 * functions called by build(). These tests must be done here because 3249 * we need some information about the context in which the operations 3250 * are performed. 3251 * After all tests are performed, expr() frees the memory which is used 3252 * for the expression. 3253 */ 3254void |
3344expr(tn, vctx, tctx) 3345 tnode_t *tn; 3346 int vctx, tctx; | 3255expr(tnode_t *tn, int vctx, int tctx) |
3347{ | 3256{ |
3257 |
|
3348 if (tn == NULL && nerr == 0) 3349 lerror("expr() 1"); 3350 3351 if (tn == NULL) { 3352 tfreeblk(); 3353 return; 3354 } 3355 --- 22 unchanged lines hidden (view full) --- 3378 if (dflag) 3379 displexpr(tn, 0); 3380 3381 /* free the tree memory */ 3382 tfreeblk(); 3383} 3384 3385static void | 3258 if (tn == NULL && nerr == 0) 3259 lerror("expr() 1"); 3260 3261 if (tn == NULL) { 3262 tfreeblk(); 3263 return; 3264 } 3265 --- 22 unchanged lines hidden (view full) --- 3288 if (dflag) 3289 displexpr(tn, 0); 3290 3291 /* free the tree memory */ 3292 tfreeblk(); 3293} 3294 3295static void |
3386nulleff(tn) 3387 tnode_t *tn; | 3296nulleff(tnode_t *tn) |
3388{ | 3297{ |
3298 |
|
3389 if (!hflag) 3390 return; 3391 3392 while (!modtab[tn->tn_op].m_sideeff) { 3393 if (tn->tn_op == CVT && tn->tn_type->t_tspec == VOID) { 3394 tn = tn->tn_left; 3395 } else if (tn->tn_op == LOGAND || tn->tn_op == LOGOR) { 3396 /* 3397 * && and || have a side effect if the right operand 3398 * has a side effect. 3399 */ 3400 tn = tn->tn_right; 3401 } else if (tn->tn_op == QUEST) { 3402 /* 3403 * ? has a side effect if at least one of its right 3404 * operands has a side effect 3405 */ 3406 tn = tn->tn_right; | 3299 if (!hflag) 3300 return; 3301 3302 while (!modtab[tn->tn_op].m_sideeff) { 3303 if (tn->tn_op == CVT && tn->tn_type->t_tspec == VOID) { 3304 tn = tn->tn_left; 3305 } else if (tn->tn_op == LOGAND || tn->tn_op == LOGOR) { 3306 /* 3307 * && and || have a side effect if the right operand 3308 * has a side effect. 3309 */ 3310 tn = tn->tn_right; 3311 } else if (tn->tn_op == QUEST) { 3312 /* 3313 * ? has a side effect if at least one of its right 3314 * operands has a side effect 3315 */ 3316 tn = tn->tn_right; |
3407 } else if (tn->tn_op == COLON) { | 3317 } else if (tn->tn_op == COLON || tn->tn_op == COMMA) { |
3408 /* 3409 * : has a side effect if at least one of its operands 3410 * has a side effect 3411 */ 3412 if (modtab[tn->tn_left->tn_op].m_sideeff) { 3413 tn = tn->tn_left; 3414 } else if (modtab[tn->tn_right->tn_op].m_sideeff) { 3415 tn = tn->tn_right; --- 9 unchanged lines hidden (view full) --- 3425 warning(129); 3426} 3427 3428/* 3429 * Dump an expression to stdout 3430 * only used for debugging 3431 */ 3432static void | 3318 /* 3319 * : has a side effect if at least one of its operands 3320 * has a side effect 3321 */ 3322 if (modtab[tn->tn_left->tn_op].m_sideeff) { 3323 tn = tn->tn_left; 3324 } else if (modtab[tn->tn_right->tn_op].m_sideeff) { 3325 tn = tn->tn_right; --- 9 unchanged lines hidden (view full) --- 3335 warning(129); 3336} 3337 3338/* 3339 * Dump an expression to stdout 3340 * only used for debugging 3341 */ 3342static void |
3433displexpr(tn, offs) 3434 tnode_t *tn; 3435 int offs; | 3343displexpr(tnode_t *tn, int offs) |
3436{ | 3344{ |
3437 u_quad_t uq; | 3345 uint64_t uq; |
3438 3439 if (tn == NULL) { 3440 (void)printf("%*s%s\n", offs, "", "NULL"); 3441 return; 3442 } 3443 (void)printf("%*sop %s ", offs, "", modtab[tn->tn_op].m_name); 3444 3445 if (tn->tn_op == NAME) { --- 38 unchanged lines hidden (view full) --- 3484 } 3485} 3486 3487/* 3488 * Called by expr() to recursively perform some tests. 3489 */ 3490/* ARGSUSED */ 3491void | 3346 3347 if (tn == NULL) { 3348 (void)printf("%*s%s\n", offs, "", "NULL"); 3349 return; 3350 } 3351 (void)printf("%*sop %s ", offs, "", modtab[tn->tn_op].m_name); 3352 3353 if (tn->tn_op == NAME) { --- 38 unchanged lines hidden (view full) --- 3392 } 3393} 3394 3395/* 3396 * Called by expr() to recursively perform some tests. 3397 */ 3398/* ARGSUSED */ 3399void |
3492chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) 3493 tnode_t *tn; 3494 int vctx, tctx, eqwarn, fcall, rvdisc, szof; | 3400chkmisc(tnode_t *tn, int vctx, int tctx, int eqwarn, int fcall, int rvdisc, 3401 int szof) |
3495{ 3496 tnode_t *ln, *rn; 3497 mod_t *mp; 3498 int nrvdisc, cvctx, ctctx; 3499 op_t op; 3500 scl_t sc; 3501 dinfo_t *di; 3502 --- 76 unchanged lines hidden (view full) --- 3579 if (hflag && eqwarn) 3580 warning(160); 3581 break; 3582 case CON: 3583 case NAME: 3584 case STRING: 3585 return; 3586 /* LINTED (enumeration values not handled in switch) */ | 3402{ 3403 tnode_t *ln, *rn; 3404 mod_t *mp; 3405 int nrvdisc, cvctx, ctctx; 3406 op_t op; 3407 scl_t sc; 3408 dinfo_t *di; 3409 --- 76 unchanged lines hidden (view full) --- 3486 if (hflag && eqwarn) 3487 warning(160); 3488 break; 3489 case CON: 3490 case NAME: 3491 case STRING: 3492 return; 3493 /* LINTED (enumeration values not handled in switch) */ |
3587 default: | 3494 case OR: 3495 case XOR: 3496 case NE: 3497 case GE: 3498 case GT: 3499 case LE: 3500 case LT: 3501 case SHR: 3502 case SHL: 3503 case MINUS: 3504 case PLUS: 3505 case MOD: 3506 case DIV: 3507 case MULT: 3508 case STAR: 3509 case UMINUS: 3510 case UPLUS: 3511 case DEC: 3512 case INC: 3513 case COMPL: 3514 case NOT: 3515 case POINT: 3516 case ARROW: 3517 case NOOP: 3518 case AND: 3519 case FARG: 3520 case CASE: 3521 case INIT: 3522 case RETURN: 3523 case ICALL: 3524 case CVT: 3525 case COMMA: 3526 case FSEL: 3527 case COLON: 3528 case QUEST: 3529 case LOGOR: 3530 case LOGAND: 3531 break; |
3588 } 3589 3590 cvctx = mp->m_vctx; 3591 ctctx = mp->m_tctx; 3592 /* 3593 * values of operands of ':' are not used if the type of at least 3594 * one of the operands (for gcc compatibility) is void 3595 * XXX test/value context of QUEST should probably be used as --- 11 unchanged lines hidden (view full) --- 3607 break; 3608 case LOGAND: 3609 case LOGOR: 3610 chkmisc(rn, 0, 1, mp->m_eqwarn, 0, 0, szof); 3611 break; 3612 case COLON: 3613 chkmisc(rn, cvctx, ctctx, mp->m_eqwarn, 0, 0, szof); 3614 break; | 3532 } 3533 3534 cvctx = mp->m_vctx; 3535 ctctx = mp->m_tctx; 3536 /* 3537 * values of operands of ':' are not used if the type of at least 3538 * one of the operands (for gcc compatibility) is void 3539 * XXX test/value context of QUEST should probably be used as --- 11 unchanged lines hidden (view full) --- 3551 break; 3552 case LOGAND: 3553 case LOGOR: 3554 chkmisc(rn, 0, 1, mp->m_eqwarn, 0, 0, szof); 3555 break; 3556 case COLON: 3557 chkmisc(rn, cvctx, ctctx, mp->m_eqwarn, 0, 0, szof); 3558 break; |
3559 case COMMA: 3560 chkmisc(rn, vctx, tctx, mp->m_eqwarn, 0, 0, szof); 3561 break; |
|
3615 default: 3616 if (mp->m_binary) 3617 chkmisc(rn, 1, 0, mp->m_eqwarn, 0, 0, szof); 3618 break; 3619 } 3620 3621} 3622 3623/* 3624 * Checks the range of array indices, if possible. 3625 * amper is set if only the address of the element is used. This 3626 * means that the index is allowd to refere to the first element 3627 * after the array. 3628 */ 3629static void | 3562 default: 3563 if (mp->m_binary) 3564 chkmisc(rn, 1, 0, mp->m_eqwarn, 0, 0, szof); 3565 break; 3566 } 3567 3568} 3569 3570/* 3571 * Checks the range of array indices, if possible. 3572 * amper is set if only the address of the element is used. This 3573 * means that the index is allowd to refere to the first element 3574 * after the array. 3575 */ 3576static void |
3630chkaidx(tn, amper) 3631 tnode_t *tn; 3632 int amper; | 3577chkaidx(tnode_t *tn, int amper) |
3633{ 3634 int dim; 3635 tnode_t *ln, *rn; 3636 int elsz; | 3578{ 3579 int dim; 3580 tnode_t *ln, *rn; 3581 int elsz; |
3637 quad_t con; | 3582 int64_t con; |
3638 3639 ln = tn->tn_left; 3640 rn = tn->tn_right; 3641 3642 /* We can only check constant indices. */ 3643 if (rn->tn_op != CON) 3644 return; 3645 3646 /* Return if the left node does not stem from an array. */ 3647 if (ln->tn_op != AMPER) 3648 return; 3649 if (ln->tn_left->tn_op != STRING && ln->tn_left->tn_op != NAME) 3650 return; 3651 if (ln->tn_left->tn_type->t_tspec != ARRAY) 3652 return; | 3583 3584 ln = tn->tn_left; 3585 rn = tn->tn_right; 3586 3587 /* We can only check constant indices. */ 3588 if (rn->tn_op != CON) 3589 return; 3590 3591 /* Return if the left node does not stem from an array. */ 3592 if (ln->tn_op != AMPER) 3593 return; 3594 if (ln->tn_left->tn_op != STRING && ln->tn_left->tn_op != NAME) 3595 return; 3596 if (ln->tn_left->tn_type->t_tspec != ARRAY) 3597 return; |
3653 | 3598 |
3654 /* 3655 * For incomplete array types, we can print a warning only if 3656 * the index is negative. 3657 */ 3658 if (incompl(ln->tn_left->tn_type) && rn->tn_val->v_quad >= 0) 3659 return; 3660 3661 /* Get the size of one array element */ 3662 if ((elsz = length(ln->tn_type->t_subt, NULL)) == 0) 3663 return; 3664 elsz /= CHAR_BIT; 3665 3666 /* Change the unit of the index from bytes to element size. */ 3667 if (isutyp(rn->tn_type->t_tspec)) { | 3599 /* 3600 * For incomplete array types, we can print a warning only if 3601 * the index is negative. 3602 */ 3603 if (incompl(ln->tn_left->tn_type) && rn->tn_val->v_quad >= 0) 3604 return; 3605 3606 /* Get the size of one array element */ 3607 if ((elsz = length(ln->tn_type->t_subt, NULL)) == 0) 3608 return; 3609 elsz /= CHAR_BIT; 3610 3611 /* Change the unit of the index from bytes to element size. */ 3612 if (isutyp(rn->tn_type->t_tspec)) { |
3668 con = (u_quad_t)rn->tn_val->v_quad / elsz; | 3613 con = (uint64_t)rn->tn_val->v_quad / elsz; |
3669 } else { 3670 con = rn->tn_val->v_quad / elsz; 3671 } 3672 3673 dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0); 3674 3675 if (!isutyp(rn->tn_type->t_tspec) && con < 0) { 3676 /* array subscript cannot be negative: %ld */ 3677 warning(167, (long)con); | 3614 } else { 3615 con = rn->tn_val->v_quad / elsz; 3616 } 3617 3618 dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0); 3619 3620 if (!isutyp(rn->tn_type->t_tspec) && con < 0) { 3621 /* array subscript cannot be negative: %ld */ 3622 warning(167, (long)con); |
3678 } else if (dim > 0 && (u_quad_t)con >= dim) { | 3623 } else if (dim > 0 && (uint64_t)con >= dim) { |
3679 /* array subscript cannot be > %d: %ld */ 3680 warning(168, dim - 1, (long)con); 3681 } 3682} 3683 3684/* 3685 * Check for ordered comparisons of unsigned values with 0. 3686 */ 3687static void | 3624 /* array subscript cannot be > %d: %ld */ 3625 warning(168, dim - 1, (long)con); 3626 } 3627} 3628 3629/* 3630 * Check for ordered comparisons of unsigned values with 0. 3631 */ 3632static void |
3688chkcomp(op, ln, rn) 3689 op_t op; 3690 tnode_t *ln, *rn; | 3633chkcomp(op_t op, tnode_t *ln, tnode_t *rn) |
3691{ 3692 tspec_t lt, rt; 3693 mod_t *mp; 3694 3695 lt = ln->tn_type->t_tspec; 3696 rt = rn->tn_type->t_tspec; 3697 mp = &modtab[op]; 3698 --- 52 unchanged lines hidden (view full) --- 3751 * the result is returned in *offsp. In the second case, the static 3752 * object is returned in *symp and the offset in *offsp. 3753 * 3754 * The expression can consist of PLUS, MINUS, AMPER, NAME, STRING and 3755 * CON. Type conversions are allowed if they do not change binary 3756 * representation (including width). 3757 */ 3758int | 3634{ 3635 tspec_t lt, rt; 3636 mod_t *mp; 3637 3638 lt = ln->tn_type->t_tspec; 3639 rt = rn->tn_type->t_tspec; 3640 mp = &modtab[op]; 3641 --- 52 unchanged lines hidden (view full) --- 3694 * the result is returned in *offsp. In the second case, the static 3695 * object is returned in *symp and the offset in *offsp. 3696 * 3697 * The expression can consist of PLUS, MINUS, AMPER, NAME, STRING and 3698 * CON. Type conversions are allowed if they do not change binary 3699 * representation (including width). 3700 */ 3701int |
3759conaddr(tn, symp, offsp) 3760 tnode_t *tn; 3761 sym_t **symp; 3762 ptrdiff_t *offsp; | 3702conaddr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp) |
3763{ 3764 sym_t *sym; 3765 ptrdiff_t offs1, offs2; 3766 tspec_t t, ot; 3767 3768 switch (tn->tn_op) { 3769 case MINUS: 3770 if (tn->tn_right->tn_op != CON) --- 45 unchanged lines hidden (view full) --- 3816 } 3817 return (0); 3818} 3819 3820/* 3821 * Concatenate two string constants. 3822 */ 3823strg_t * | 3703{ 3704 sym_t *sym; 3705 ptrdiff_t offs1, offs2; 3706 tspec_t t, ot; 3707 3708 switch (tn->tn_op) { 3709 case MINUS: 3710 if (tn->tn_right->tn_op != CON) --- 45 unchanged lines hidden (view full) --- 3756 } 3757 return (0); 3758} 3759 3760/* 3761 * Concatenate two string constants. 3762 */ 3763strg_t * |
3824catstrg(strg1, strg2) 3825 strg_t *strg1, *strg2; | 3764catstrg(strg_t *strg1, strg_t *strg2) |
3826{ 3827 size_t len1, len2, len; 3828 3829 if (strg1->st_tspec != strg2->st_tspec) { 3830 /* cannot concatenate wide and regular string literals */ 3831 error(292); 3832 return (strg1); 3833 } --- 21 unchanged lines hidden (view full) --- 3855/* 3856 * Print a warning if the given node has operands which should be 3857 * parenthesized. 3858 * 3859 * XXX Does not work if an operand is a constant expression. Constant 3860 * expressions are already folded. 3861 */ 3862static void | 3765{ 3766 size_t len1, len2, len; 3767 3768 if (strg1->st_tspec != strg2->st_tspec) { 3769 /* cannot concatenate wide and regular string literals */ 3770 error(292); 3771 return (strg1); 3772 } --- 21 unchanged lines hidden (view full) --- 3794/* 3795 * Print a warning if the given node has operands which should be 3796 * parenthesized. 3797 * 3798 * XXX Does not work if an operand is a constant expression. Constant 3799 * expressions are already folded. 3800 */ 3801static void |
3863precconf(tn) 3864 tnode_t *tn; | 3802precconf(tnode_t *tn) |
3865{ 3866 tnode_t *ln, *rn; | 3803{ 3804 tnode_t *ln, *rn; |
3867 op_t lop, rop; 3868 int lparn, rparn; | 3805 op_t lop, rop = NOOP; 3806 int lparn, rparn = 0; |
3869 mod_t *mp; 3870 int warn; 3871 3872 if (!hflag) 3873 return; 3874 3875 mp = &modtab[tn->tn_op]; 3876 --- 43 unchanged lines hidden (view full) --- 3920 if (rop == PLUS || rop == MINUS) { 3921 warn = 1; 3922 } else if (rop == AND || rop == XOR) { 3923 warn = 1; 3924 } 3925 } 3926 break; 3927 /* LINTED (enumeration values not handled in switch) */ | 3807 mod_t *mp; 3808 int warn; 3809 3810 if (!hflag) 3811 return; 3812 3813 mp = &modtab[tn->tn_op]; 3814 --- 43 unchanged lines hidden (view full) --- 3858 if (rop == PLUS || rop == MINUS) { 3859 warn = 1; 3860 } else if (rop == AND || rop == XOR) { 3861 warn = 1; 3862 } 3863 } 3864 break; 3865 /* LINTED (enumeration values not handled in switch) */ |
3928 default: | 3866 case DECAFT: 3867 case XORASS: 3868 case SHLASS: 3869 case NOOP: 3870 case ARROW: 3871 case ORASS: 3872 case POINT: 3873 case NAME: 3874 case NOT: 3875 case COMPL: 3876 case CON: 3877 case INC: 3878 case STRING: 3879 case DEC: 3880 case INCBEF: 3881 case DECBEF: 3882 case INCAFT: 3883 case FSEL: 3884 case CALL: 3885 case COMMA: 3886 case CVT: 3887 case ICALL: 3888 case LOAD: 3889 case PUSH: 3890 case RETURN: 3891 case INIT: 3892 case CASE: 3893 case FARG: 3894 case SUBASS: 3895 case ADDASS: 3896 case MODASS: 3897 case DIVASS: 3898 case MULASS: 3899 case ASSIGN: 3900 case COLON: 3901 case QUEST: 3902 case LOGAND: 3903 case NE: 3904 case EQ: 3905 case GE: 3906 case GT: 3907 case LE: 3908 case LT: 3909 case MINUS: 3910 case PLUS: 3911 case MOD: 3912 case DIV: 3913 case MULT: 3914 case AMPER: 3915 case STAR: 3916 case UMINUS: 3917 case SHRASS: 3918 case UPLUS: 3919 case ANDASS: 3920 break; |
3929 } 3930 3931 if (warn) { 3932 /* precedence confusion possible: parenthesize! */ 3933 warning(169); 3934 } 3935 3936} | 3921 } 3922 3923 if (warn) { 3924 /* precedence confusion possible: parenthesize! */ 3925 warning(169); 3926 } 3927 3928} |