Module Name: src Committed By: rillig Date: Mon Nov 1 19:10:07 UTC 2021
Modified Files: src/usr.bin/xlint: Makefile.inc src/usr.bin/xlint/lint1: ckgetopt.c decl.c lex.c tree.c Log Message: lint: move all declarations above statements All code that is used by src/tools is supposed to be compatible with C90. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/Makefile.inc cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.391 -r1.392 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/Makefile.inc diff -u src/usr.bin/xlint/Makefile.inc:1.15 src/usr.bin/xlint/Makefile.inc:1.16 --- src/usr.bin/xlint/Makefile.inc:1.15 Sat Aug 7 17:38:41 2021 +++ src/usr.bin/xlint/Makefile.inc Mon Nov 1 19:10:07 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.15 2021/08/07 17:38:41 rillig Exp $ +# $NetBSD: Makefile.inc,v 1.16 2021/11/01 19:10:07 rillig Exp $ .include <bsd.own.mk> @@ -16,6 +16,7 @@ ARCHSUBDIR= ${MACHINE_CPU} CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR} CPPFLAGS+= -I${.CURDIR}/../common +CWARNFLAGS+= -Wdeclaration-after-statement # it's a build tool CLEANFILES+= *.gcno *.gcda *.gcov Index: src/usr.bin/xlint/lint1/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.12 src/usr.bin/xlint/lint1/ckgetopt.c:1.13 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.12 Sat Oct 9 14:22:42 2021 +++ src/usr.bin/xlint/lint1/ckgetopt.c Mon Nov 1 19:10:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: ckgetopt.c,v 1.12 2021/10/09 14:22:42 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.13 2021/11/01 19:10:07 rillig Exp $"); #endif #include <stdbool.h> @@ -85,11 +85,13 @@ static struct { static bool is_getopt_condition(const tnode_t *tn, char **out_options) { + const tnode_t *call, *last_arg; + NEED(tn != NULL); NEED(tn->tn_op == NE); NEED(tn->tn_left->tn_op == ASSIGN); - const tnode_t *call = tn->tn_left->tn_right; + call = tn->tn_left->tn_right; NEED(call->tn_op == CALL); NEED(call->tn_left->tn_op == ADDR); NEED(call->tn_left->tn_left->tn_op == NAME); @@ -97,7 +99,7 @@ is_getopt_condition(const tnode_t *tn, c NEED(call->tn_right->tn_op == PUSH); - const tnode_t *last_arg = call->tn_right->tn_left; + last_arg = call->tn_right->tn_left; NEED(last_arg->tn_op == CVT); NEED(last_arg->tn_left->tn_op == ADDR); NEED(last_arg->tn_left->tn_left->tn_op == STRING); @@ -111,12 +113,14 @@ is_getopt_condition(const tnode_t *tn, c static void check_unlisted_option(char opt) { + char *optptr; + lint_assert(ck.options != NULL); if (opt == ':' && ck.options[0] != ':') goto warn; - char *optptr = strchr(ck.options, opt); + optptr = strchr(ck.options, opt); if (optptr != NULL) *optptr = ' '; else if (opt != '?') { Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.241 src/usr.bin/xlint/lint1/decl.c:1.242 --- src/usr.bin/xlint/lint1/decl.c:1.241 Fri Sep 17 21:15:19 2021 +++ src/usr.bin/xlint/lint1/decl.c Mon Nov 1 19:10:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.241 2021/09/17 21:15:19 christos Exp $ */ +/* $NetBSD: decl.c,v 1.242 2021/11/01 19:10:07 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.241 2021/09/17 21:15:19 christos Exp $"); +__RCSID("$NetBSD: decl.c,v 1.242 2021/11/01 19:10:07 rillig Exp $"); #endif #include <sys/param.h> @@ -541,12 +541,14 @@ setpackedsize(type_t *tp) sp->sou_size_in_bits = 0; for (mem = sp->sou_first_member; mem != NULL; mem = mem->s_next) { + unsigned int x; + if (mem->s_type->t_bitfield) { sp->sou_size_in_bits += bitfieldsize(&mem); if (mem == NULL) break; } - unsigned int x = type_size_in_bits(mem->s_type); + x = type_size_in_bits(mem->s_type); if (tp->t_tspec == STRUCT) sp->sou_size_in_bits += x; else if (x > sp->sou_size_in_bits) @@ -1098,9 +1100,11 @@ check_bit_field_type(sym_t *dsym, type_ * above are okay only if BITFIELDTYPE is in effect. */ if (!(bitfieldtype_ok || gflag) || !is_integer(t)) { + unsigned int sz; + /* illegal bit-field type '%s' */ warning(35, type_name(tp)); - unsigned int sz = tp->t_flen; + sz = tp->t_flen; dsym->s_type = tp = dup_type(gettyp(t = INT)); if ((tp->t_flen = sz) > size_in_bits(t)) tp->t_flen = size_in_bits(t); @@ -1113,11 +1117,13 @@ check_bit_field_type(sym_t *dsym, type_ static void declare_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp) { + type_t *tp; + tspec_t t; check_bit_field_type(dsym, inout_tp, inout_t); - type_t *const tp = *inout_tp; - tspec_t const t = *inout_t; + tp = *inout_tp; + t = *inout_t; if (tp->t_flen > size_in_bits(t)) { /* illegal bit-field size: %d */ error(36, tp->t_flen); Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.84 src/usr.bin/xlint/lint1/lex.c:1.85 --- src/usr.bin/xlint/lint1/lex.c:1.84 Sat Sep 18 10:46:17 2021 +++ src/usr.bin/xlint/lint1/lex.c Mon Nov 1 19:10:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.84 2021/09/18 10:46:17 jmcneill Exp $ */ +/* $NetBSD: lex.c,v 1.85 2021/11/01 19:10:07 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: lex.c,v 1.84 2021/09/18 10:46:17 jmcneill Exp $"); +__RCSID("$NetBSD: lex.c,v 1.85 2021/11/01 19:10:07 rillig Exp $"); #endif #include <ctype.h> @@ -997,13 +997,15 @@ parse_line_directive_flags(const char *p *is_system = false; while (*p != '\0') { + const char *word_start, *word_end; + while (ch_isspace(*p)) p++; - const char *word_start = p; + word_start = p; while (*p != '\0' && !ch_isspace(*p)) p++; - const char *word_end = p; + word_end = p; if (word_end - word_start == 1 && word_start[0] == '1') *is_begin = true; Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.391 src/usr.bin/xlint/lint1/tree.c:1.392 --- src/usr.bin/xlint/lint1/tree.c:1.391 Mon Nov 1 18:11:25 2021 +++ src/usr.bin/xlint/lint1/tree.c Mon Nov 1 19:10:07 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.391 2021/11/01 18:11:25 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.392 2021/11/01 19:10:07 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.391 2021/11/01 18:11:25 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.392 2021/11/01 19:10:07 rillig Exp $"); #endif #include <float.h> @@ -1024,6 +1024,8 @@ typeok_compare(op_t op, const tnode_t *ln, const type_t *ltp, tspec_t lt, const tnode_t *rn, const type_t *rtp, tspec_t rt) { + const char *lx, *rx; + if (lt == PTR && rt == PTR) { check_pointer_comparison(op, ln, rn); return true; @@ -1037,8 +1039,8 @@ typeok_compare(op_t op, return false; } - const char *lx = lt == PTR ? "pointer" : "integer"; - const char *rx = rt == PTR ? "pointer" : "integer"; + lx = lt == PTR ? "pointer" : "integer"; + rx = rt == PTR ? "pointer" : "integer"; /* illegal combination of %s (%s) and %s (%s), op %s */ warning(123, lx, type_name(ltp), rx, type_name(rtp), op_name(op)); return true; @@ -1552,11 +1554,13 @@ check_assign_pointer_integer(op_t op, in const type_t *const ltp, tspec_t const lt, const type_t *const rtp, tspec_t const rt) { + const char *lx, *rx; + if (!((lt == PTR && is_integer(rt)) || (is_integer(lt) && rt == PTR))) return false; - const char *lx = lt == PTR ? "pointer" : "integer"; - const char *rx = rt == PTR ? "pointer" : "integer"; + lx = lt == PTR ? "pointer" : "integer"; + rx = rt == PTR ? "pointer" : "integer"; switch (op) { case INIT: @@ -2715,14 +2719,15 @@ static type_t * merge_qualifiers(type_t *tp1, const type_t *tp2) { type_t *ntp, *nstp; + bool c1, c2, v1, v2; lint_assert(tp1->t_tspec == PTR); lint_assert(tp2->t_tspec == PTR); - bool c1 = tp1->t_subt->t_const; - bool c2 = tp2->t_subt->t_const; - bool v1 = tp1->t_subt->t_volatile; - bool v2 = tp2->t_subt->t_volatile; + c1 = tp1->t_subt->t_const; + c2 = tp2->t_subt->t_const; + v1 = tp1->t_subt->t_volatile; + v2 = tp2->t_subt->t_volatile; if (c1 == (c1 | c2) && v1 == (v1 | v2)) return tp1; @@ -3453,14 +3458,16 @@ build_sizeof(const type_t *tp) tnode_t * build_offsetof(const type_t *tp, const sym_t *sym) { - tspec_t t = tp->t_tspec; - if (t != STRUCT && t != UNION) + unsigned int offset_in_bytes; + tnode_t *tn; + + if (!is_struct_or_union(tp->t_tspec)) /* unacceptable operand of '%s' */ error(111, "offsetof"); // XXX: wrong size, no checking for sym fixme - unsigned int offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE; - tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes); + offset_in_bytes = type_size_in_bits(tp) / CHAR_SIZE; + tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes); tn->tn_system_dependent = true; return tn; } @@ -4166,9 +4173,10 @@ void check_expr_misc(const tnode_t *tn, bool vctx, bool tctx, bool eqwarn, bool fcall, bool retval_discarded, bool szof) { - tnode_t *ln, *rn; + tnode_t *ln, *rn; const mod_t *mp; - op_t op; + op_t op; + bool cvctx, ctctx, eq, discard; if (tn == NULL) return; @@ -4181,11 +4189,11 @@ check_expr_misc(const tnode_t *tn, bool szof, fcall, vctx, tctx, retval_discarded, eqwarn)) return; - bool cvctx = mp->m_left_value_context; - bool ctctx = mp->m_left_test_context; - bool eq = mp->m_warn_if_operand_eq && - !ln->tn_parenthesized && - rn != NULL && !rn->tn_parenthesized; + cvctx = mp->m_left_value_context; + ctctx = mp->m_left_test_context; + eq = mp->m_warn_if_operand_eq && + !ln->tn_parenthesized && + rn != NULL && !rn->tn_parenthesized; /* * values of operands of ':' are not used if the type of at least @@ -4195,7 +4203,7 @@ check_expr_misc(const tnode_t *tn, bool */ if (op == COLON && tn->tn_type->t_tspec == VOID) cvctx = ctctx = false; - bool discard = op == CVT && tn->tn_type->t_tspec == VOID; + discard = op == CVT && tn->tn_type->t_tspec == VOID; check_expr_misc(ln, cvctx, ctctx, eq, op == CALL, discard, szof); switch (op) {