Module Name: src Committed By: rillig Date: Sun Jan 10 00:05:46 UTC 2021
Modified Files: src/usr.bin/xlint/common: lint.h src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c func.c init.c scan.l tree.c src/usr.bin/xlint/lint2: chk.c Log Message: lint: rename type classification macros The previous names tspec_is_int and tspec_is_uint were confusing because there are actually tspec_t constants called INT and UINT, these classification macros return true for other integer types as well, though. While here, remove the prefix "tspec_" from these macros. It wasn't as helpful as intended, in many cases it was obviously redundant, when it was called as tspec_is_integer(tn->tn_type->t_tspec). No functional change. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/common/lint.h cvs rdiff -u -r1.136 -r1.137 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.113 -r1.114 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.34 -r1.35 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.54 -r1.55 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.60 -r1.61 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.115 -r1.116 src/usr.bin/xlint/lint1/scan.l cvs rdiff -u -r1.143 -r1.144 src/usr.bin/xlint/lint1/tree.c cvs rdiff -u -r1.32 -r1.33 src/usr.bin/xlint/lint2/chk.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/common/lint.h diff -u src/usr.bin/xlint/common/lint.h:1.23 src/usr.bin/xlint/common/lint.h:1.24 --- src/usr.bin/xlint/common/lint.h:1.23 Mon Jan 4 01:12:20 2021 +++ src/usr.bin/xlint/common/lint.h Sun Jan 10 00:05:45 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lint.h,v 1.23 2021/01/04 01:12:20 rillig Exp $ */ +/* $NetBSD: lint.h,v 1.24 2021/01/10 00:05:45 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -96,10 +96,10 @@ typedef struct { if pflag is set */ tspec_t tt_signed_counterpart; tspec_t tt_unsigned_counterpart; - bool tt_is_int : 1; /* integer type */ - bool tt_is_uint : 1; /* unsigned integer type */ - bool tt_is_float : 1; /* floating point type */ - bool tt_is_arith : 1; /* arithmetic type */ + bool tt_is_integer : 1; /* integer type */ + bool tt_is_uinteger : 1; /* unsigned integer type */ + bool tt_is_floating : 1; /* floating point type */ + bool tt_is_arithmetic : 1; /* arithmetic type */ bool tt_is_scalar : 1; /* scalar type */ bool tt_is_complex : 1; /* complex type */ const char *tt_name; /* name of the type */ @@ -109,12 +109,12 @@ typedef struct { #define psize(t) (ttab[t].tt_psz) #define signed_type(t) (ttab[t].tt_signed_counterpart) #define unsigned_type(t) (ttab[t].tt_unsigned_counterpart) -#define tspec_is_int(t) (ttab[t].tt_is_int) -#define tspec_is_uint(t) (ttab[t].tt_is_uint) -#define tspec_is_float(t) (ttab[t].tt_is_float) -#define tspec_is_arith(t) (ttab[t].tt_is_arith) -#define tspec_is_complex(t) (ttab[t].tt_is_complex) -#define tspec_is_scalar(t) (ttab[t].tt_is_scalar) +#define is_integer(t) (ttab[t].tt_is_integer) +#define is_uinteger(t) (ttab[t].tt_is_uinteger) +#define is_floating(t) (ttab[t].tt_is_floating) +#define is_arithmetic(t) (ttab[t].tt_is_arithmetic) +#define is_complex(t) (ttab[t].tt_is_complex) +#define is_scalar(t) (ttab[t].tt_is_scalar) extern ttab_t ttab[]; Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.136 src/usr.bin/xlint/lint1/cgram.y:1.137 --- src/usr.bin/xlint/lint1/cgram.y:1.136 Sat Jan 9 14:10:15 2021 +++ src/usr.bin/xlint/lint1/cgram.y Sun Jan 10 00:05:46 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.136 2021/01/09 14:10:15 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.137 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.136 2021/01/09 14:10:15 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.137 2021/01/10 00:05:46 rillig Exp $"); #endif #include <limits.h> @@ -2112,7 +2112,7 @@ toicon(tnode_t *tn, int required) error(55); } else { i = (int)v->v_quad; - if (tspec_is_uint(t)) { + if (is_uinteger(t)) { if (uq_gt((uint64_t)v->v_quad, (uint64_t)TARG_INT_MAX)) { /* integral constant too large */ Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.113 src/usr.bin/xlint/lint1/decl.c:1.114 --- src/usr.bin/xlint/lint1/decl.c:1.113 Sat Jan 9 14:10:15 2021 +++ src/usr.bin/xlint/lint1/decl.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.113 2021/01/09 14:10:15 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.114 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: decl.c,v 1.113 2021/01/09 14:10:15 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.114 2021/01/10 00:05:46 rillig Exp $"); #endif #include <sys/param.h> @@ -1127,7 +1127,7 @@ declarator_1_struct_union(sym_t *dsym) * Integer types not dealt with above are * okay only if BITFIELDTYPE is in effect. */ - if (!bitfieldtype_ok || !tspec_is_int(t)) { + if (!bitfieldtype_ok || !is_integer(t)) { /* illegal bit-field type */ warning(35); sz = tp->t_flen; Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.34 src/usr.bin/xlint/lint1/emit1.c:1.35 --- src/usr.bin/xlint/lint1/emit1.c:1.34 Mon Jan 4 22:26:50 2021 +++ src/usr.bin/xlint/lint1/emit1.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.34 2021/01/04 22:26:50 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.35 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit1.c,v 1.34 2021/01/04 22:26:50 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.35 2021/01/10 00:05:46 rillig Exp $"); #endif #include <ctype.h> @@ -442,7 +442,7 @@ outcall(tnode_t *tn, int rvused, int rvd continue; arg = arg->tn_left; if (arg->tn_op == CON) { - if (tspec_is_int(t = arg->tn_type->t_tspec)) { + if (is_integer(t = arg->tn_type->t_tspec)) { /* * XXX it would probably be better to * explicitly test the sign Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.54 src/usr.bin/xlint/lint1/func.c:1.55 --- src/usr.bin/xlint/lint1/func.c:1.54 Sat Jan 9 03:08:54 2021 +++ src/usr.bin/xlint/lint1/func.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.54 2021/01/09 03:08:54 rillig Exp $ */ +/* $NetBSD: func.c,v 1.55 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.54 2021/01/09 03:08:54 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.55 2021/01/10 00:05:46 rillig Exp $"); #endif #include <stdlib.h> @@ -437,7 +437,7 @@ check_case_label(tnode_t *tn, cstk_t *ci return; } - if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { + if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { /* non-integral case expression */ error(198); return; @@ -473,7 +473,7 @@ check_case_label(tnode_t *tn, cstk_t *ci if (cl->cl_val.v_quad == nv.v_quad) break; } - if (cl != NULL && tspec_is_uint(nv.v_tspec)) { + if (cl != NULL && is_uinteger(nv.v_tspec)) { /* duplicate case in switch: %lu */ error(200, (u_long)nv.v_quad); } else if (cl != NULL) { @@ -543,7 +543,7 @@ check_controlling_expression(tnode_t *tn if (tn != NULL) tn = promote(NOOP, 0, tn); - if (tn != NULL && !tspec_is_scalar(tn->tn_type->t_tspec)) { + if (tn != NULL && !is_scalar(tn->tn_type->t_tspec)) { /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */ /* C99 6.8.4.1p1 for if statements */ /* C99 6.8.5p2 for while, do and for loops */ @@ -610,7 +610,7 @@ switch1(tnode_t *tn) tn = cconv(tn); if (tn != NULL) tn = promote(NOOP, 0, tn); - if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { + if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) { /* switch expression must have integral type */ error(205); tn = NULL; @@ -720,7 +720,7 @@ while1(tnode_t *tn) pushctrl(T_WHILE); cstmt->c_loop = 1; if (tn != NULL && tn->tn_op == CON) { - if (tspec_is_int(tn->tn_type->t_tspec)) { + if (is_integer(tn->tn_type->t_tspec)) { cstmt->c_infinite = tn->tn_val->v_quad != 0; } else { cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0; @@ -784,7 +784,7 @@ do2(tnode_t *tn) tn = check_controlling_expression(tn); if (tn != NULL && tn->tn_op == CON) { - if (tspec_is_int(tn->tn_type->t_tspec)) { + if (is_integer(tn->tn_type->t_tspec)) { cstmt->c_infinite = tn->tn_val->v_quad != 0; } else { cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0; @@ -847,7 +847,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t if (tn2 == NULL) { cstmt->c_infinite = 1; } else if (tn2->tn_op == CON) { - if (tspec_is_int(tn2->tn_type->t_tspec)) { + if (is_integer(tn2->tn_type->t_tspec)) { cstmt->c_infinite = tn2->tn_val->v_quad != 0; } else { cstmt->c_infinite = tn2->tn_val->v_ldbl != 0.0; Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.60 src/usr.bin/xlint/lint1/init.c:1.61 --- src/usr.bin/xlint/lint1/init.c:1.60 Sun Jan 3 20:31:08 2021 +++ src/usr.bin/xlint/lint1/init.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.60 2021/01/03 20:31:08 rillig Exp $ */ +/* $NetBSD: init.c,v 1.61 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: init.c,v 1.60 2021/01/03 20:31:08 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.61 2021/01/10 00:05:46 rillig Exp $"); #endif #include <stdlib.h> @@ -327,8 +327,7 @@ initstack_push(void) } lint_assert(istk->i_remaining > 0); - lint_assert(istk->i_type == NULL || - !tspec_is_scalar(istk->i_type->t_tspec)); + lint_assert(istk->i_type == NULL || !is_scalar(istk->i_type->t_tspec)); initstk = xcalloc(1, sizeof (istk_t)); initstk->i_next = istk; @@ -472,8 +471,7 @@ initstack_next_brace(void) { DPRINTF(("%s\n", __func__)); - if (initstk->i_type != NULL && - tspec_is_scalar(initstk->i_type->t_tspec)) { + if (initstk->i_type != NULL && is_scalar(initstk->i_type->t_tspec)) { /* invalid initializer type %s */ error(176, type_name(initstk->i_type)); initerr = 1; @@ -494,8 +492,7 @@ initstack_next_nobrace(void) { DPRINTF(("%s\n", __func__)); - if (initstk->i_type == NULL && - !tspec_is_scalar(initstk->i_subt->t_tspec)) { + if (initstk->i_type == NULL && !is_scalar(initstk->i_subt->t_tspec)) { /* {}-enclosed initializer required */ error(181); } @@ -505,7 +502,7 @@ initstack_next_nobrace(void) initstack_check_too_many(); while (!initerr) { if ((initstk->i_type != NULL && - tspec_is_scalar(initstk->i_type->t_tspec))) + is_scalar(initstk->i_type->t_tspec))) break; initstack_push(); } @@ -521,7 +518,7 @@ init_lbrace(void) if ((initsym->s_scl == AUTO || initsym->s_scl == REG) && initstk->i_next == NULL) { - if (tflag && !tspec_is_scalar(initstk->i_subt->t_tspec)) + if (tflag && !is_scalar(initstk->i_subt->t_tspec)) /* no automatic aggregate initialization in trad. C */ warning(188); } @@ -620,7 +617,7 @@ mkinit(tnode_t *tn) lt = ln->tn_type->t_tspec; rt = tn->tn_type->t_tspec; - lint_assert(tspec_is_scalar(lt)); + lint_assert(is_scalar(lt)); if (!typeok(INIT, 0, ln, tn)) return; @@ -633,7 +630,7 @@ mkinit(tnode_t *tn) expr(tn, 1, 0, 1); trestor(tmem); - if (tspec_is_int(lt) && ln->tn_type->t_bitfield && !tspec_is_int(rt)) { + if (is_integer(lt) && ln->tn_type->t_bitfield && !is_integer(rt)) { /* * Bit-fields can be initialized in trad. C only by integer * constants. Index: src/usr.bin/xlint/lint1/scan.l diff -u src/usr.bin/xlint/lint1/scan.l:1.115 src/usr.bin/xlint/lint1/scan.l:1.116 --- src/usr.bin/xlint/lint1/scan.l:1.115 Sat Jan 9 14:10:15 2021 +++ src/usr.bin/xlint/lint1/scan.l Sun Jan 10 00:05:46 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.115 2021/01/09 14:10:15 rillig Exp $ */ +/* $NetBSD: scan.l,v 1.116 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: scan.l,v 1.115 2021/01/09 14:10:15 rillig Exp $"); +__RCSID("$NetBSD: scan.l,v 1.116 2021/01/10 00:05:46 rillig Exp $"); #endif #include <ctype.h> @@ -764,7 +764,7 @@ int sign(int64_t q, tspec_t t, int len) { - if (t == PTR || tspec_is_uint(t)) + if (t == PTR || is_uinteger(t)) return 0; return msb(q, t, len); } @@ -788,7 +788,7 @@ xsign(int64_t q, tspec_t t, int len) if (len <= 0) len = size(t); - if (t == PTR || tspec_is_uint(t) || !sign(q, t, len)) { + if (t == PTR || is_uinteger(t) || !sign(q, t, len)) { q &= qlmasks[len]; } else { q |= qumasks[len]; Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.143 src/usr.bin/xlint/lint1/tree.c:1.144 --- src/usr.bin/xlint/lint1/tree.c:1.143 Sat Jan 9 23:18:19 2021 +++ src/usr.bin/xlint/lint1/tree.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.143 2021/01/09 23:18:19 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.144 2021/01/10 00:05:46 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.143 2021/01/09 23:18:19 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.144 2021/01/10 00:05:46 rillig Exp $"); #endif #include <float.h> @@ -629,7 +629,7 @@ build(op_t op, tnode_t *ln, tnode_t *rn) if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) { if (mp->m_tctx) { ntn = fold_test(ntn); - } else if (tspec_is_float(ntn->tn_type->t_tspec)) { + } else if (is_floating(ntn->tn_type->t_tspec)) { ntn = fold_float(ntn); } else { ntn = fold(ntn); @@ -726,7 +726,7 @@ typeok_amper(mod_t *const mp, /* %soperand of '%s' must be lvalue */ error(114, "", mp->m_name); return false; - } else if (tspec_is_scalar(lt)) { + } else if (is_scalar(lt)) { if (ltp->t_bitfield) { /* cannot take address of bit-field */ error(112); @@ -761,8 +761,7 @@ static bool typeok_plus(op_t op, tspec_t lt, tspec_t rt) { /* operands have scalar types (checked above) */ - if ((lt == PTR && !tspec_is_int(rt)) || - (rt == PTR && !tspec_is_int(lt))) { + if ((lt == PTR && !is_integer(rt)) || (rt == PTR && !is_integer(lt))) { warn_incompatible_types(op, lt, rt); return false; } @@ -773,7 +772,7 @@ static bool typeok_minus(op_t op, type_t *ltp, tspec_t lt, type_t *rtp, tspec_t rt) { /* operands have scalar types (checked above) */ - if (lt == PTR && (!tspec_is_int(rt) && rt != PTR)) { + if (lt == PTR && (!is_integer(rt) && rt != PTR)) { warn_incompatible_types(op, lt, rt); return false; } else if (rt == PTR && lt != PTR) { @@ -806,7 +805,7 @@ typeok_shr(mod_t *mp, tnode_t *ln, tspec ort = before_promotion_and_balancing(rn)->tn_type->t_tspec; /* operands have integer types (checked above) */ - if (pflag && !tspec_is_uint(lt)) { + if (pflag && !is_uinteger(lt)) { /* * The left operand is signed. This means that * the operation is (possibly) nonportable. @@ -818,8 +817,7 @@ typeok_shr(mod_t *mp, tnode_t *ln, tspec /* bitop. on signed value nonportable */ warning(120); } - } else if (!tflag && !sflag && - !tspec_is_uint(olt) && tspec_is_uint(ort)) { + } else if (!tflag && !sflag && !is_uinteger(olt) && is_uinteger(ort)) { /* * The left operand would become unsigned in * traditional C. @@ -829,8 +827,7 @@ typeok_shr(mod_t *mp, tnode_t *ln, tspec /* semantics of '%s' change in ANSI C; ... */ warning(118, mp->m_name); } - } else if (!tflag && !sflag && - !tspec_is_uint(olt) && !tspec_is_uint(ort) && + } else if (!tflag && !sflag && !is_uinteger(olt) && !is_uinteger(ort) && psize(lt) < psize(rt)) { /* * In traditional C the left operand would be extended, @@ -870,7 +867,7 @@ static void typeok_shift(tspec_t lt, tnode_t *rn, tspec_t rt) { if (rn->tn_op == CON) { - if (!tspec_is_uint(rt) && rn->tn_val->v_quad < 0) { + if (!is_uinteger(rt) && rn->tn_val->v_quad < 0) { /* negative shift */ warning(121); } else if ((uint64_t)rn->tn_val->v_quad == (uint64_t)size(lt)) { @@ -887,12 +884,12 @@ static bool typeok_eq(tnode_t *ln, tspec_t lt, tnode_t *rn, tspec_t rt) { if (lt == PTR && ((rt == PTR && rn->tn_type->t_tspec == VOID) || - tspec_is_int(rt))) { + is_integer(rt))) { if (rn->tn_op == CON && rn->tn_val->v_quad == 0) return true; } if (rt == PTR && ((lt == PTR && ln->tn_type->t_tspec == VOID) || - tspec_is_int(lt))) { + is_integer(lt))) { if (ln->tn_op == CON && ln->tn_val->v_quad == 0) return true; } @@ -905,7 +902,7 @@ typeok_ordered_comparison(op_t op, mod_t tnode_t *rn, type_t *rtp, tspec_t rt) { if ((lt == PTR || rt == PTR) && lt != rt) { - if (tspec_is_int(lt) || tspec_is_int(rt)) { + if (is_integer(lt) || is_integer(rt)) { const char *lx = lt == PTR ? "pointer" : "integer"; const char *rx = rt == PTR ? @@ -926,7 +923,7 @@ typeok_ordered_comparison(op_t op, mod_t static bool typeok_quest(tspec_t lt, tnode_t **rn) { - if (!tspec_is_scalar(lt)) { + if (!is_scalar(lt)) { /* first operand must have scalar type, op ? : */ error(170); return false; @@ -945,7 +942,7 @@ typeok_colon(mod_t *mp, type_t *lstp, *rstp; tspec_t lst, rst; - if (tspec_is_arith(lt) && tspec_is_arith(rt)) + if (is_arithmetic(lt) && is_arithmetic(rt)) return true; if (lt == STRUCT && rt == STRUCT && ltp->t_str == rtp->t_str) @@ -959,17 +956,16 @@ typeok_colon(mod_t *mp, rst = rstp != NULL ? rstp->t_tspec : NOTSPEC; /* combination of any pointer and 0, 0L or (void *)0 is ok */ - if (lt == PTR && ((rt == PTR && rst == VOID) || tspec_is_int(rt))) { + if (lt == PTR && ((rt == PTR && rst == VOID) || is_integer(rt))) { if (rn->tn_op == CON && rn->tn_val->v_quad == 0) return true; } - if (rt == PTR && ((lt == PTR && lst == VOID) || tspec_is_int(lt))) { + if (rt == PTR && ((lt == PTR && lst == VOID) || is_integer(lt))) { if (ln->tn_op == CON && ln->tn_val->v_quad == 0) return true; } - if ((lt == PTR && tspec_is_int(rt)) || - (tspec_is_int(lt) && rt == PTR)) { + if ((lt == PTR && is_integer(rt)) || (is_integer(lt) && rt == PTR)) { const char *lx = lt == PTR ? "pointer" : "integer"; const char *rx = rt == PTR ? "pointer" : "integer"; /* illegal combination of %s (%s) and %s (%s), op %s */ @@ -1059,26 +1055,24 @@ typeok(op_t op, int arg, tnode_t *ln, tn } if (mp->m_requires_integer) { - if (!tspec_is_int(lt) || (mp->m_binary && !tspec_is_int(rt))) { + if (!is_integer(lt) || (mp->m_binary && !is_integer(rt))) { warn_incompatible_types(op, lt, rt); return false; } } else if (mp->m_requires_integer_or_complex) { - if ((!tspec_is_int(lt) && !tspec_is_complex(lt)) || - (mp->m_binary && - (!tspec_is_int(rt) && !tspec_is_complex(rt)))) { + if ((!is_integer(lt) && !is_complex(lt)) || + (mp->m_binary && (!is_integer(rt) && !is_complex(rt)))) { warn_incompatible_types(op, lt, rt); return false; } } else if (mp->m_requires_scalar) { - if (!tspec_is_scalar(lt) || - (mp->m_binary && !tspec_is_scalar(rt))) { + if (!is_scalar(lt) || (mp->m_binary && !is_scalar(rt))) { warn_incompatible_types(op, lt, rt); return false; } } else if (mp->m_requires_arith) { - if (!tspec_is_arith(lt) || - (mp->m_binary && !tspec_is_arith(rt))) { + if (!is_arithmetic(lt) || + (mp->m_binary && !is_arithmetic(rt))) { warn_incompatible_types(op, lt, rt); return false; } @@ -1102,7 +1096,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn /* Now we have an object we can create a pointer to */ break; case ARROW: - if (lt != PTR && !(tflag && tspec_is_int(lt))) { + if (lt != PTR && !(tflag && is_integer(lt))) { /* Without tflag we got already an error */ if (tflag) /* unacceptable operand of '%s' */ @@ -1180,7 +1174,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn case ADDASS: case SUBASS: /* operands have scalar types (checked above) */ - if ((lt == PTR && !tspec_is_int(rt)) || rt == PTR) { + if ((lt == PTR && !is_integer(rt)) || rt == PTR) { warn_incompatible_types(op, lt, rt); return false; } @@ -1188,8 +1182,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn case SHLASS: goto assign; case SHRASS: - if (pflag && !tspec_is_uint(lt) && - !(tflag && tspec_is_uint(rt))) { + if (pflag && !is_uinteger(lt) && !(tflag && is_uinteger(rt))) { /* bitop. on signed value possibly nonportable */ warning(117); } @@ -1303,7 +1296,7 @@ check_assign_types_compatible(op_t op, i rst = (rstp = rtp->t_subt)->t_tspec; mp = &modtab[op]; - if (tspec_is_arith(lt) && tspec_is_arith(rt)) + if (is_arithmetic(lt) && is_arithmetic(rt)) return 1; if ((lt == STRUCT || lt == UNION) && (rt == STRUCT || rt == UNION)) @@ -1311,7 +1304,7 @@ check_assign_types_compatible(op_t op, i return ltp->t_str == rtp->t_str; /* 0, 0L and (void *)0 may be assigned to any pointer */ - if (lt == PTR && ((rt == PTR && rst == VOID) || tspec_is_int(rt))) { + if (lt == PTR && ((rt == PTR && rst == VOID) || is_integer(rt))) { if (rn->tn_op == CON && rn->tn_val->v_quad == 0) return 1; } @@ -1368,8 +1361,7 @@ check_assign_types_compatible(op_t op, i return 1; } - if ((lt == PTR && tspec_is_int(rt)) || - (tspec_is_int(lt) && rt == PTR)) { + if ((lt == PTR && is_integer(rt)) || (is_integer(lt) && rt == PTR)) { const char *lx = lt == PTR ? "pointer" : "integer"; const char *rx = rt == PTR ? "pointer" : "integer"; @@ -1521,7 +1513,7 @@ check_enum_int_mismatch(op_t op, int arg * consequently. */ if (!rn->tn_type->t_isenum && rn->tn_op == CON && - tspec_is_int(rn->tn_type->t_tspec) && + is_integer(rn->tn_type->t_tspec) && rn->tn_val->v_quad == 0) { return; } @@ -1629,7 +1621,7 @@ promote(op_t op, int farg, tnode_t *tn) t = tn->tn_type->t_tspec; - if (!tspec_is_arith(t)) + if (!is_arithmetic(t)) return tn; if (!tflag) { @@ -1644,7 +1636,7 @@ promote(op_t op, int farg, tnode_t *tn) t = INT; } else { lint_assert(len == size(INT)); - if (tspec_is_uint(t)) { + if (is_uinteger(t)) { t = UINT; } else { t = INT; @@ -1707,7 +1699,7 @@ balance(op_t op, tnode_t **lnp, tnode_t lt = (*lnp)->tn_type->t_tspec; rt = (*rnp)->tn_type->t_tspec; - if (!tspec_is_arith(lt) || !tspec_is_arith(rt)) + if (!is_arithmetic(lt) || !is_arithmetic(rt)) return; if (!tflag) { @@ -1741,8 +1733,8 @@ balance(op_t op, tnode_t **lnp, tnode_t if (tl[i] == lt || tl[i] == rt) break; } - if ((tspec_is_uint(lt) || tspec_is_uint(rt)) && - !tspec_is_uint(tl[i])) { + if ((is_uinteger(lt) || is_uinteger(rt)) && + !is_uinteger(tl[i])) { i--; } t = tl[i]; @@ -1750,13 +1742,13 @@ balance(op_t op, tnode_t **lnp, tnode_t } } else { /* Keep unsigned in traditional C */ - u = tspec_is_uint(lt) || tspec_is_uint(rt); + u = is_uinteger(lt) || is_uinteger(rt); for (i = 0; tl[i] != INT; i++) { if (lt == tl[i] || rt == tl[i]) break; } t = tl[i]; - if (u && tspec_is_int(t) && !tspec_is_uint(t)) + if (u && is_integer(t) && !is_uinteger(t)) t = unsigned_type(t); } @@ -1789,12 +1781,13 @@ convert(op_t op, int arg, type_t *tp, tn if (!tflag && !sflag && op == FARG) check_prototype_conversion(arg, nt, ot, tp, tn); - if (tspec_is_int(nt) && tspec_is_int(ot)) { + if (is_integer(nt) && is_integer(ot)) { check_integer_conversion(op, arg, nt, ot, tp, tn); } else if (nt == PTR && ((ot == PTR && ost == VOID) || - tspec_is_int(ot)) && tn->tn_op == CON && tn->tn_val->v_quad == 0) { + is_integer(ot)) && tn->tn_op == CON && + tn->tn_val->v_quad == 0) { /* 0, 0L and (void *)0 may be assigned to any pointer. */ - } else if (tspec_is_int(nt) && ot == PTR) { + } else if (is_integer(nt) && ot == PTR) { check_pointer_integer_conversion(op, nt, tp, tn); } else if (nt == PTR && ot == PTR) { check_pointer_conversion(op, tn, tp); @@ -1830,7 +1823,7 @@ check_prototype_conversion(int arg, tspe { tnode_t *ptn; - if (!tspec_is_arith(nt) || !tspec_is_arith(ot)) + if (!is_arithmetic(nt) || !is_arithmetic(ot)) return; /* @@ -1849,10 +1842,10 @@ check_prototype_conversion(int arg, tspe if (nt == ot || (nt == ENUM && ot == INT)) return; - if (tspec_is_float(nt) != tspec_is_float(ot) || + if (is_floating(nt) != is_floating(ot) || psize(nt) != psize(ot)) { /* representation and/or width change */ - if (!tspec_is_int(ot) || psize(ot) > psize(INT)) { + if (!is_integer(ot) || psize(ot) > psize(INT)) { /* conversion to '%s' due to prototype, arg #%d */ warning(259, type_name(tp), arg); } @@ -1864,7 +1857,7 @@ check_prototype_conversion(int arg, tspe * if they differ only in sign and the argument is a constant * and the msb of the argument is not set, print no warning */ - if (ptn->tn_op == CON && tspec_is_int(nt) && + if (ptn->tn_op == CON && is_integer(nt) && signed_type(nt) == signed_type(ot) && msb(ptn->tn_val->v_quad, ot, -1) == 0) { /* ok */ @@ -1892,7 +1885,7 @@ check_integer_conversion(op_t op, int ar return; if (Pflag && psize(nt) > psize(ot) && - tspec_is_uint(nt) != tspec_is_uint(ot)) { + is_uinteger(nt) != is_uinteger(ot)) { if (aflag && pflag) { if (op == FARG) { /* conversion to '%s' may sign-extend ... */ @@ -2097,18 +2090,18 @@ cvtcon(op_t op, int arg, type_t *tp, val } else if (nt == LDOUBLE) { nv->v_ldbl = v->v_ldbl; } else { - nv->v_quad = (nt == PTR || tspec_is_uint(nt)) ? + nv->v_quad = (nt == PTR || is_uinteger(nt)) ? (int64_t)v->v_ldbl : (int64_t)v->v_ldbl; } } else { if (nt == FLOAT) { - nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ? + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? (float)(uint64_t)v->v_quad : (float)v->v_quad; } else if (nt == DOUBLE) { - nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ? + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? (double)(uint64_t)v->v_quad : (double)v->v_quad; } else if (nt == LDOUBLE) { - nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ? + nv->v_ldbl = (ot == PTR || is_uinteger(ot)) ? (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; } else { rchk = 1; /* Check for lost precision. */ @@ -2116,11 +2109,11 @@ cvtcon(op_t op, int arg, type_t *tp, val } } - if (v->v_ansiu && tspec_is_float(nt)) { + if (v->v_ansiu && is_floating(nt)) { /* ANSI C treats constant as unsigned */ warning(157); v->v_ansiu = 0; - } else if (v->v_ansiu && (tspec_is_int(nt) && !tspec_is_uint(nt) && + } else if (v->v_ansiu && (is_integer(nt) && !is_uinteger(nt) && psize(nt) > psize(ot))) { /* ANSI C treats constant as unsigned */ warning(157); @@ -2178,8 +2171,9 @@ cvtcon(op_t op, int arg, type_t *tp, val /* constant truncated by conv., op %s */ warning(306, modtab[op].m_name); } - } else if ((nt != PTR && tspec_is_uint(nt)) && - (ot != PTR && !tspec_is_uint(ot)) && v->v_quad < 0) { + } else if ((nt != PTR && is_uinteger(nt)) && + (ot != PTR && !is_uinteger(ot)) && + v->v_quad < 0) { if (op == ASSIGN) { /* assignment of negative constant to ... */ warning(164); @@ -2197,8 +2191,7 @@ cvtcon(op_t op, int arg, type_t *tp, val } } else if (nv->v_quad != v->v_quad && nsz <= osz && (v->v_quad & xmask) != 0 && - (tspec_is_uint(ot) || - (v->v_quad & xmsk1) != xmsk1)) { + (is_uinteger(ot) || (v->v_quad & xmsk1) != xmsk1)) { /* * Loss of significant bit(s). All truncated bits * of unsigned types or all truncated bits plus the @@ -2404,7 +2397,7 @@ build_struct_access(op_t op, tnode_t *ln ln = build_ampersand(ln, 1); } else if (ln->tn_type->t_tspec != PTR) { lint_assert(tflag); - lint_assert(tspec_is_int(ln->tn_type->t_tspec)); + lint_assert(is_integer(ln->tn_type->t_tspec)); ln = convert(NOOP, 0, tincref(gettyp(VOID), PTR), ln); } @@ -2521,8 +2514,7 @@ build_plus_minus(op_t op, tnode_t *ln, t type_t *tp; /* If pointer and integer, then pointer to the lhs. */ - if (rn->tn_type->t_tspec == PTR && - tspec_is_int(ln->tn_type->t_tspec)) { + if (rn->tn_type->t_tspec == PTR && is_integer(ln->tn_type->t_tspec)) { ntn = ln; ln = rn; rn = ntn; @@ -2530,7 +2522,7 @@ build_plus_minus(op_t op, tnode_t *ln, t if (ln->tn_type->t_tspec == PTR && rn->tn_type->t_tspec != PTR) { - lint_assert(tspec_is_int(rn->tn_type->t_tspec)); + lint_assert(is_integer(rn->tn_type->t_tspec)); ctn = plength(ln->tn_type); if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec) @@ -2601,7 +2593,7 @@ build_colon(tnode_t *ln, tnode_t *rn) * Arithmetic types are balanced, all other type combinations * still need to be handled. */ - if (tspec_is_arith(lt) && tspec_is_arith(rt)) { + if (is_arithmetic(lt) && is_arithmetic(rt)) { rtp = ln->tn_type; } else if (lt == VOID || rt == VOID) { rtp = gettyp(VOID); @@ -2615,13 +2607,13 @@ build_colon(tnode_t *ln, tnode_t *rn) return NULL; } rtp = ln->tn_type; - } else if (lt == PTR && tspec_is_int(rt)) { + } else if (lt == PTR && is_integer(rt)) { if (rt != pdt) { rn = convert(NOOP, 0, gettyp(pdt), rn); rt = pdt; } rtp = ln->tn_type; - } else if (rt == PTR && tspec_is_int(lt)) { + } else if (rt == PTR && is_integer(lt)) { if (lt != pdt) { ln = convert(NOOP, 0, gettyp(pdt), ln); lt = pdt; @@ -2669,7 +2661,7 @@ build_assignment(op_t op, tnode_t *ln, t rt = rn->tn_type->t_tspec; if ((op == ADDASS || op == SUBASS) && lt == PTR) { - lint_assert(tspec_is_int(rt)); + lint_assert(is_integer(rt)); ctn = plength(ln->tn_type); if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec) rn = convert(NOOP, 0, ctn->tn_type, rn); @@ -2806,7 +2798,7 @@ fold(tnode_t *tn) v = xcalloc(1, sizeof (val_t)); v->v_tspec = t = tn->tn_type->t_tspec; - utyp = t == PTR || tspec_is_uint(t); + utyp = t == PTR || is_uinteger(t); ul = sl = tn->tn_left->tn_val->v_quad; if (modtab[tn->tn_op].m_binary) ur = sr = tn->tn_right->tn_val->v_quad; @@ -2947,14 +2939,14 @@ fold_test(tnode_t *tn) v->v_tspec = tn->tn_type->t_tspec; lint_assert(tn->tn_type->t_tspec == INT); - if (tspec_is_float(tn->tn_left->tn_type->t_tspec)) { + if (is_floating(tn->tn_left->tn_type->t_tspec)) { l = tn->tn_left->tn_val->v_ldbl != 0.0; } else { l = tn->tn_left->tn_val->v_quad != 0; } if (modtab[tn->tn_op].m_binary) { - if (tspec_is_float(tn->tn_right->tn_type->t_tspec)) { + if (is_floating(tn->tn_right->tn_type->t_tspec)) { r = tn->tn_right->tn_val->v_ldbl != 0.0; } else { r = tn->tn_right->tn_val->v_quad != 0; @@ -2995,7 +2987,7 @@ fold_float(tnode_t *tn) v = xcalloc(1, sizeof (val_t)); v->v_tspec = t = tn->tn_type->t_tspec; - lint_assert(tspec_is_float(t)); + lint_assert(is_floating(t)); lint_assert(t == tn->tn_left->tn_type->t_tspec); lint_assert(!modtab[tn->tn_op].m_binary || t == tn->tn_right->tn_type->t_tspec); @@ -3281,11 +3273,11 @@ cast(tnode_t *tn, type_t *tp) /* improper cast of void expression */ error(148); return NULL; - } else if (tspec_is_int(nt) && tspec_is_scalar(ot)) { + } else if (is_integer(nt) && is_scalar(ot)) { /* ok */ - } else if (tspec_is_float(nt) && tspec_is_arith(ot)) { + } else if (is_floating(nt) && is_arithmetic(ot)) { /* ok */ - } else if (nt == PTR && tspec_is_int(ot)) { + } else if (nt == PTR && is_integer(ot)) { /* ok */ } else if (nt == PTR && ot == PTR) { if (!tp->t_subt->t_const && tn->tn_type->t_subt->t_const) { @@ -3416,7 +3408,7 @@ check_function_arguments(type_t *ftp, tn /* argument cannot have unknown size, arg #%d */ error(152, n); return NULL; - } else if (tspec_is_int(at) && + } else if (is_integer(at) && arg->tn_left->tn_type->t_isenum && incompl(arg->tn_left->tn_type)) { /* argument cannot have unknown size, arg #%d */ @@ -3496,7 +3488,7 @@ constant(tnode_t *tn, int required) if (tn->tn_op == CON) { lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec); - if (tspec_is_int(tn->tn_val->v_tspec)) { + if (is_integer(tn->tn_val->v_tspec)) { v->v_ansiu = tn->tn_val->v_ansiu; v->v_quad = tn->tn_val->v_quad; return v; @@ -3513,7 +3505,7 @@ constant(tnode_t *tn, int required) /* variable array dimension is a C99/GCC extension */ c99ism(318); - if (!tspec_is_int(v->v_tspec)) + if (!is_integer(v->v_tspec)) v->v_tspec = INT; return v; @@ -3630,9 +3622,9 @@ display_expression(tnode_t *tn, int offs (void)printf("%s: %s ", tn->tn_sym->s_name, storage_class_name(tn->tn_sym->s_scl)); - } else if (tn->tn_op == CON && tspec_is_float(tn->tn_type->t_tspec)) { + } else if (tn->tn_op == CON && is_floating(tn->tn_type->t_tspec)) { (void)printf("%#g ", (double)tn->tn_val->v_ldbl); - } else if (tn->tn_op == CON && tspec_is_int(tn->tn_type->t_tspec)) { + } else if (tn->tn_op == CON && is_integer(tn->tn_type->t_tspec)) { uq = tn->tn_val->v_quad; (void)printf("0x %08lx %08lx ", (long)(uq >> 32) & 0xffffffffl, @@ -3887,7 +3879,7 @@ check_array_index(tnode_t *tn, int amper elsz /= CHAR_SIZE; /* Change the unit of the index from bytes to element size. */ - if (tspec_is_uint(rn->tn_type->t_tspec)) { + if (is_uinteger(rn->tn_type->t_tspec)) { con = (uint64_t)rn->tn_val->v_quad / elsz; } else { con = rn->tn_val->v_quad / elsz; @@ -3895,7 +3887,7 @@ check_array_index(tnode_t *tn, int amper dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0); - if (!tspec_is_uint(rn->tn_type->t_tspec) && con < 0) { + if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) { /* array subscript cannot be negative: %ld */ warning(167, (long)con); } else if (dim > 0 && (uint64_t)con >= (uint64_t)dim) { @@ -3920,7 +3912,7 @@ check_integer_comparison(op_t op, tnode_ if (ln->tn_op != CON && rn->tn_op != CON) return; - if (!tspec_is_int(lt) || !tspec_is_int(rt)) + if (!is_integer(lt) || !is_integer(rt)) return; if ((hflag || pflag) && lt == CHAR && rn->tn_op == CON && @@ -3937,7 +3929,7 @@ check_integer_comparison(op_t op, tnode_ warning(230, mp->m_name); return; } - if (tspec_is_uint(lt) && !tspec_is_uint(rt) && + if (is_uinteger(lt) && !is_uinteger(rt) && rn->tn_op == CON && rn->tn_val->v_quad <= 0) { if (rn->tn_val->v_quad < 0) { /* comparison of %s with %s, op %s */ @@ -3949,7 +3941,7 @@ check_integer_comparison(op_t op, tnode_ } return; } - if (tspec_is_uint(rt) && !tspec_is_uint(lt) && + if (is_uinteger(rt) && !is_uinteger(lt) && ln->tn_op == CON && ln->tn_val->v_quad <= 0) { if (ln->tn_val->v_quad < 0) { /* comparison of %s with %s, op %s */ @@ -4023,8 +4015,8 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdi case CVT: t = tn->tn_type->t_tspec; ot = tn->tn_left->tn_type->t_tspec; - if ((!tspec_is_int(t) && t != PTR) || - (!tspec_is_int(ot) && ot != PTR)) { + if ((!is_integer(t) && t != PTR) || + (!is_integer(ot) && ot != PTR)) { return -1; } #ifdef notdef Index: src/usr.bin/xlint/lint2/chk.c diff -u src/usr.bin/xlint/lint2/chk.c:1.32 src/usr.bin/xlint/lint2/chk.c:1.33 --- src/usr.bin/xlint/lint2/chk.c:1.32 Mon Jan 4 22:26:51 2021 +++ src/usr.bin/xlint/lint2/chk.c Sun Jan 10 00:05:46 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.32 2021/01/04 22:26:51 rillig Exp $ */ +/* $NetBSD: chk.c,v 1.33 2021/01/10 00:05:46 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: chk.c,v 1.32 2021/01/04 22:26:51 rillig Exp $"); +__RCSID("$NetBSD: chk.c,v 1.33 2021/01/10 00:05:46 rillig Exp $"); #endif #include <ctype.h> @@ -492,7 +492,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym */ t1 = arg1->t_tspec; t2 = arg2->t_tspec; - if (tspec_is_int(t1) && tspec_is_int(t2) && + if (is_integer(t1) && is_integer(t2) && !arg1->t_isenum && !arg2->t_isenum) { if (promote) { /* @@ -571,7 +571,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym } } - } else if (t1 == PTR && tspec_is_int(t2)) { + } else if (t1 == PTR && is_integer(t2)) { for (ai = call->f_args; ai != NULL; ai = ai->a_next) { if (ai->a_num == n) break;