Module Name: src Committed By: rillig Date: Fri Nov 29 06:57:43 UTC 2024
Modified Files: src/usr.bin/xlint/lint1: decl.c err.c externs1.h func.c lex.c lint1.h tree.c Log Message: lint: remove premature optimization for non-query scenarios To generate a diff of this commit: cvs rdiff -u -r1.409 -r1.410 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.256 -r1.257 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.235 -r1.236 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.189 -r1.190 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/lex.c \ src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.660 -r1.661 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/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.409 src/usr.bin/xlint/lint1/decl.c:1.410 --- src/usr.bin/xlint/lint1/decl.c:1.409 Thu Nov 28 22:32:53 2024 +++ src/usr.bin/xlint/lint1/decl.c Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.409 2024/11/28 22:32:53 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.410 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.409 2024/11/28 22:32:53 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.410 2024/11/29 06:57:43 rillig Exp $"); #endif #include <sys/param.h> @@ -1454,8 +1454,7 @@ declarator_name(sym_t *sym) dcs->d_redeclared_symbol = NULL; } else { dcs->d_redeclared_symbol = sym; - if (is_query_enabled[16] - && sym->s_scl == STATIC && dcs->d_scl != STATIC) { + if (sym->s_scl == STATIC && dcs->d_scl != STATIC) { /* '%s' was declared 'static', now non-'static' */ query_message(16, sym->s_name); print_previous_declaration(sym); @@ -1817,8 +1816,7 @@ check_extern_declaration(const sym_t *sy warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'", sym->s_name); } - if (any_query_enabled && - sym->s_type->t_tspec == FUNC && + if (sym->s_type->t_tspec == FUNC && sym->s_scl == EXTERN && sym->s_def == DECL && !in_system_header) @@ -2372,7 +2370,7 @@ declare_parameter(sym_t *sym, bool has_i /* parameter '%s' declared inline */ warning(269, sym->s_name); - if (any_query_enabled && sym->s_type->t_const + if (sym->s_type->t_const && (sym->s_scl == AUTO || sym->s_scl == REG)) { /* const automatic variable '%s' */ query_message(18, sym->s_name); @@ -2715,7 +2713,7 @@ declare_local(sym_t *dsym, bool has_init } } - if (any_query_enabled && dsym->s_type->t_const + if (dsym->s_type->t_const && (dsym->s_scl == AUTO || dsym->s_scl == REG)) { /* const automatic variable '%s' */ query_message(18, dsym->s_name); @@ -2753,7 +2751,7 @@ declare_local(sym_t *dsym, bool has_init set_first_typedef(dsym->s_type, dsym); } - if (dsym->s_scl == STATIC && any_query_enabled) + if (dsym->s_scl == STATIC) /* static variable '%s' in function */ query_message(11, dsym->s_name); Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.256 src/usr.bin/xlint/lint1/err.c:1.257 --- src/usr.bin/xlint/lint1/err.c:1.256 Thu Nov 28 22:32:53 2024 +++ src/usr.bin/xlint/lint1/err.c Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.256 2024/11/28 22:32:53 rillig Exp $ */ +/* $NetBSD: err.c,v 1.257 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.256 2024/11/28 22:32:53 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.257 2024/11/29 06:57:43 rillig Exp $"); #endif #include <limits.h> @@ -755,7 +755,6 @@ static const char *queries[] = { "typedef '%s' of pointer to union type '%s'", // Q24 }; -bool any_query_enabled; /* for optimizing non-query scenarios */ bool is_query_enabled[sizeof(queries) / sizeof(queries[0])]; void @@ -788,7 +787,6 @@ enable_queries(const char *p) queries[id][0] == '\0') break; - any_query_enabled = true; is_query_enabled[id] = true; if (*end == '\0') Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.235 src/usr.bin/xlint/lint1/externs1.h:1.236 --- src/usr.bin/xlint/lint1/externs1.h:1.235 Wed Nov 13 04:32:49 2024 +++ src/usr.bin/xlint/lint1/externs1.h Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.235 2024/11/13 04:32:49 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.236 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -183,7 +183,6 @@ void debug_attribute_list(const attribut extern bool seen_error; extern bool seen_warning; extern int sytxerr; -extern bool any_query_enabled; extern bool is_query_enabled[]; void msglist(void); Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.189 src/usr.bin/xlint/lint1/func.c:1.190 --- src/usr.bin/xlint/lint1/func.c:1.189 Wed Nov 13 04:32:49 2024 +++ src/usr.bin/xlint/lint1/func.c Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.189 2024/11/13 04:32:49 rillig Exp $ */ +/* $NetBSD: func.c,v 1.190 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.189 2024/11/13 04:32:49 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.190 2024/11/29 06:57:43 rillig Exp $"); #endif #include <stdlib.h> @@ -921,10 +921,9 @@ is_parenthesized(const tnode_t *tn) static void check_return_value(bool sys, tnode_t *tn) { - if (any_query_enabled && is_parenthesized(tn)) { + if (is_parenthesized(tn)) /* parenthesized return value */ query_message(9); - } /* Create a temporary node for the left side */ tnode_t *ln = expr_zero_alloc(sizeof(*ln), "tnode"); Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.229 src/usr.bin/xlint/lint1/lex.c:1.230 --- src/usr.bin/xlint/lint1/lex.c:1.229 Thu Aug 29 20:35:19 2024 +++ src/usr.bin/xlint/lint1/lex.c Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.229 2024/08/29 20:35:19 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.230 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.229 2024/08/29 20:35:19 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.230 2024/11/29 06:57:43 rillig Exp $"); #endif #include <ctype.h> @@ -592,7 +592,7 @@ lex_integer_constant(const char *text, s warned = true; } - if (any_query_enabled && base == 8 && ui != 0) + if (base == 8 && ui != 0) /* octal number '%.*s' */ query_message(8, (int)len, cp); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.229 src/usr.bin/xlint/lint1/lint1.h:1.230 --- src/usr.bin/xlint/lint1/lint1.h:1.229 Wed Nov 13 03:43:00 2024 +++ src/usr.bin/xlint/lint1/lint1.h Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.229 2024/11/13 03:43:00 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.230 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -635,8 +635,7 @@ check_printf(const char *fmt, ...) #else # define query_message(...) \ do { \ - if (any_query_enabled) \ - (query_message)(__VA_ARGS__); \ + (query_message)(__VA_ARGS__); \ } while (false) #endif Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.660 src/usr.bin/xlint/lint1/tree.c:1.661 --- src/usr.bin/xlint/lint1/tree.c:1.660 Sat Nov 23 16:48:35 2024 +++ src/usr.bin/xlint/lint1/tree.c Fri Nov 29 06:57:43 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.660 2024/11/23 16:48:35 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.661 2024/11/29 06:57:43 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.660 2024/11/23 16:48:35 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.661 2024/11/29 06:57:43 rillig Exp $"); #endif #include <float.h> @@ -708,7 +708,7 @@ check_integer_comparison(op_t op, tnode_ if (!is_integer(lt) || !is_integer(rt)) return; - if (any_query_enabled && !in_system_header) { + if (!in_system_header) { if (lt == CHAR && rn->tn_op == CON && !rn->u.value.v_char_constant) { /* comparison '%s' of 'char' with plain integer %d */ @@ -1485,10 +1485,9 @@ build_assignment(op_t op, bool sys, tnod tspec_t lt = ln->tn_type->t_tspec; tspec_t rt = rn->tn_type->t_tspec; - if (any_query_enabled && is_assignment(rn->tn_op)) { + if (is_assignment(rn->tn_op)) /* chained assignment with '%s' and '%s' */ query_message(10, op_name(op), op_name(rn->tn_op)); - } if ((op == ADDASS || op == SUBASS) && lt == PTR) { lint_assert(is_integer(rt)); @@ -1527,14 +1526,13 @@ build_assignment(op_t op, bool sys, tnod rt = lt; } - if (is_query_enabled[20] - && lt == PTR && ln->tn_type->t_subt->t_tspec != VOID + if (lt == PTR && ln->tn_type->t_subt->t_tspec != VOID && rt == PTR && rn->tn_type->t_subt->t_tspec == VOID && !is_null_pointer(rn)) /* implicit narrowing conversion from void ... */ query_message(20, type_name(ln->tn_type)); - if (any_query_enabled && rn->tn_op == CVT && rn->tn_cast && + if (rn->tn_op == CVT && rn->tn_cast && types_compatible(ln->tn_type, rn->tn_type, false, false, NULL) && is_cast_redundant(rn)) { /* redundant cast from '%s' to '%s' before assignment */ @@ -1934,11 +1932,9 @@ build_binary(tnode_t *ln, op_t op, bool ntn = build_assignment(op, sys, ln, rn); break; case COMMA: - if (any_query_enabled) { - /* comma operator with types '%s' and '%s' */ - query_message(12, - type_name(ln->tn_type), type_name(rn->tn_type)); - } + /* comma operator with types '%s' and '%s' */ + query_message(12, + type_name(ln->tn_type), type_name(rn->tn_type)); /* FALLTHROUGH */ case QUEST: ntn = build_op(op, sys, rn->tn_type, ln, rn); @@ -3583,7 +3579,7 @@ convert_integer_from_integer(op_t op, in } } - if (any_query_enabled && is_uinteger(nt) != is_uinteger(ot)) + if (is_uinteger(nt) != is_uinteger(ot)) /* implicit conversion changes sign from '%s' to '%s' */ query_message(3, type_name(tn->tn_type), type_name(tp)); } @@ -4305,8 +4301,7 @@ cast(tnode_t *tn, bool sys, type_t *tp) } else goto invalid_cast; - if (any_query_enabled - && types_compatible(tp, tn->tn_type, false, false, NULL)) + if (types_compatible(tp, tn->tn_type, false, false, NULL)) /* no-op cast from '%s' to '%s' */ query_message(6, type_name(tn->tn_type), type_name(tp));