Module Name: src Committed By: rillig Date: Sat Mar 20 20:39:35 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: main1.c op.h oper.c ops.def tree.c Log Message: lint: remove redundant operator properties table It's enough to have modtab, which describes the properties of the various operators. There is no need to have a second table imods that holds the same content. Rather make modtab constant as well. The only possible functional change is that the names of the internal operators 'no-op', '++', '--', 'real', 'imag' and 'case' may appear in diagnostics, where previously lint invoked undefined behavior by passing a null pointer for a '%s' conversion specifier. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/usr.bin/xlint/lint1/main1.c cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/ops.def cvs rdiff -u -r1.239 -r1.240 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/main1.c diff -u src/usr.bin/xlint/lint1/main1.c:1.37 src/usr.bin/xlint/lint1/main1.c:1.38 --- src/usr.bin/xlint/lint1/main1.c:1.37 Sat Jan 16 16:53:23 2021 +++ src/usr.bin/xlint/lint1/main1.c Sat Mar 20 20:39:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: main1.c,v 1.37 2021/01/16 16:53:23 rillig Exp $ */ +/* $NetBSD: main1.c,v 1.38 2021/03/20 20:39:35 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: main1.c,v 1.37 2021/01/16 16:53:23 rillig Exp $"); +__RCSID("$NetBSD: main1.c,v 1.38 2021/03/20 20:39:35 rillig Exp $"); #endif #include <sys/types.h> @@ -253,7 +253,6 @@ main(int argc, char *argv[]) initmem(); initdecl(); initscan(); - initmtab(); if ((yyin = bltin()) == NULL) err(1, "cannot open builtins"); Index: src/usr.bin/xlint/lint1/op.h diff -u src/usr.bin/xlint/lint1/op.h:1.14 src/usr.bin/xlint/lint1/op.h:1.15 --- src/usr.bin/xlint/lint1/op.h:1.14 Sat Mar 20 20:15:37 2021 +++ src/usr.bin/xlint/lint1/op.h Sat Mar 20 20:39:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: op.h,v 1.14 2021/03/20 20:15:37 rillig Exp $ */ +/* $NetBSD: op.h,v 1.15 2021/03/20 20:39:35 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -60,7 +60,7 @@ typedef struct { const char *m_name; } mod_t; -extern mod_t modtab[]; +extern const mod_t modtab[]; #define begin_ops() typedef enum { #define op(name, repr, \ @@ -68,11 +68,9 @@ extern mod_t modtab[]; in, ic, ar, sc, \ fo, va, ts, ba, \ se, lu, ru, pc, \ - cm, ve, de, ew, \ - active) \ + cm, ve, de, ew) \ name, #define end_ops() } op_t; #include "ops.def" const char *getopname(op_t); -void initmtab(void); Index: src/usr.bin/xlint/lint1/oper.c diff -u src/usr.bin/xlint/lint1/oper.c:1.7 src/usr.bin/xlint/lint1/oper.c:1.8 --- src/usr.bin/xlint/lint1/oper.c:1.7 Sat Mar 20 20:15:37 2021 +++ src/usr.bin/xlint/lint1/oper.c Sat Mar 20 20:39:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: oper.c,v 1.7 2021/03/20 20:15:37 rillig Exp $ */ +/* $NetBSD: oper.c,v 1.8 2021/03/20 20:39:35 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -33,27 +33,21 @@ #include "op.h" #include "param.h" -mod_t modtab[NOPS]; - -static const struct { - mod_t m; - bool ok; -} imods[] = +const mod_t modtab[NOPS] = #define begin_ops() { #define op(name, repr, \ bi, lo, tb, rb, \ in, ic, ar, sc, \ fo, va, ts, ba, \ se, lu, ru, pc, \ - cm, ve, de, ew, \ - active) \ - { { \ + cm, ve, de, ew) \ + { \ bi + 0 > 0, lo + 0 > 0, tb + 0 > 0, rb + 0 > 0, \ in + 0 > 0, ic + 0 > 0, ar + 0 > 0, sc + 0 > 0, \ fo + 0 > 0, va + 0 > 0, ts + 0 > 0, ba + 0 > 0, \ se + 0 > 0, lu + 0 > 0, ru + 0 > 0, pc + 0 > 0, \ cm + 0 > 0, ve + 0 > 0, de + 0 > 0, ew + 0 > 0, \ - repr }, (active) > 0 \ + repr, \ }, #define end_ops(n) }; #include "ops.def" @@ -61,15 +55,5 @@ static const struct { const char * getopname(op_t op) { - return imods[op].m.m_name; -} - -void -initmtab(void) -{ - size_t i; - - for (i = 0; i < sizeof imods / sizeof imods[0]; i++) - if (imods[i].ok) - modtab[i] = imods[i].m; + return modtab[op].m_name; } Index: src/usr.bin/xlint/lint1/ops.def diff -u src/usr.bin/xlint/lint1/ops.def:1.18 src/usr.bin/xlint/lint1/ops.def:1.19 --- src/usr.bin/xlint/lint1/ops.def:1.18 Sat Mar 20 20:15:37 2021 +++ src/usr.bin/xlint/lint1/ops.def Sat Mar 20 20:39:35 2021 @@ -1,86 +1,86 @@ -/* $NetBSD: ops.def,v 1.18 2021/03/20 20:15:37 rillig Exp $ */ +/* $NetBSD: ops.def,v 1.19 2021/03/20 20:39:35 rillig Exp $ */ begin_ops() /* See mod_t in op.h for the definition of the table columns. */ -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( NOOP, "no-op", , , , , , , , , , , , , , , , , , , , ,0) -op( ARROW, "->", 1, ,1, , , , , , ,1, , , , , , , , , , ,1) -op( POINT, ".", 1, ,1, , , , , , , , , , , , , , , , , ,1) -op( NOT, "!", ,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ,1) -op( COMPL, "~", , , , , ,1, , ,1,1, , , , , , , , ,1,1,1) -op( INC, "++", , , , , , , , , , , , , , , , , , , , ,0) -op( DEC, "--", , , , , , , , , , , , , , , , , , , , ,0) -op( INCBEF, "++x", , , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( DECBEF, "--x", , , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( INCAFT, "x++", , , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( DECAFT, "x--", , , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( UPLUS, "+", , , , , , ,1, ,1,1, , , , , , , , ,1,1,1) -op( UMINUS, "-", , , , , , ,1, ,1,1, , , ,1, , , , ,1,1,1) -op( INDIR, "*", , , , , , , , , ,1, , , , , , , , , , ,1) -op( ADDR, "&", , ,1, , , , , , , , , , , , , , , , , ,1) +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( NOOP, "no-op", , , , , , , , , , , , , , , , , , , , ) +op( ARROW, "->", 1, ,1, , , , , , ,1, , , , , , , , , , ) +op( POINT, ".", 1, ,1, , , , , , , , , , , , , , , , , ) +op( NOT, "!", ,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ) +op( COMPL, "~", , , , , ,1, , ,1,1, , , , , , , , ,1,1) +op( INC, "++", , , , , , , , , , , , , , , , , , , , ) +op( DEC, "--", , , , , , , , , , , , , , , , , , , , ) +op( INCBEF, "++x", , , , , , , ,1, , , , ,1, , , , , ,1, ) +op( DECBEF, "--x", , , , , , , ,1, , , , ,1, , , , , ,1, ) +op( INCAFT, "x++", , , , , , , ,1, , , , ,1, , , , , ,1, ) +op( DECAFT, "x--", , , , , , , ,1, , , , ,1, , , , , ,1, ) +op( UPLUS, "+", , , , , , ,1, ,1,1, , , , , , , , ,1,1) +op( UMINUS, "-", , , , , , ,1, ,1,1, , , ,1, , , , ,1,1) +op( INDIR, "*", , , , , , , , , ,1, , , , , , , , , , ) +op( ADDR, "&", , ,1, , , , , , , , , , , , , , , , , ) /* the operator 'arr[ind]' is translated to '*(arr + ind)' during parsing. */ -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( MULT, "*", 1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1,1) -op( DIV, "/", 1, , , , , ,1, ,1,1, ,1, ,1,1, , , ,1,1,1) -op( MOD, "%", 1, , , ,1, , , ,1,1, ,1, ,1,1, , , ,1,1,1) -op( PLUS, "+", 1, , , , , , ,1,1,1, ,1, , , , , , ,1, ,1) -op( MINUS, "-", 1, , , , , , ,1,1,1, ,1, , , , , , ,1, ,1) -op( SHL, "<<", 1, , , ,1, , , ,1,1, , , , , ,1, , ,1,1,1) -op( SHR, ">>", 1, , , ,1, , , ,1,1, , , ,1, ,1, , ,1,1,1) - -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( LT, "<", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1) -op( LE, "<=", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1) -op( GT, ">", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1) -op( GE, ">=", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1,1) -op( EQ, "==", 1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1,1) -op( NE, "!=", 1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1,1) - -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( BITAND, "&", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1) -op( BITXOR, "^", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1) -op( BITOR, "|", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ,1) -op( LOGAND, "&&", 1,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ,1) -op( LOGOR, "||", 1,1,1,1, , , ,1,1, ,1, , , , ,1, , ,1, ,1) -op( QUEST, "?", 1, , , , , , , ,1, ,1, , , , , , , , , ,1) -op( COLON, ":", 1, ,1, , , , , , ,1, ,1, , , , , ,1, , ,1) - -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( ASSIGN, "=", 1, ,1, , , , , , , , , ,1, , , , ,1, , ,1) -op( MULASS, "*=", 1, , , , , ,1, , , , , ,1, , , , , ,1, ,1) -op( DIVASS, "/=", 1, , , , , ,1, , , , , ,1, ,1, , , ,1, ,1) -op( MODASS, "%=", 1, , , ,1, , , , , , , ,1, ,1, , , ,1, ,1) -op( ADDASS, "+=", 1, , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( SUBASS, "-=", 1, , , , , , ,1, , , , ,1, , , , , ,1, ,1) -op( SHLASS, "<<=", 1, , , ,1, , , , , , , ,1, , , , , ,1, ,1) -op( SHRASS, ">>=", 1, , , ,1, , , , , , , ,1, , , , , ,1, ,1) -op( ANDASS, "&=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1) -op( XORASS, "^=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1) -op( ORASS, "|=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ,1) - -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( NAME, "name", , , , , , , , , , , , , , , , , , , , ,1) -op( CON, "constant", , , , , , , , , , , , , , , , , , , , ,1) -op( STRING, "string", , , , , , , , , , , , , , , , , , , , ,1) -op( FSEL, "fsel", , , , , , , , , , , , , , , , , , , , ,1) -op( CALL, "call", 1, , , , , , , , , , , ,1, , , , , , , ,1) -op( COMMA, ",", 1, ,1, , , , , , , , , , , , , , , , ,1,1) -op( CVT, "convert", , , , , , , , , ,1, , , , , , , , , , ,1) -op( ICALL, "icall", 1, , , , , , , , , , , ,1, , , , , , , ,1) -op( LOAD, "load", , , , , , , , , , , , , , , , , , , , ,1) -op( PUSH, "push", , , , , , , , , ,1, , , , , , , , , , ,1) -op( RETURN, "return", 1, ,1, , , , , , , , , ,1, , , , ,1, , ,1) -op( REAL, "real", , , , , , , , , , , , , , , , , , , , ,0) -op( IMAG, "imag", , , , , , , , , , , , , , , , , , , , ,0) +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( MULT, "*", 1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1) +op( DIV, "/", 1, , , , , ,1, ,1,1, ,1, ,1,1, , , ,1,1) +op( MOD, "%", 1, , , ,1, , , ,1,1, ,1, ,1,1, , , ,1,1) +op( PLUS, "+", 1, , , , , , ,1,1,1, ,1, , , , , , ,1, ) +op( MINUS, "-", 1, , , , , , ,1,1,1, ,1, , , , , , ,1, ) +op( SHL, "<<", 1, , , ,1, , , ,1,1, , , , , ,1, , ,1,1) +op( SHR, ">>", 1, , , ,1, , , ,1,1, , , ,1, ,1, , ,1,1) + +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( LT, "<", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1) +op( LE, "<=", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1) +op( GT, ">", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1) +op( GE, ">=", 1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1) +op( EQ, "==", 1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1) +op( NE, "!=", 1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1) + +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( BITAND, "&", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ) +op( BITXOR, "^", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ) +op( BITOR, "|", 1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, ) +op( LOGAND, "&&", 1,1,1,1, , , ,1,1, ,1, , , , , , , ,1, ) +op( LOGOR, "||", 1,1,1,1, , , ,1,1, ,1, , , , ,1, , ,1, ) +op( QUEST, "?", 1, , , , , , , ,1, ,1, , , , , , , , , ) +op( COLON, ":", 1, ,1, , , , , , ,1, ,1, , , , , ,1, , ) + +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( ASSIGN, "=", 1, ,1, , , , , , , , , ,1, , , , ,1, , ) +op( MULASS, "*=", 1, , , , , ,1, , , , , ,1, , , , , ,1, ) +op( DIVASS, "/=", 1, , , , , ,1, , , , , ,1, ,1, , , ,1, ) +op( MODASS, "%=", 1, , , ,1, , , , , , , ,1, ,1, , , ,1, ) +op( ADDASS, "+=", 1, , , , , , ,1, , , , ,1, , , , , ,1, ) +op( SUBASS, "-=", 1, , , , , , ,1, , , , ,1, , , , , ,1, ) +op( SHLASS, "<<=", 1, , , ,1, , , , , , , ,1, , , , , ,1, ) +op( SHRASS, ">>=", 1, , , ,1, , , , , , , ,1, , , , , ,1, ) +op( ANDASS, "&=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ) +op( XORASS, "^=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ) +op( ORASS, "|=", 1, ,1, ,1, , , , , , , ,1, , , , , ,1, ) + +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( NAME, "name", , , , , , , , , , , , , , , , , , , , ) +op( CON, "constant", , , , , , , , , , , , , , , , , , , , ) +op( STRING, "string", , , , , , , , , , , , , , , , , , , , ) +op( FSEL, "fsel", , , , , , , , , , , , , , , , , , , , ) +op( CALL, "call", 1, , , , , , , , , , , ,1, , , , , , , ) +op( COMMA, ",", 1, ,1, , , , , , , , , , , , , , , , ,1) +op( CVT, "convert", , , , , , , , , ,1, , , , , , , , , , ) +op( ICALL, "icall", 1, , , , , , , , , , , ,1, , , , , , , ) +op( LOAD, "load", , , , , , , , , , , , , , , , , , , , ) +op( PUSH, "push", , , , , , , , , ,1, , , , , , , , , , ) +op( RETURN, "return", 1, ,1, , , , , , , , , ,1, , , , ,1, , ) +op( REAL, "real", , , , , , , , , , , , , , , , , , , , ) +op( IMAG, "imag", , , , , , , , , , , , , , , , , , , , ) /* INIT, CASE and FARG are pseudo operators that don't appear in the tree. */ -/* name repr b l b B i c a s f v t b s l r p c e e = act */ -op( INIT, "init", 1, ,1, , , , , , , , , , , , , , ,1, , ,1) -op( CASE, "case", , , , , , , , , , , , , , , , , , , , ,0) -op( FARG, "farg", 1, ,1, , , , , , , , , , , , , , ,1, , ,1) +/* name repr b l b B i c a s f v t b s l r p c e e = */ +op( INIT, "init", 1, ,1, , , , , , , , , , , , , , ,1, , ) +op( CASE, "case", , , , , , , , , , , , , , , , , , , , ) +op( FARG, "farg", 1, ,1, , , , , , , , , , , , , , ,1, , ) end_ops() Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.239 src/usr.bin/xlint/lint1/tree.c:1.240 --- src/usr.bin/xlint/lint1/tree.c:1.239 Sat Mar 20 18:38:25 2021 +++ src/usr.bin/xlint/lint1/tree.c Sat Mar 20 20:39:35 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.239 2021/03/20 18:38:25 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.240 2021/03/20 20:39:35 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.239 2021/03/20 18:38:25 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.240 2021/03/20 20:39:35 rillig Exp $"); #endif #include <float.h> @@ -490,7 +490,7 @@ struct_or_union_member(tnode_t *tn, op_t tnode_t * build(op_t op, tnode_t *ln, tnode_t *rn) { - mod_t *mp; + const mod_t *mp; tnode_t *ntn; type_t *rettp; @@ -1469,7 +1469,7 @@ typeok_enum(op_t op, const mod_t *mp, in bool typeok(op_t op, int arg, const tnode_t *ln, const tnode_t *rn) { - mod_t *mp; + const mod_t *mp; tspec_t lt, rt; type_t *ltp, *rtp; @@ -1542,7 +1542,7 @@ check_assign_types_compatible(op_t op, i { tspec_t lt, rt, lst = NOTSPEC, rst = NOTSPEC; type_t *ltp, *rtp, *lstp = NULL, *rstp = NULL; - mod_t *mp; + const mod_t *mp; const char *lts, *rts; if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR) @@ -1713,7 +1713,7 @@ check_bad_enum_operation(op_t op, const static void check_enum_type_mismatch(op_t op, int arg, const tnode_t *ln, const tnode_t *rn) { - mod_t *mp; + const mod_t *mp; mp = &modtab[op]; @@ -2525,7 +2525,7 @@ convert_constant(op_t op, int arg, type_ static void warn_incompatible_types(op_t op, tspec_t lt, tspec_t rt) { - mod_t *mp; + const mod_t *mp; mp = &modtab[op]; @@ -3907,7 +3907,7 @@ check_expr_misc(const tnode_t *tn, bool bool eqwarn, bool fcall, bool rvdisc, bool szof) { tnode_t *ln, *rn; - mod_t *mp; + const mod_t *mp; op_t op; scl_t sc; dinfo_t *di; @@ -4146,7 +4146,7 @@ static void check_integer_comparison(op_t op, tnode_t *ln, tnode_t *rn) { tspec_t lt, rt; - mod_t *mp; + const mod_t *mp; lt = ln->tn_type->t_tspec; rt = rn->tn_type->t_tspec;