Module Name: src Committed By: rillig Date: Sat Jan 9 23:18:19 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: push down complexity from typeok to typeok_shr Contrary to the comment in typeok, the types of the expressions before promotions and conversions are not needed for SHL, SHLASS and SHRASS. Move that code over to typeok_shr, the only place where it is actually used. This removes another 3 variables from typeok. To generate a diff of this commit: cvs rdiff -u -r1.142 -r1.143 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.142 src/usr.bin/xlint/lint1/tree.c:1.143 --- src/usr.bin/xlint/lint1/tree.c:1.142 Sat Jan 9 23:02:51 2021 +++ src/usr.bin/xlint/lint1/tree.c Sat Jan 9 23:18:19 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.142 2021/01/09 23:02:51 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.143 2021/01/09 23:18:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.142 2021/01/09 23:02:51 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.143 2021/01/09 23:18:19 rillig Exp $"); #endif #include <float.h> @@ -789,11 +789,22 @@ typeok_minus(op_t op, type_t *ltp, tspec return true; } +static const tnode_t * +before_promotion_and_balancing(const tnode_t *tn) +{ + while (tn->tn_op == CVT && !tn->tn_cast) + tn = tn->tn_left; + return tn; +} + static void -typeok_shr(mod_t *mp, - tnode_t *ln, tspec_t lt, tspec_t olt, - tspec_t rt, tspec_t ort) +typeok_shr(mod_t *mp, tnode_t *ln, tspec_t lt, tnode_t *rn, tspec_t rt) { + tspec_t olt, ort; + + olt = before_promotion_and_balancing(ln)->tn_type->t_tspec; + ort = before_promotion_and_balancing(rn)->tn_type->t_tspec; + /* operands have integer types (checked above) */ if (pflag && !tspec_is_uint(lt)) { /* @@ -1031,9 +1042,8 @@ bool typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn) { mod_t *mp; - tspec_t lt, rt, olt = NOTSPEC, ort = NOTSPEC; + tspec_t lt, rt; type_t *ltp, *rtp; - tnode_t *tn; mp = &modtab[op]; @@ -1074,19 +1084,6 @@ typeok(op_t op, int arg, tnode_t *ln, tn } } - if (op == SHL || op == SHR || op == SHLASS || op == SHRASS) { - /* - * For these operations we need the types before promotion - * and balancing. - */ - for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) - continue; - olt = tn->tn_type->t_tspec; - for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) - continue; - ort = tn->tn_type->t_tspec; - } - switch (op) { case POINT: /* @@ -1137,7 +1134,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn return false; break; case SHR: - typeok_shr(mp, ln, lt, olt, rt, ort); + typeok_shr(mp, ln, lt, rn, rt); goto shift; case SHL: typeok_shl(mp, lt, rt);