CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Apr 12 05:44:38 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c externs1.h tree.c Log Message: lint: clean up and speed up the check for snprintb To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.634 -r1.635 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/cksnprintb.c diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.13 src/usr.bin/xlint/lint1/cksnprintb.c:1.14 --- src/usr.bin/xlint/lint1/cksnprintb.c:1.13 Fri Apr 12 05:17:48 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Fri Apr 12 05:44:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cksnprintb.c,v 1.13 2024/04/12 05:17:48 rillig Exp $ */ +/* $NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cksnprintb.c,v 1.13 2024/04/12 05:17:48 rillig Exp $"); +__RCSID("$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $"); #endif #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: cksnprintb.c,v 1.13 20 typedef struct { bool new_style; const buffer *fmt; - const tnode_t *value; + uint64_t possible_value_bits; quoted_iterator it; uint64_t field_width; @@ -128,7 +128,7 @@ check_bit(checker *ck, uint64_t dir_lsb, } } - if (!(possible_bits(ck->value) & field_mask)) + if (!(ck->possible_value_bits & field_mask)) /* conversion '%.*s' is unreachable by input value */ warning(378, len, start); } @@ -265,9 +265,8 @@ check_conversion(checker *ck) } void -check_snprintb(const tnode_t *expr) +check_snprintb(const function_call *call) { - const function_call *call = expr->u.call; const char *name; const buffer *fmt; const tnode_t *value; @@ -287,7 +286,7 @@ check_snprintb(const tnode_t *expr) checker ck = { .fmt = fmt, - .value = value, + .possible_value_bits = possible_bits(value), .field_width = 64, }; Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.221 src/usr.bin/xlint/lint1/externs1.h:1.222 --- src/usr.bin/xlint/lint1/externs1.h:1.221 Fri Mar 29 08:35:32 2024 +++ src/usr.bin/xlint/lint1/externs1.h Fri Apr 12 05:44:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.221 2024/03/29 08:35:32 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.222 2024/04/12 05:44:38 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -422,4 +422,4 @@ void check_getopt_end_switch(void); void check_getopt_end_while(void); /* cksnprintb.c */ -void check_snprintb(const tnode_t *); +void check_snprintb(const function_call *); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.634 src/usr.bin/xlint/lint1/tree.c:1.635 --- src/usr.bin/xlint/lint1/tree.c:1.634 Sun Mar 31 20:28:45 2024 +++ src/usr.bin/xlint/lint1/tree.c Fri Apr 12 05:44:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.634 2024/03/31 20:28:45 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.634 2024/03/31 20:28:45 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $"); #endif #include @@ -4507,7 +4507,10 @@ check_expr_call(const tnode_t *tn, const lint_assert(ln->u.ops.left->tn_op == NAME); if (!szof && !is_compiler_builtin(ln->u.ops.left->u.sym->s_name)) outcall(tn, vctx || cond, retval_discarded); - check_snprintb(tn); + + const function_call *call = tn->u.call; + if (call->args_len == 4 || call->args_len == 5) + check_snprintb(call); } static void
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Apr 12 05:44:38 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c externs1.h tree.c Log Message: lint: clean up and speed up the check for snprintb To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.634 -r1.635 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 31 20:28:45 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md debug.c lint1.h op.h oper.c tree.c Log Message: lint: merge function call operators 'CALL' and 'ICALL' To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.74 -r1.75 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.633 -r1.634 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/README.md diff -u src/usr.bin/xlint/lint1/README.md:1.17 src/usr.bin/xlint/lint1/README.md:1.18 --- src/usr.bin/xlint/lint1/README.md:1.17 Thu Mar 28 21:04:48 2024 +++ src/usr.bin/xlint/lint1/README.md Sun Mar 31 20:28:45 2024 @@ -1,4 +1,4 @@ -[//]: # ($NetBSD: README.md,v 1.17 2024/03/28 21:04:48 rillig Exp $) +[//]: # ($NetBSD: README.md,v 1.18 2024/03/31 20:28:45 rillig Exp $) # Introduction @@ -115,8 +115,7 @@ Some examples for operators: | NAME | references the identifier in `u.sym` | | UPLUS| the unary operator `+u.ops.left` | | PLUS | the binary operator `u.ops.left + u.ops.right` | -| CALL | a direct function call | -| ICALL| an indirect function call | +| CALL | a function call| | CVT | an implicit conversion or an explicit cast | As an example, the expression `strcmp(names[i], "name")` has this internal Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.74 src/usr.bin/xlint/lint1/debug.c:1.75 --- src/usr.bin/xlint/lint1/debug.c:1.74 Tue Mar 19 23:19:03 2024 +++ src/usr.bin/xlint/lint1/debug.c Sun Mar 31 20:28:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.75 2024/03/31 20:28:45 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.75 2024/03/31 20:28:45 rillig Exp $"); #endif #include @@ -241,7 +241,6 @@ debug_node(const tnode_t *tn) // NOLINT( debug_printf(", length %zu\n", tn->u.str_literals->len); break; case CALL: - case ICALL: debug_printf("\n"); debug_indent_inc(); @@ -259,8 +258,7 @@ debug_node(const tnode_t *tn) // NOLINT( lint_assert(tn->u.ops.left != NULL); debug_node(tn->u.ops.left); if (op != INCBEF && op != INCAFT - && op != DECBEF && op != DECAFT - && op != CALL && op != ICALL) + && op != DECBEF && op != DECAFT) lint_assert(is_binary(tn) == (tn->u.ops.right != NULL)); if (tn->u.ops.right != NULL) debug_node(tn->u.ops.right); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.221 src/usr.bin/xlint/lint1/lint1.h:1.222 --- src/usr.bin/xlint/lint1/lint1.h:1.221 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sun Mar 31 20:28:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.221 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.222 2024/03/31 20:28:45 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -290,7 +290,7 @@ struct tnode { * wide strings, 'data' is NULL and * 'len' is the number of resulting * characters */ - function_call *call; /* if CALL or ICALL */ + function_call *call; /* if CALL */ } u; }; Index: src/usr.bin/xlint/lint1/op.h diff -u src/usr.bin/xlint/lint1/op.h:1.27 src/usr.bin/xlint/lint1/op.h:1.28 --- src/usr.bin/xlint/lint1/op.h:1.27 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/op.h Sun Mar 31 20:28:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: op.h,v 1.27 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: op.h,v 1.28 2024/03/31 20:28:45 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -117,7 +117,6 @@ typedef enum { CALL, COMMA, CVT, - ICALL, LOAD, RETURN, REAL, Index: src/usr.bin/xlint/lint1/oper.c diff -u src/usr.bin/xlint/lint1/oper.c:1.15 src/usr.bin/xlint/lint1/oper.c:1.16 --- src/usr.bin/xlint/lint1/oper.c:1.15 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/oper.c Sun Mar 31 20:28:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: oper.c,v 1.15 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: oper.c,v 1.16 2024/03/31 20:28:45 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -124,7 +124,6 @@ const mod_t modtab[NOPS] = { {_,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_, "call" }, {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X,X, "," }, {_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "convert" }, - {_,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_, "icall" },
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 31 20:28:45 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md debug.c lint1.h op.h oper.c tree.c Log Message: lint: merge function call operators 'CALL' and 'ICALL' To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.74 -r1.75 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.633 -r1.634 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 30 19:51:00 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c Log Message: lint: document which fields are not reset when starting a new type Setting all visible fields to their null value seemed as if the whole object were reset. To generate a diff of this commit: cvs rdiff -u -r1.397 -r1.398 src/usr.bin/xlint/lint1/decl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 30 19:51:00 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c Log Message: lint: document which fields are not reset when starting a new type Setting all visible fields to their null value seemed as if the whole object were reset. To generate a diff of this commit: cvs rdiff -u -r1.397 -r1.398 src/usr.bin/xlint/lint1/decl.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.397 src/usr.bin/xlint/lint1/decl.c:1.398 --- src/usr.bin/xlint/lint1/decl.c:1.397 Fri Mar 29 08:35:32 2024 +++ src/usr.bin/xlint/lint1/decl.c Sat Mar 30 19:51:00 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.398 2024/03/30 19:51:00 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.398 2024/03/30 19:51:00 rillig Exp $"); #endif #include @@ -589,6 +589,8 @@ dcs_begin_type(void) { debug_enter(); + + // keep d_kind dcs->d_abstract_type = NO_TSPEC; dcs->d_complex_mod = NO_TSPEC; dcs->d_sign_mod = NO_TSPEC; @@ -596,17 +598,24 @@ dcs_begin_type(void) dcs->d_scl = NO_SCL; dcs->d_type = NULL; dcs->d_redeclared_symbol = NULL; + // keep d_sou_size_in_bits + // keep d_sou_align_in_bits dcs->d_qual = (type_qualifiers) { .tq_const = false }; dcs->d_inline = false; dcs->d_multiple_storage_classes = false; dcs->d_invalid_type_combination = false; dcs->d_nonempty_decl = false; dcs->d_no_type_specifier = false; + // keep d_asm dcs->d_packed = false; dcs->d_used = false; + // keep d_tag_type dcs->d_func_params = NULL; dcs->d_func_def_pos = (pos_t){ NULL, 0, 0 }; + // keep d_first_dlsym + // keep d_last_dlsym dcs->d_func_proto_syms = NULL; + // keep d_enclosing } static void
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Mar 27 21:14:09 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: add missing assignment to $$ in grammar Byacc and Bison both provide this assignment for all actions, whether default or not, but the wording in POSIX doesn't guarantee this. To generate a diff of this commit: cvs rdiff -u -r1.491 -r1.492 src/usr.bin/xlint/lint1/cgram.y 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.491 src/usr.bin/xlint/lint1/cgram.y:1.492 --- src/usr.bin/xlint/lint1/cgram.y:1.491 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/cgram.y Wed Mar 27 21:14:09 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 rillig Exp $"); #endif #include @@ -651,6 +651,7 @@ argument_expression_list: add_function_argument($$, $1); } | argument_expression_list T_COMMA assignment_expression { + $$ = $1; add_function_argument($1, $3); } ;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Mar 27 21:14:09 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: add missing assignment to $$ in grammar Byacc and Bison both provide this assignment for all actions, whether default or not, but the wording in POSIX doesn't guarantee this. To generate a diff of this commit: cvs rdiff -u -r1.491 -r1.492 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Mar 19 23:19:04 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckctype.c ckgetopt.c debug.c emit1.c tree.c Log Message: lint: keep invalid arguments in function calls Previously, arguments of incomplete type or 'void' cleared all arguments of the function call expression, requiring extra checks in later checks. Invalid function calls are now exported to the .ln files, but that's irrelevant in practice as these invalid function calls make lint1 fail, after which xlint removes the .ln file. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.73 -r1.74 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.92 -r1.93 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.624 -r1.625 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/ckctype.c diff -u src/usr.bin/xlint/lint1/ckctype.c:1.11 src/usr.bin/xlint/lint1/ckctype.c:1.12 --- src/usr.bin/xlint/lint1/ckctype.c:1.11 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/ckctype.c Tue Mar 19 23:19:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckctype.c,v 1.11 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: ckctype.c,v 1.12 2024/03/19 23:19:03 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckctype.c,v 1.11 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: ckctype.c,v 1.12 2024/03/19 23:19:03 rillig Exp $"); #endif #include @@ -123,7 +123,7 @@ void check_ctype_function_call(const function_call *call) { - if (call->args_len == 1 && call->args != NULL && + if (call->args_len == 1 && call->func->tn_op == NAME && is_ctype_function(call->func->u.sym->s_name)) check_ctype_arg(call->func->u.sym->s_name, call->args[0]); Index: src/usr.bin/xlint/lint1/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.26 src/usr.bin/xlint/lint1/ckgetopt.c:1.27 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.26 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/ckgetopt.c Tue Mar 19 23:19:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.26 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.26 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $"); #endif #include @@ -96,8 +96,6 @@ is_getopt_condition(const tnode_t *tn, c && call->func->u.ops.left->tn_op == NAME && strcmp(call->func->u.ops.left->u.sym->s_name, "getopt") == 0 && call->args_len == 3 - && call->args != NULL - && (last_arg = call->args[2]) != NULL && last_arg->tn_op == CVT && last_arg->u.ops.left->tn_op == ADDR Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.73 src/usr.bin/xlint/lint1/debug.c:1.74 --- src/usr.bin/xlint/lint1/debug.c:1.73 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/debug.c Tue Mar 19 23:19:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.73 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.73 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $"); #endif #include @@ -247,11 +247,8 @@ debug_node(const tnode_t *tn) // NOLINT( debug_indent_inc(); const function_call *call = tn->u.call; debug_node(call->func); - if (call->args != NULL) { - for (size_t i = 0; i < call->args_len; i++) -debug_node(call->args[i]); - } else - debug_step("error in arguments"); + for (size_t i = 0, n = call->args_len; i < n; i++) + debug_node(call->args[i]); debug_indent_dec(); break; default: Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.92 src/usr.bin/xlint/lint1/emit1.c:1.93 --- src/usr.bin/xlint/lint1/emit1.c:1.92 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/emit1.c Tue Mar 19 23:19:03 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.92 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.92 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $"); #endif #include @@ -337,9 +337,8 @@ outcall(const tnode_t *tn, bool retval_u */ const function_call *call = tn->u.call; - /*
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Mar 19 23:19:04 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckctype.c ckgetopt.c debug.c emit1.c tree.c Log Message: lint: keep invalid arguments in function calls Previously, arguments of incomplete type or 'void' cleared all arguments of the function call expression, requiring extra checks in later checks. Invalid function calls are now exported to the .ln files, but that's irrelevant in practice as these invalid function calls make lint1 fail, after which xlint removes the .ln file. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.73 -r1.74 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.92 -r1.93 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.624 -r1.625 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Mar 13 06:48:49 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: trim down the check for snprintb formats To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/cksnprintb.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/cksnprintb.c diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.10 src/usr.bin/xlint/lint1/cksnprintb.c:1.11 --- src/usr.bin/xlint/lint1/cksnprintb.c:1.10 Sun Mar 10 16:27:16 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Wed Mar 13 06:48:49 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $ */ +/* $NetBSD: cksnprintb.c,v 1.11 2024/03/13 06:48:49 rillig Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $"); +__RCSID("$NetBSD: cksnprintb.c,v 1.11 2024/03/13 06:48:49 rillig Exp $"); #endif #include @@ -51,35 +51,10 @@ typedef struct { quoted_iterator it; uint64_t field_width; uint64_t covered; - unsigned covered_start[64]; - unsigned covered_end[64]; + const char *covered_start[64]; + int covered_len[64]; } checker; -static bool -match_string_literal(const tnode_t *tn, const buffer **str) -{ - while (tn->tn_op == CVT) - tn = tn->u.ops.left; - return tn->tn_op == ADDR - && tn->u.ops.left->tn_op == STRING - && (*str = tn->u.ops.left->u.str_literals, (*str)->data != NULL); -} - -static bool -match_snprintb_call(const function_call *call, -const buffer **fmt, const tnode_t **val) -{ - const char *func; - - return call->func->tn_op == ADDR - && call->func->u.ops.left->tn_op == NAME - && (func = call->func->u.ops.left->u.sym->s_name, true) - && ((strcmp(func, "snprintb") == 0 && call->args_len == 4) - || (strcmp(func, "snprintb_m") == 0 && call->args_len == 5)) - && match_string_literal(call->args[2], fmt) - && (*val = call->args[3], true); -} - static int len(quoted_iterator it) { @@ -126,52 +101,36 @@ check_hex_escape(const buffer *buf, quot } static void -check_overlap(checker *ck, uint64_t dir_lsb, uint64_t width, - size_t start, size_t end) +check_bit(checker *ck, uint64_t dir_lsb, uint64_t width, + const char *start, int len) { unsigned lsb = (unsigned)(ck->new_style ? dir_lsb : dir_lsb - 1); if (lsb >= 64 || width == 0 || width > 64) return; uint64_t field_mask = value_bits((unsigned)width) << lsb; - uint64_t overlap = ck->covered & field_mask; - if (overlap == 0) - goto update_covered; - for (unsigned i = lsb; i < 64; i++) { - if (!(overlap & bit(i))) - continue; - /* '%.*s' overlaps earlier '%.*s' on bit %u */ - warning(376, - (int)(end - start), ck->fmt->data + start, - (int)(ck->covered_end[i] - ck->covered_start[i]), - ck->fmt->data + ck->covered_start[i], - ck->new_style ? i : i + 1); - break; + if (ck->covered & field_mask & bit(i)) { + /* '%.*s' overlaps earlier '%.*s' on bit %u */ + warning(376, + len, start, ck->covered_len[i], + ck->covered_start[i], + ck->new_style ? i : i + 1); + break; + } } -update_covered: ck->covered |= field_mask; for (unsigned i = lsb; i < 64; i++) { if (field_mask & bit(i)) { - ck->covered_start[i] = (unsigned)start; - ck->covered_end[i] = (unsigned)end; + ck->covered_start[i] = start; + ck->covered_len[i] = len; } } -} - -static void -check_reachable(checker *ck, uint64_t dir_lsb, uint64_t width, - size_t start, size_t end) -{ - unsigned lsb = (unsigned)(ck->new_style ? dir_lsb : dir_lsb - 1); - if (lsb >= 64 || width == 0 || width > 64) - return; - uint64_t field_mask = value_bits((unsigned)width) << lsb; if (!(possible_bits(ck->value) & field_mask)) /* directive '%.*s' is unreachable by input value */ - warning(378, (int)(end - start), ck->fmt->data + start); + warning(378, len, start); } static bool @@ -266,45 +225,37 @@ check_directive(checker *ck) check_hex_escape(fmt, bit); if (has_width) check_hex_escape(fmt, width); - if (has_bit && bit.octal_digits == 0 && bit.hex_digits == 0) { + if (has_bit && bit.octal_digits == 0 && bit.hex_digits == 0) /* bit position '%.*s' in '%.*s' should be escaped as ... */ warning(369, len(bit), start(bit, fmt), range(dir, *it), start(dir, fmt)); - } - if (has_width && width.octal_digits == 0 && width.hex_digits == 0) { + if (has_width && width.octal_digits == 0 && width.hex_digits == 0) /* field width '%.*s' in '%.*s' should be escaped as ... */ warning(370, len(width), start(width, fmt), range(dir, *it), start(dir, fmt)); - } - if (has_bit && (new_style ? bit.value > 63 : bit.value - 1 > 31)) { + if (has_bit && (new_style ? bit.value > 63 : bit.value - 1 > 31)) /* bit position '%.*s' (%ju) in
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Mar 13 06:48:49 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: trim down the check for snprintb formats To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/cksnprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 16:27:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: clean up tree matcher for snprintb calls To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/cksnprintb.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/cksnprintb.c diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.9 src/usr.bin/xlint/lint1/cksnprintb.c:1.10 --- src/usr.bin/xlint/lint1/cksnprintb.c:1.9 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Sun Mar 10 16:27:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cksnprintb.c,v 1.9 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cksnprintb.c,v 1.9 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $"); #endif #include @@ -67,24 +67,17 @@ match_string_literal(const tnode_t *tn, static bool match_snprintb_call(const function_call *call, -const buffer **out_fmt, const tnode_t **out_val) +const buffer **fmt, const tnode_t **val) { const char *func; - const tnode_t *val; - const buffer *str; - if (call->func->tn_op == ADDR + return call->func->tn_op == ADDR && call->func->u.ops.left->tn_op == NAME && (func = call->func->u.ops.left->u.sym->s_name, true) && ((strcmp(func, "snprintb") == 0 && call->args_len == 4) || (strcmp(func, "snprintb_m") == 0 && call->args_len == 5)) - && match_string_literal(call->args[2], ) - && (val = call->args[3], true)) { - *out_fmt = str; - *out_val = val; - return true; - } - return false; + && match_string_literal(call->args[2], fmt) + && (*val = call->args[3], true); } static int
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 16:27:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: clean up tree matcher for snprintb calls To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/cksnprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 14:42:04 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: clean up check for overflow in integer constants To generate a diff of this commit: cvs rdiff -u -r1.619 -r1.620 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 14:42:04 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: clean up check for overflow in integer constants To generate a diff of this commit: cvs rdiff -u -r1.619 -r1.620 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.619 src/usr.bin/xlint/lint1/tree.c:1.620 --- src/usr.bin/xlint/lint1/tree.c:1.619 Sun Mar 10 14:32:30 2024 +++ src/usr.bin/xlint/lint1/tree.c Sun Mar 10 14:42:04 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.619 2024/03/10 14:32:30 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.620 2024/03/10 14:42:04 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.619 2024/03/10 14:32:30 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.620 2024/03/10 14:42:04 rillig Exp $"); #endif #include @@ -795,30 +795,26 @@ fold_unsigned_integer(op_t op, uint64_t case COMPL: return ~l; case UPLUS: - return l; + return +l; case UMINUS: return -l; - case MULT:; - uint64_t mult_result = l * r; - if (mult_result != (mult_result & max_value)) - *overflow = true; - else if (l != 0 && mult_result / l != r) - *overflow = true; - return mult_result; + case MULT: + *overflow = r > 0 && l > max_value / r; + return l * r; case DIV: if (r == 0) { /* division by 0 */ error(139); return max_value; - } else - return l / r; + } + return l / r; case MOD: if (r == 0) { /* modulus by 0 */ error(140); return 0; - } else - return l % r; + } + return l % r; case PLUS: *overflow = l > max_value - r; return l + r; @@ -827,6 +823,7 @@ fold_unsigned_integer(op_t op, uint64_t return l - r; case SHL: /* TODO: warn about out-of-bounds 'sr'. */ + /* TODO: warn about overflow. */ return l << (r & 63); case SHR: /* TODO: warn about out-of-bounds 'sr'. */ @@ -851,8 +848,8 @@ fold_unsigned_integer(op_t op, uint64_t return l | r; default: lint_assert(/*CONSTCOND*/false); + /* NOTREACHED */ } - /* NOTREACHED */ } static int64_t @@ -863,7 +860,7 @@ fold_signed_integer(op_t op, int64_t l, case COMPL: return ~l; case UPLUS: - return l; + return +l; case UMINUS: *overflow = l == min_value; return *overflow ? l : -l; @@ -876,12 +873,7 @@ fold_signed_integer(op_t op, int64_t l, *overflow = true; return (int64_t)(al * ar); } - uint64_t mult_result = l * r; - uint64_t hi = (uint64_t)max_value + 1; - // FIXME: Overflow can also happen in other bits. - if ((mult_result & hi) != ((l & hi) ^ (r & hi))) - *overflow = true; - return (int64_t)mult_result; + return l * r; case DIV: if (r == 0) { /* division by 0 */ @@ -926,9 +918,10 @@ fold_signed_integer(op_t op, int64_t l, return l - r; case SHL: /* TODO: warn about out-of-bounds 'sr'. */ - /* TODO: warn about overflow in signed '<<'. */ + /* TODO: warn about overflow. */ return l << (r & 63); case SHR:; + /* TODO: warn about out-of-bounds 'sr'. */ uint64_t shr_result = (uint64_t)l >> (r & 63); if (shr_result & min_value) shr_result |= min_value; @@ -953,8 +946,8 @@ fold_signed_integer(op_t op, int64_t l, return l | r; default: lint_assert(/*CONSTCOND*/false); + /* NOTREACHED */ } - /* NOTREACHED */ } /*
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 12:50:46 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: split integer overflow check into separate functions The checks for unsigned and signed integers differ for each operator, so there's no point having both parts in the same function. To generate a diff of this commit: cvs rdiff -u -r1.617 -r1.618 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 12:50:46 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: split integer overflow check into separate functions The checks for unsigned and signed integers differ for each operator, so there's no point having both parts in the same function. To generate a diff of this commit: cvs rdiff -u -r1.617 -r1.618 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.617 src/usr.bin/xlint/lint1/tree.c:1.618 --- src/usr.bin/xlint/lint1/tree.c:1.617 Sun Mar 10 10:31:29 2024 +++ src/usr.bin/xlint/lint1/tree.c Sun Mar 10 12:50:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.617 2024/03/10 10:31:29 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.618 2024/03/10 12:50:45 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.617 2024/03/10 10:31:29 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.618 2024/03/10 12:50:45 rillig Exp $"); #endif #include @@ -787,147 +787,206 @@ build_address(bool sys, tnode_t *tn, boo tn, NULL); } -/* - * XXX - * Note: There appear to be a number of bugs in detecting overflow in - * this function. An audit and a set of proper regression tests are needed. - * --Perry Metzger, Nov. 16, 2001 - */ -static tnode_t * -fold_constant_integer(tnode_t *tn) +static uint64_t +fold_unsigned_integer(op_t op, uint64_t l, uint64_t r, + uint64_t max_value, bool *overflow) { - - lint_assert(has_operands(tn)); - tspec_t t = tn->u.ops.left->tn_type->t_tspec; - bool utyp = !is_integer(t) || is_uinteger(t); - int64_t sl = tn->u.ops.left->u.value.u.integer, sr = 0; - uint64_t ul = sl, ur = 0; - if (is_binary(tn)) - ur = sr = tn->u.ops.right->u.value.u.integer; - - uint64_t mask = value_bits(size_in_bits(t)); - int64_t max_value = (int64_t)(mask >> 1); - int64_t min_value = -max_value - 1; - bool ovfl = false; - - int64_t si; - switch (tn->tn_op) { + switch (op) { case COMPL: - si = ~sl; - break; + return ~l; case UPLUS: - si = sl; - break; + return l; case UMINUS: - if (utyp) - si = (int64_t)-ul; - else { - ovfl = sl == min_value; - si = ovfl ? sl : -sl; - } - break; - case MULT: - if (utyp) { - si = (int64_t)(ul * ur); - if (si != (si & (int64_t)mask)) -ovfl = true; - else if (ul != 0 && si / ul != ur) -ovfl = true; - } else { - uint64_t al = sl >= 0 ? ul : -ul; - uint64_t ar = sr >= 0 ? ur : -ur; - bool neg = (sl >= 0) != (sr >= 0); - uint64_t max_prod = (uint64_t)max_value - + (neg ? 1 : 0); - if (al > 0 && ar > max_prod / al) { -si = (int64_t)(al * ar); -ovfl = true; - } else -si = sl * sr; - if (msb(si, t) != (msb(sl, t) ^ msb(sr, t))) -ovfl = true; - } - break; + return -l; + case MULT:; + uint64_t mult_result = l * r; + if (mult_result != (mult_result & max_value)) + *overflow = true; + else if (l != 0 && mult_result / l != r) + *overflow = true; + return mult_result; case DIV: - if (sr == 0) { + if (r == 0) { /* division by 0 */ error(139); - si = utyp ? -1 : max_value; - } else if (!utyp && sl == min_value && sr == -1) { - ovfl = true; - si = sl; + return max_value; } else - si = utyp ? (int64_t)(ul / ur) : sl / sr; - break; + return l / r; case MOD: - if (sr == 0) { + if (r == 0) { /* modulus by 0 */ error(140); - si = 0; - } else if (!utyp && sl == min_value && sr == -1) { - ovfl = true; - si = 0; + return 0; } else - si = utyp ? (int64_t)(ul % ur) : sl % sr; - break; - case PLUS: - si = (int64_t)(ul + ur); - if (msb(sl, t) && msb(sr, t) && !msb(si, t)) - ovfl = true; - if (!utyp && !msb(sl, t) && !msb(sr, t) && msb(si, t)) - ovfl = true; - break; - case MINUS: - si = (int64_t)(ul - ur); - if (!utyp && msb(sl, t) && !msb(sr, t) && !msb(si, t)) - ovfl = true; - if (!msb(sl, t) && msb(sr, t) && msb(si, t)) - ovfl = true; - break; + return l % r; + case PLUS:; + uint64_t plus_result = l + r; + uint64_t hi = max_value ^ (max_value >> 1); + if (l & hi && r & hi && !(plus_result & hi)) + *overflow = true; + return plus_result; + case MINUS:; + uint64_t minus_result = l - r; + hi = max_value ^ (max_value >> 1); + if (!(l & hi) && r & hi && minus_result & hi) + *overflow = true; + return minus_result; case SHL: /* TODO: warn about out-of-bounds 'sr'. */ - /* TODO: warn about overflow in signed '<<'. */ - si = utyp ? (int64_t)(ul << (sr & 63)) : sl << (sr & 63); - break; + return l << (r & 63); case SHR: - /* - * The sign must be explicitly extended because shifts of - * signed values are implementation dependent. - */ /* TODO: warn about out-of-bounds 'sr'. */ - si = (int64_t)(ul >> (sr & 63)); - si = convert_integer(si, t,
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 09:24:54 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: in check for integer overflow, sort operators To generate a diff of this commit: cvs rdiff -u -r1.614 -r1.615 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Mar 10 09:24:54 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: in check for integer overflow, sort operators To generate a diff of this commit: cvs rdiff -u -r1.614 -r1.615 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.614 src/usr.bin/xlint/lint1/tree.c:1.615 --- src/usr.bin/xlint/lint1/tree.c:1.614 Sat Mar 9 23:55:11 2024 +++ src/usr.bin/xlint/lint1/tree.c Sun Mar 10 09:24:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $"); #endif #include @@ -815,6 +815,9 @@ fold_constant_integer(tnode_t *tn) int64_t si; switch (tn->tn_op) { + case COMPL: + si = ~sl; + break; case UPLUS: si = sl; break; @@ -823,9 +826,6 @@ fold_constant_integer(tnode_t *tn) if (sl != 0 && msb(si, t) == msb(sl, t)) ovfl = true; break; - case COMPL: - si = ~sl; - break; case MULT: if (utyp) { si = (int64_t)(ul * ur); @@ -892,12 +892,12 @@ fold_constant_integer(tnode_t *tn) case LE: si = (utyp ? ul <= ur : sl <= sr) ? 1 : 0; break; - case GE: - si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0; - break; case GT: si = (utyp ? ul > ur : sl > sr) ? 1 : 0; break; + case GE: + si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0; + break; case EQ: si = (utyp ? ul == ur : sl == sr) ? 1 : 0; break;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 14:54:14 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: merge duplicate code for checking array index To generate a diff of this commit: cvs rdiff -u -r1.612 -r1.613 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.612 src/usr.bin/xlint/lint1/tree.c:1.613 --- src/usr.bin/xlint/lint1/tree.c:1.612 Sat Mar 9 13:54:47 2024 +++ src/usr.bin/xlint/lint1/tree.c Sat Mar 9 14:54:14 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $"); #endif #include @@ -4327,52 +4327,37 @@ expr(tnode_t *tn, bool vctx, bool cond, expr_free_all(); } -/* - * Checks the range of array indices, if possible. - * amper is set if only the address of the element is used. This - * means that the index is allowed to refer to the first element - * after the array. - */ +/* If the expression has the form '*(arr + idx)', check the array index. */ static void -check_array_index(tnode_t *tn, bool amper) +check_array_index(const tnode_t *indir, bool taking_address) { - lint_assert(has_operands(tn)); - const tnode_t *ln = tn->u.ops.left; - const tnode_t *rn = tn->u.ops.right; - - /* We can only check constant indices. */ - if (rn->tn_op != CON) - return; - - /* Return if the left node does not stem from an array. */ - if (ln->tn_op != ADDR) - return; - if (ln->u.ops.left->tn_op != STRING && ln->u.ops.left->tn_op != NAME) - return; - if (ln->u.ops.left->tn_type->t_tspec != ARRAY) - return; + const tnode_t *plus, *arr, *idx; - /* - * For incomplete array types, we can print a warning only if the index - * is negative. - */ - if (is_incomplete(ln->u.ops.left->tn_type) - && rn->u.value.u.integer >= 0) - return; + if (indir->tn_op == INDIR + && (plus = indir->u.ops.left, plus->tn_op == PLUS) + && plus->u.ops.left->tn_op == ADDR + && (arr = plus->u.ops.left->u.ops.left, true) + && (arr->tn_op == STRING || arr->tn_op == NAME) + && arr->tn_type->t_tspec == ARRAY + && (idx = plus->u.ops.right, idx->tn_op == CON) + && (!is_incomplete(arr->tn_type) || idx->u.value.u.integer < 0)) + goto proceed; + return; - int elsz = length_in_bits(ln->tn_type->t_subt, NULL); +proceed:; + int elsz = length_in_bits(arr->tn_type->t_subt, NULL); if (elsz == 0) return; elsz /= CHAR_SIZE; /* Change the unit of the index from bytes to element size. */ - int64_t con = is_uinteger(rn->tn_type->t_tspec) - ? (int64_t)((uint64_t)rn->u.value.u.integer / elsz) - : rn->u.value.u.integer / elsz; + int64_t con = is_uinteger(idx->tn_type->t_tspec) + ? (int64_t)((uint64_t)idx->u.value.u.integer / elsz) + : idx->u.value.u.integer / elsz; - int dim = ln->u.ops.left->tn_type->u.dimension + (amper ? 1 : 0); + int dim = arr->tn_type->u.dimension + (taking_address ? 1 : 0); - if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) + if (!is_uinteger(idx->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) @@ -4389,15 +4374,7 @@ check_expr_addr(const tnode_t *ln, bool mark_as_set(ln->u.sym); mark_as_used(ln->u.sym, fcall, szof); } - if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS) - check_array_index(ln->u.ops.left, true); -} - -static void -check_expr_load(const tnode_t *ln) -{ - if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS) - check_array_index(ln->u.ops.left, false); + check_array_index(ln, true); } /* @@ -4439,9 +4416,7 @@ check_expr_assign(const tnode_t *ln, boo if (ln->u.sym->s_scl == EXTERN) outusg(ln->u.sym); } - if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS) - /* check the range of array indices */ - check_array_index(ln->u.ops.left, false); + check_array_index(ln, false); } static void @@ -4463,7 +4438,7 @@ check_expr_op(op_t op, const tnode_t *ln check_expr_addr(ln, szof, fcall); break; case LOAD: - check_expr_load(ln); + check_array_index(ln, false); /* FALLTHROUGH */ case INCBEF: case DECBEF:
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 14:54:14 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: merge duplicate code for checking array index To generate a diff of this commit: cvs rdiff -u -r1.612 -r1.613 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 13:54:47 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h tree.c Log Message: lint: inline accessor macros for tnode_t To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.611 -r1.612 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 13:54:47 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h tree.c Log Message: lint: inline accessor macros for tnode_t To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.611 -r1.612 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/README.md diff -u src/usr.bin/xlint/lint1/README.md:1.15 src/usr.bin/xlint/lint1/README.md:1.16 --- src/usr.bin/xlint/lint1/README.md:1.15 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/README.md Sat Mar 9 13:54:47 2024 @@ -1,4 +1,4 @@ -[//]: # ($NetBSD: README.md,v 1.15 2024/02/05 23:11:22 rillig Exp $) +[//]: # ($NetBSD: README.md,v 1.16 2024/03/09 13:54:47 rillig Exp $) # Introduction @@ -108,15 +108,15 @@ Each node has an operator that defines w The operators and their properties are defined in `oper.c`. Some examples for operators: -| Operator | Meaning| -|--|| -| CON | compile-time constant in `tn_val` | -| NAME | references the identifier in `tn_sym` | -| UPLUS| the unary operator `+tn_left` | -| PLUS | the binary operator `tn_left + tn_right` | -| CALL | a direct function call | -| ICALL| an indirect function call | -| CVT | an implicit conversion or an explicit cast | +| Operator | Meaning| +|--|| +| CON | compile-time constant in `u.value` | +| NAME | references the identifier in `u.sym` | +| UPLUS| the unary operator `+u.ops.left` | +| PLUS | the binary operator `u.ops.left + u.ops.right` | +| CALL | a direct function call | +| ICALL| an indirect function call | +| CVT | an implicit conversion or an explicit cast | As an example, the expression `strcmp(names[i], "name")` has this internal structure: Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.490 src/usr.bin/xlint/lint1/cgram.y:1.491 --- src/usr.bin/xlint/lint1/cgram.y:1.490 Sat Mar 9 10:41:11 2024 +++ src/usr.bin/xlint/lint1/cgram.y Sat Mar 9 13:54:47 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $"); #endif #include @@ -625,7 +625,7 @@ gcc_statement_expr_item: } else { /* XXX: do that only on the last name */ if ($1->tn_op == NAME) -$1->tn_sym->s_used = true; +$1->u.sym->s_used = true; expr($1, false, false, false, false); suppress_fallthrough = false; $$ = $1; Index: src/usr.bin/xlint/lint1/ckbool.c diff -u src/usr.bin/xlint/lint1/ckbool.c:1.29 src/usr.bin/xlint/lint1/ckbool.c:1.30 --- src/usr.bin/xlint/lint1/ckbool.c:1.29 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/ckbool.c Sat Mar 9 13:54:47 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $"); #endif #include @@ -73,7 +73,7 @@ is_symmetric_bool_or_other(op_t op) static bool is_int_constant_zero(const tnode_t *tn, tspec_t t) { - return t == INT && tn->tn_op == CON && tn->tn_val.u.integer == 0; + return t == INT && tn->tn_op == CON && tn->u.value.u.integer == 0; } static bool @@ -201,7 +201,7 @@ bool is_typeok_bool_compares_with_zero(const tnode_t
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 11:05:05 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lint1.h Log Message: lint: clean up comments, use typedefs To generate a diff of this commit: cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lint1.h 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/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.218 src/usr.bin/xlint/lint1/lint1.h:1.219 --- src/usr.bin/xlint/lint1/lint1.h:1.218 Sat Mar 9 10:54:12 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sat Mar 9 11:05:05 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.219 2024/03/09 11:05:05 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -71,19 +71,6 @@ typedef struct { int p_uniq; /* uniquifier */ } pos_t; -// TODO: Use bit-fields instead of plain bool, but keep an eye on arm and -// powerpc, on which NetBSD's GCC 10.5.0 (but not the upstream GCC) generates -// code that leads to extra 327 warnings, even in msg_327.c, which does not -// contain any type qualifier at all. -// -// A possible starting point for continuing the investigation is that -// type_qualifiers is a very small struct that contains only bool bit-fields, -// and this struct is a member of the parser's union. -// -// Instead of using plain bool instead of bit-fields, an alternative workaround -// is to compile cgram.c with -Os or -O1 instead of -O2. The generated code -// between -Os and -O2 differs too much though to give a hint at the root -// cause. typedef struct { bool tq_const; bool tq_restrict; @@ -128,9 +115,7 @@ typedef struct { sym_t *sou_first_typedef; } struct_or_union; -/* - * same as above for enums - */ +/* The same as in struct_or_union, only for enums. */ typedef struct { bool en_incomplete:1; sym_t *en_first_enumerator; @@ -138,28 +123,21 @@ typedef struct { sym_t *en_first_typedef; } enumeration; -/* - * The type of an expression or object. Complex types are formed via t_subt - * (for arrays, pointers and functions), as well as t_sou. - */ +/* The type of an expression, object or function. */ struct lint1_type { tspec_t t_tspec; /* type specifier */ bool t_incomplete_array:1; - bool t_const:1; /* const modifier */ - bool t_volatile:1; /* volatile modifier */ + bool t_const:1; + bool t_volatile:1; bool t_proto:1; /* function prototype (t_params valid) */ bool t_vararg:1; /* prototype with '...' */ bool t_typedef:1; /* type defined with typedef */ bool t_typeof:1; /* type defined with GCC's __typeof__ */ bool t_bitfield:1; /* - * Either the type is currently an enum (having t_tspec ENUM), or it is - * an integer type (typically INT) that has been implicitly converted - * from an enum type. In both cases, t_enum is valid. - * - * The information about a former enum type is retained to allow type - * checks in expressions such as ((var1 & 0x0001) == var2), to detect - * when var1 and var2 are from incompatible enum types. + * Either the type is currently an enum (having t_tspec ENUM), or it + * is an integer type (typically INT) that has been implicitly + * converted from an enum type. In both cases, t_enum is valid. */ bool t_is_enum:1; bool t_packed:1; @@ -179,7 +157,7 @@ struct lint1_type { #define t_dim t_u._t_dim #define t_sou t_u._t_sou #define t_enum t_u._t_enum -#define t_params t_u._t_params +#define t_params t_u._t_params typedef enum { @@ -189,16 +167,14 @@ typedef enum { SK_LABEL } symbol_kind; -/* - * storage classes and related things - */ +/* storage classes and related things */ typedef enum { NO_SCL, EXTERN, /* external symbols (independent of decl_t) */ STATIC, /* static symbols (local and global) */ AUTO, /* automatic symbols (except register) */ REG, /* register */ - TYPEDEF, /* typedef */ + TYPEDEF, THREAD_LOCAL, STRUCT_TAG, UNION_TAG, @@ -217,9 +193,7 @@ typedef enum { FS_NORETURN, /* since C11 */ } function_specifier; -/* - * symbol table entry - */ +/* A type, variable, keyword; basically anything that has a name. */ struct sym { const char *s_name; const char *s_rename; /* renamed symbol's given name */ @@ -232,26 +206,26 @@ struct sym { symbol_kind s_kind; const struct keyword *s_keyword; bool s_bitfield:1; - bool s_set:1; /* variable set, label defined */ - bool s_used:1; /* variable/label used */ - bool s_param:1; /* symbol is function parameter */ - bool s_register:1; /* symbol is register variable */ + bool s_set:1; + bool s_used:1; + bool s_param:1; + bool s_register:1; bool s_defparam:1; /* undefined symbol in old-style function * definition */ bool s_return_type_implicit_int:1; bool s_osdef:1; /* symbol stems from old-style function def. */ - bool s_inline:1; /* true if this is an inline function */ - struct
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 11:05:05 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lint1.h Log Message: lint: clean up comments, use typedefs To generate a diff of this commit: cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lint1.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:54:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: func.c lint1.h Log Message: lint: internally store case label values in order of appearance To generate a diff of this commit: cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lint1.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:54:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: func.c lint1.h Log Message: lint: internally store case label values in order of appearance To generate a diff of this commit: cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lint1.h 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/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.181 src/usr.bin/xlint/lint1/func.c:1.182 --- src/usr.bin/xlint/lint1/func.c:1.181 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/func.c Sat Mar 9 10:54:12 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $"); #endif #include @@ -162,12 +162,7 @@ end_control_statement(control_statement_ control_statement *cs = cstmt; cstmt = cs->c_surrounding; - case_label_t *cl, *next; - for (cl = cs->c_case_labels; cl != NULL; cl = next) { - next = cl->cl_next; - free(cl); - } - + free(cs->c_case_labels.vals); free(cs->c_switch_type); free(cs); } @@ -436,6 +431,34 @@ check_case_label_enum(const tnode_t *tn, #endif } +static bool +check_duplicate_case_label(control_statement *cs, const val_t *nv) +{ + case_labels *labels = >c_case_labels; + size_t i = 0, n = labels->len; + + while (i < n && labels->vals[i].u.integer != nv->u.integer) + i++; + + if (i < n) { + if (is_uinteger(nv->v_tspec)) + /* duplicate case '%lu' in switch */ + error(200, (unsigned long)nv->u.integer); + else + /* duplicate case '%ld' in switch */ + error(199, (long)nv->u.integer); + return false; + } + + if (labels->len >= labels->cap) { + labels->cap = 16 + 2 * labels->cap; + labels->vals = xrealloc(labels->vals, + sizeof(*labels->vals) * labels->cap); + } + labels->vals[labels->len++] = *nv; + return true; +} + static void check_case_label(tnode_t *tn) { @@ -487,27 +510,8 @@ check_case_label(tnode_t *tn) convert_constant(CASE, 0, cs->c_switch_type, , v); free(v); - /* look if we had this value already */ - case_label_t *cl; - for (cl = cs->c_case_labels; cl != NULL; cl = cl->cl_next) { - if (cl->cl_val.u.integer == nv.u.integer) - break; - } - if (cl != NULL && is_uinteger(nv.v_tspec)) - /* duplicate case '%lu' in switch */ - error(200, (unsigned long)nv.u.integer); - else if (cl != NULL) - /* duplicate case '%ld' in switch */ - error(199, (long)nv.u.integer); - else { + if (check_duplicate_case_label(cs, )) check_getopt_case_label(nv.u.integer); - - /* Prepend the value to the list of case values. */ - cl = xcalloc(1, sizeof(*cl)); - cl->cl_val = nv; - cl->cl_next = cs->c_case_labels; - cs->c_case_labels = cl; - } } void @@ -660,7 +664,6 @@ stmt_switch_expr_stmt(void) { int nenum = 0, nclab = 0; sym_t *esym; - case_label_t *cl; lint_assert(cstmt->c_switch_type != NULL); @@ -675,8 +678,7 @@ stmt_switch_expr_stmt(void) esym != NULL; esym = esym->s_next) { nenum++; } - for (cl = cstmt->c_case_labels; cl != NULL; cl = cl->cl_next) - nclab++; + nclab = (int)cstmt->c_case_labels.len; if (hflag && eflag && nclab < nenum && !cstmt->c_default) /* enumeration value(s) not handled in switch */ warning(206); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.217 src/usr.bin/xlint/lint1/lint1.h:1.218 --- src/usr.bin/xlint/lint1/lint1.h:1.217 Sat Mar 9 10:47:16 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sat Mar 9 10:54:12 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -425,14 +425,12 @@ typedef struct qual_ptr { struct qual_ptr *p_next; } qual_ptr; -/* - * The values of the 'case' labels, linked via cl_next in reverse order of - * appearance in the code, that is from bottom to top. - */ -typedef struct case_label { - val_t cl_val; - struct case_label *cl_next; -} case_label_t; +/* The values of the 'case' labels. */ +typedef struct { + val_t *vals; + size_t len; + size_t cap; +} case_labels; typedef enum { CS_DO_WHILE, @@ -466,7 +464,7 @@ typedef struct control_statement { type_t *c_switch_type; /* type of switch expression */ tnode_t *c_switch_expr; - case_label_t *c_case_labels; /* list of case values */ + case_labels c_case_labels; /* list of case values */ memory_pool c_for_expr3_mem; /* saved memory for end of loop * expression in for() */
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:47:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c lint1.h tree.c Log Message: lint: remove unneeded checks for left and right operands To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.609 -r1.610 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/cksnprintb.c diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.7 src/usr.bin/xlint/lint1/cksnprintb.c:1.8 --- src/usr.bin/xlint/lint1/cksnprintb.c:1.7 Sun Mar 3 16:09:01 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Sat Mar 9 10:47:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $ */ +/* $NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $"); +__RCSID("$NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $"); #endif #include @@ -59,7 +59,7 @@ static bool match_string_literal(const tnode_t *tn, const buffer **str) { while (tn->tn_op == CVT) - tn = tn_ck_left(tn); + tn = tn->tn_left; return tn->tn_op == ADDR && tn->tn_left->tn_op == STRING && (*str = tn->tn_left->tn_string, (*str)->data != NULL); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.216 src/usr.bin/xlint/lint1/lint1.h:1.217 --- src/usr.bin/xlint/lint1/lint1.h:1.216 Sat Mar 9 10:41:11 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sat Mar 9 10:47:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.216 2024/03/09 10:41:11 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -555,20 +555,6 @@ typedef struct { assert_failed(__FILE__, __LINE__, __func__, #cond); \ } while (false) -static inline tnode_t * -tn_ck_left(const tnode_t *tn) -{ - lint_assert(has_operands(tn)); - return tn->tn_left; -} - -static inline tnode_t * -tn_ck_right(const tnode_t *tn) -{ - lint_assert(has_operands(tn)); - return tn->tn_right; -} - #ifdef DEBUG # include "err-msgs.h" Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.609 src/usr.bin/xlint/lint1/tree.c:1.610 --- src/usr.bin/xlint/lint1/tree.c:1.609 Sun Mar 3 16:09:01 2024 +++ src/usr.bin/xlint/lint1/tree.c Sat Mar 9 10:47:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $"); #endif #include @@ -1236,7 +1236,7 @@ build_colon(bool sys, tnode_t *ln, tnode static bool is_cast_redundant(const tnode_t *tn) { - const type_t *ntp = tn->tn_type, *otp = tn_ck_left(tn)->tn_type; + const type_t *ntp = tn->tn_type, *otp = tn->tn_left->tn_type; tspec_t nt = ntp->t_tspec, ot = otp->t_tspec; if (nt == BOOL || ot == BOOL)
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:47:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cksnprintb.c lint1.h tree.c Log Message: lint: remove unneeded checks for left and right operands To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.609 -r1.610 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:41:11 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h lint1.h Log Message: lint: use fewer struct keywords To generate a diff of this commit: cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lint1.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Mar 9 10:41:11 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h lint1.h Log Message: lint: use fewer struct keywords To generate a diff of this commit: cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lint1.h 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.489 src/usr.bin/xlint/lint1/cgram.y:1.490 --- src/usr.bin/xlint/lint1/cgram.y:1.489 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/cgram.y Sat Mar 9 10:41:11 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $"); #endif #include @@ -128,7 +128,7 @@ is_either(const char *s, const char *a, tspec_t y_tspec; type_qualifiers y_type_qualifiers; function_specifier y_function_specifier; - struct parameter_list y_parameter_list; + parameter_list y_parameter_list; function_call *y_arguments; type_t *y_type; tnode_t *y_tnode; @@ -137,7 +137,7 @@ is_either(const char *s, const char *a, qual_ptr *y_qual_ptr; bool y_seen_statement; struct generic_association *y_generic; - struct array_size y_array_size; + array_size y_array_size; bool y_in_system_header; designation y_designation; }; @@ -1421,7 +1421,7 @@ param_list: block_level++; begin_declaration_level(DLK_PROTO_PARAMS); } identifier_list T_RPAREN { - $$ = (struct parameter_list){ .first = $3 }; + $$ = (parameter_list){ .first = $3 }; } | abstract_decl_param_list ; @@ -1541,7 +1541,7 @@ direct_abstract_declarator: abstract_decl_param_list: /* specific to lint */ abstract_decl_lparen T_RPAREN type_attribute_opt { - $$ = (struct parameter_list){ .first = NULL }; + $$ = (parameter_list){ .first = NULL }; } | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { @@ -1549,7 +1549,7 @@ abstract_decl_param_list: /* specific to $$.prototype = true; } | abstract_decl_lparen error T_RPAREN type_attribute_opt { - $$ = (struct parameter_list){ .first = NULL }; + $$ = (parameter_list){ .first = NULL }; } ; @@ -1574,14 +1574,14 @@ vararg_parameter_type_list: /* specific else if (allow_c90) /* C90 to C17 require formal parameter before '...' */ warning(84); - $$ = (struct parameter_list){ .vararg = true }; + $$ = (parameter_list){ .vararg = true }; } ; /* XXX: C99 6.7.5 defines the same name, but it looks different. */ parameter_type_list: parameter_declaration { - $$ = (struct parameter_list){ .first = $1 }; + $$ = (parameter_list){ .first = $1 }; } | parameter_type_list T_COMMA parameter_declaration { $$ = $1; Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.394 src/usr.bin/xlint/lint1/decl.c:1.395 --- src/usr.bin/xlint/lint1/decl.c:1.394 Sat Mar 2 09:32:18 2024 +++ src/usr.bin/xlint/lint1/decl.c Sat Mar 9 10:41:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $"); #endif #include @@ -1334,7 +1334,7 @@ old_style_function(sym_t *decl, sym_t *p } sym_t * -add_function(sym_t *decl, struct parameter_list params) +add_function(sym_t *decl, parameter_list params) { debug_enter(); Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.218 src/usr.bin/xlint/lint1/externs1.h:1.219 --- src/usr.bin/xlint/lint1/externs1.h:1.218 Sun Mar 3 00:50:41 2024 +++ src/usr.bin/xlint/lint1/externs1.h Sat Mar 9 10:41:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.218 2024/03/03 00:50:41 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.219 2024/03/09 10:41:11 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -233,7 +233,7 @@ void add_type_qualifiers(type_qualifiers qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *); sym_t *add_pointer(sym_t *, qual_ptr *); sym_t *add_array(sym_t *, bool, int); -sym_t *add_function(sym_t *, struct parameter_list); +sym_t *add_function(sym_t *, parameter_list); void check_extern_declaration(const sym_t *);
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 21:52:48 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c tree.c Log Message: lint: fix misleading initializer for string iterator The field 'start' marks the start of the previous matching character, not the current iterator position. No binary change. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.606 -r1.607 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/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.23 src/usr.bin/xlint/lint1/ckgetopt.c:1.24 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.23 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/ckgetopt.c Fri Mar 1 21:52:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $"); #endif #include @@ -105,7 +105,7 @@ is_getopt_condition(const tnode_t *tn, c && (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) { buffer buf; buf_init(); - quoted_iterator it = { .start = 0 }; + quoted_iterator it = { .i = 0 }; while (quoted_next(str, )) buf_add_char(, (char)it.value); *out_options = buf.data; Index: src/usr.bin/xlint/lint1/cksnprintb.c diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.1 src/usr.bin/xlint/lint1/cksnprintb.c:1.2 --- src/usr.bin/xlint/lint1/cksnprintb.c:1.1 Fri Mar 1 19:40:45 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Fri Mar 1 21:52:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $ */ +/* $NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $"); +__RCSID("$NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $"); #endif #include @@ -266,7 +266,7 @@ check_snprintb(const tnode_t *expr) if (!match_snprintb_call(expr->tn_call, , )) return; - quoted_iterator it = { .start = 0 }; + quoted_iterator it = { .i = 0 }; if (!quoted_next(fmt, )) { /* missing new-style '\177' or old-style number base */ warning(359); Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.87 src/usr.bin/xlint/lint1/emit1.c:1.88 --- src/usr.bin/xlint/lint1/emit1.c:1.87 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/emit1.c Fri Mar 1 21:52:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $"); #endif #include @@ -362,7 +362,7 @@ outcall(const tnode_t *tn, bool retval_u arg->tn_left->tn_string->data != NULL) { buffer buf; buf_init(); - quoted_iterator it = { .start = 0 }; + quoted_iterator it = { .i = 0 }; while (quoted_next(arg->tn_left->tn_string, )) buf_add_char(, (char)it.value); Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.259 src/usr.bin/xlint/lint1/init.c:1.260 --- src/usr.bin/xlint/lint1/init.c:1.259 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/init.c Fri Mar 1 21:52:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $"); #endif #include @@ -886,7 +886,7 @@ initialization_init_array_from_string(in size_t len = tn->tn_string->len; if (tn->tn_string->data != NULL) { - quoted_iterator it = { .start = 0 }; + quoted_iterator it = { .i = 0 }; for (len = 0; quoted_next(tn->tn_string, ); len++) continue; } Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.219 src/usr.bin/xlint/lint1/lex.c:1.220 ---
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 21:52:48 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c tree.c Log Message: lint: fix misleading initializer for string iterator The field 'start' marks the start of the previous matching character, not the current iterator position. No binary change. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.606 -r1.607 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 19:40:45 UTC 2024 Added Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: test format strings from snprintb calls The functions snprintb and snprintb_m are specific to NetBSD, and their format strings are tricky to get correct. Provide some assistance in catching the most common mistakes. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/cksnprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/usr.bin/xlint/lint1/cksnprintb.c diff -u /dev/null src/usr.bin/xlint/lint1/cksnprintb.c:1.1 --- /dev/null Fri Mar 1 19:40:45 2024 +++ src/usr.bin/xlint/lint1/cksnprintb.c Fri Mar 1 19:40:45 2024 @@ -0,0 +1,290 @@ +/* $NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $ */ + +/*- + * Copyright (c) 2024 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Roland Illig . + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + +#include +#if defined(__RCSID) +__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $"); +#endif + +#include +#include + +#include "lint1.h" + +static bool +match_string_literal(const tnode_t *tn, const buffer **str) +{ + while (tn->tn_op == CVT) + tn = tn_ck_left(tn); + return tn->tn_op == ADDR + && tn->tn_left->tn_op == STRING + && (*str = tn->tn_left->tn_string, (*str)->data != NULL); +} + +static bool +match_snprintb_call(const function_call *call, +const buffer **out_fmt, const tnode_t **out_val) +{ + const char *func; + const tnode_t *val; + const buffer *str; + + if (call->func->tn_op == ADDR + && call->func->tn_left->tn_op == NAME + && (func = call->func->tn_left->tn_sym->s_name, true) + && ((strcmp(func, "snprintb") == 0 && call->args_len == 4) + || (strcmp(func, "snprintb_m") == 0 && call->args_len == 5)) + && match_string_literal(call->args[2], ) + && (val = call->args[3], true)) { + *out_fmt = str; + *out_val = val; + return true; + } + return false; +} + +static int +len(quoted_iterator it) +{ + return (int)(it.i - it.start); +} + +static int +range(quoted_iterator start, quoted_iterator end) +{ + return (int)(end.i - start.start); +} + +static const char * +start(quoted_iterator it, const buffer *buf) +{ + return buf->data + it.start; +} + +static uintmax_t +val(quoted_iterator it) +{ + return it.value; +} + +static void +check_hex_escape(const buffer *buf, quoted_iterator it) +{ + if (it.hex_digits > 1) { + bool upper = false; + bool lower = false; + for (size_t i = it.start + 2; i < it.i; i++) { + if (isupper((unsigned char)buf->data[i])) +upper = true; + if (islower((unsigned char)buf->data[i])) +lower = true; + } + if (upper && lower) + /* hex escape '%.*s' mixes uppercase and lower... */ + warning(357, len(it), start(it, buf)); + } + if (it.hex_digits > 2) + /* hex escape '%.*s' has more than 2 digits */ + warning(358, len(it), start(it, buf)); +} + +static bool +check_directive(const buffer *fmt, quoted_iterator *it, bool new_style, + uint64_t *prev_field_width) +{ + + if (!quoted_next(fmt, it)) + return false; + quoted_iterator dir = *it; + + bool has_bit = !new_style + || dir.value == 'b' || dir.value == 'f' || dir.value == 'F'; + if (has_bit && new_style && !quoted_next(fmt, it)) { + /* missing bit position after '%.*s' */ + warning(364, len(dir), start(dir, fmt)); + return false; + } + /* LINTED 86 "automatic 'bit' hides external declaration" */ +
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 19:40:45 UTC 2024 Added Files: src/usr.bin/xlint/lint1: cksnprintb.c Log Message: lint: test format strings from snprintb calls The functions snprintb and snprintb_m are specific to NetBSD, and their format strings are tricky to get correct. Provide some assistance in catching the most common mistakes. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/cksnprintb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 17:14:34 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: fix type error in strict bool mode (since yesterday) To generate a diff of this commit: cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Mar 1 17:14:34 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: fix type error in strict bool mode (since yesterday) To generate a diff of this commit: cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.218 src/usr.bin/xlint/lint1/lex.c:1.219 --- src/usr.bin/xlint/lint1/lex.c:1.218 Thu Feb 29 21:37:10 2024 +++ src/usr.bin/xlint/lint1/lex.c Fri Mar 1 17:14:34 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 rillig Exp $"); #endif #include @@ -597,7 +597,7 @@ lex_integer_constant(const char *yytext, bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0 && is_unsigned_since_c90(l_suffix, ui, base); - tspec_t t = u_suffix + tspec_t t = u_suffix > 0 ? integer_constant_type_unsigned(l_suffix, ui, warned) : integer_constant_type_signed(l_suffix, ui, base, warned); ui = (uint64_t)convert_integer((int64_t)ui, t, 0);
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 29 21:37:10 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint1: remove redundant type table for integer constant suffixes To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.217 src/usr.bin/xlint/lint1/lex.c:1.218 --- src/usr.bin/xlint/lint1/lex.c:1.217 Thu Feb 8 20:59:19 2024 +++ src/usr.bin/xlint/lint1/lex.c Thu Feb 29 21:37:10 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $"); #endif #include @@ -481,84 +481,72 @@ lex_name(const char *yytext, size_t yyle // Determines whether the constant is signed in traditional C but unsigned in // C90 and later. static bool -is_unsigned_since_c90(tspec_t t, uint64_t ui, int base) +is_unsigned_since_c90(unsigned ls, uint64_t ui, int base) { - if (!(allow_trad && allow_c90)) + if (ui <= TARG_INT_MAX) return false; - if (t == INT) { - if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10) - return true; - return ui > TARG_LONG_MAX; - } - return t == LONG && ui > TARG_LONG_MAX; + if (ls == 0 && ui <= TARG_UINT_MAX && base != 10) + return true; + return ls <= 1 && ui > TARG_LONG_MAX; } static tspec_t -integer_constant_type(tspec_t t, uint64_t ui, int base, bool warned) +integer_constant_type_signed(unsigned ls, uint64_t ui, int base, bool warned) { - switch (t) { - case INT: - if (ui <= TARG_INT_MAX) - return INT; - if (ui <= TARG_UINT_MAX && base != 10 && allow_c90) - return UINT; - if (ui <= TARG_LONG_MAX) - return LONG; - /* FALLTHROUGH */ - case LONG: - if (ui <= TARG_LONG_MAX) - return LONG; - if (ui <= TARG_ULONG_MAX && base != 10) - return allow_c90 ? ULONG : LONG; - if (!allow_c99) { - if (!warned) -/* integer constant out of range */ -warning(252); - return allow_c90 ? ULONG : LONG; - } - /* FALLTHROUGH */ - case LLONG: - if (ui <= TARG_LLONG_MAX) - return LLONG; - if (ui <= TARG_ULLONG_MAX && base != 10) - return allow_c90 ? ULLONG : LLONG; + if (ls == 0 && ui <= TARG_INT_MAX) + return INT; + if (ls == 0 && ui <= TARG_UINT_MAX && base != 10 && allow_c90) + return UINT; + if (ls == 0 && ui <= TARG_LONG_MAX) + return LONG; + + if (ls <= 1 && ui <= TARG_LONG_MAX) + return LONG; + if (ls <= 1 && ui <= TARG_ULONG_MAX && base != 10) + return allow_c90 ? ULONG : LONG; + if (ls <= 1 && !allow_c99) { if (!warned) /* integer constant out of range */ warning(252); + return allow_c90 ? ULONG : LONG; + } + + if (ui <= TARG_LLONG_MAX) + return LLONG; + if (ui <= TARG_ULLONG_MAX && base != 10) return allow_c90 ? ULLONG : LLONG; - case UINT: - if (ui <= TARG_UINT_MAX) - return UINT; - /* FALLTHROUGH */ - case ULONG: - if (ui <= TARG_ULONG_MAX) - return ULONG; - if (!allow_c99) { - if (!warned) -/* integer constant out of range */ -warning(252); - return ULONG; - } - /* FALLTHROUGH */ - default: - if (ui <= TARG_ULLONG_MAX) - return ULLONG; + if (!warned) + /* integer constant out of range */ + warning(252); + return allow_c90 ? ULLONG : LLONG; +} + +static tspec_t +integer_constant_type_unsigned(unsigned l, uint64_t ui, bool warned) +{ + if (l == 0 && ui <= TARG_UINT_MAX) + return UINT; + + if (l <= 1 && ui <= TARG_ULONG_MAX) + return ULONG; + if (l <= 1 && !allow_c99) { if (!warned) /* integer constant out of range */ warning(252); - return ULLONG; + return ULONG; } + + if (ui <= TARG_ULLONG_MAX) + return ULLONG; + if (!warned) + /* integer constant out of range */ + warning(252); + return ULLONG; } int lex_integer_constant(const char *yytext, size_t yyleng, int base) { - /* C11 6.4.4.1p5 */ - static const tspec_t suffix_type[2][3] = { - { INT, LONG, LLONG, }, - { UINT, ULONG, ULLONG, } - }; - const char *cp = yytext; size_t len = yyleng; @@ -590,7 +578,6 @@ lex_integer_constant(const char *yytext, if (!allow_c90 && u_suffix > 0) /* suffix 'U' is illegal in traditional C */ warning(97); - tspec_t ct = suffix_type[u_suffix][l_suffix]; bool warned = false; errno = 0; @@ -607,14 +594,17 @@ lex_integer_constant(const char *yytext, /* octal number '%.*s' */ query_message(8, (int)len, cp); - bool ansiu = is_unsigned_since_c90(ct, ui, base); + bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0 + && is_unsigned_since_c90(l_suffix, ui, base); - tspec_t t = integer_constant_type(ct, ui, base,
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 29 21:37:10 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint1: remove redundant type table for integer constant suffixes To generate a diff of this commit: cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 20:59:20 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c lex.c tree.c Log Message: lint: clean up variable names, parameter order, comments No functional change. To generate a diff of this commit: cvs rdiff -u -r1.392 -r1.393 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.604 -r1.605 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.392 src/usr.bin/xlint/lint1/decl.c:1.393 --- src/usr.bin/xlint/lint1/decl.c:1.392 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/decl.c Thu Feb 8 20:59:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.392 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.392 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $"); #endif #include @@ -1341,8 +1341,8 @@ add_function(sym_t *decl, struct paramet debug_dcs_all(); debug_sym("decl: ", decl, "\n"); #ifdef DEBUG - for (const sym_t *arg = params.first; arg != NULL; arg = arg->s_next) - debug_sym("arg: ", arg, "\n"); + for (const sym_t *p = params.first; p != NULL; p = p->s_next) + debug_sym("param: ", p, "\n"); #endif if (params.prototype) { Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.216 src/usr.bin/xlint/lint1/lex.c:1.217 --- src/usr.bin/xlint/lint1/lex.c:1.216 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/lex.c Thu Feb 8 20:59:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.216 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.216 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $"); #endif #include @@ -705,7 +705,7 @@ lex_operator(int t, op_t o) } static buffer * -read_quoted(bool *complete, bool wide, char delim) +read_quoted(bool *complete, char delim, bool wide) { buffer *buf = xcalloc(1, sizeof(*buf)); buf_init(buf); @@ -947,7 +947,7 @@ static buffer * lex_quoted(char delim, bool wide) { bool complete; - buffer *buf = read_quoted(, wide, delim); + buffer *buf = read_quoted(, delim, wide); check_quoted(buf, complete, delim); return buf; } Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.604 src/usr.bin/xlint/lint1/tree.c:1.605 --- src/usr.bin/xlint/lint1/tree.c:1.604 Thu Feb 8 20:45:20 2024 +++ src/usr.bin/xlint/lint1/tree.c Thu Feb 8 20:59:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.605 2024/02/08 20:59:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.605 2024/02/08 20:59:19 rillig Exp $"); #endif #include @@ -321,9 +321,8 @@ ic_expr(const tnode_t *tn) type_t * block_derive_type(type_t *tp, tspec_t t) { - type_t *tp2; - tp2 = block_zero_alloc(sizeof(*tp2), "type"); + type_t *tp2 = block_zero_alloc(sizeof(*tp2), "type"); tp2->t_tspec = t; tp2->t_subt = tp; return tp2; @@ -336,9 +335,8 @@ block_derive_type(type_t *tp, tspec_t t) type_t * expr_derive_type(type_t *tp, tspec_t t) { - type_t *tp2; - tp2 = expr_zero_alloc(sizeof(*tp2), "type"); + type_t *tp2 = expr_zero_alloc(sizeof(*tp2), "type"); tp2->t_tspec = t; tp2->t_subt = tp; return tp2; @@ -3806,55 +3804,48 @@ convert_constant_check_range(tspec_t ot, warn_constant_check_range_loss(op, arg, tp, ot); } -/*- - * Converts a typed constant to a constant of another type. - * - * op operator which requires conversion - * arg if op is FARG, # of parameter - * tp type to which to convert the constant - * nv new constant - * v old constant - */ +/* Converts a typed constant to a constant of another type. */ void -convert_constant(op_t op, int arg, const type_t *tp, val_t *nv, val_t *v) +convert_constant(op_t op, int arg, const type_t *ntp, val_t *nv, val_t *ov) { /* - * TODO: make 'v' const; the name of this function does not suggest - * that it modifies 'v'. + * TODO: make 'ov' const; the name of this function does not suggest + * that it modifies 'ov'. */ - tspec_t ot = v->v_tspec; - tspec_t nt = nv->v_tspec = tp->t_tspec; + tspec_t ot = ov->v_tspec; + tspec_t nt = nv->v_tspec = ntp->t_tspec; bool range_check = false; if (nt == BOOL)
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 20:59:20 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c lex.c tree.c Log Message: lint: clean up variable names, parameter order, comments No functional change. To generate a diff of this commit: cvs rdiff -u -r1.392 -r1.393 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.604 -r1.605 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 20:45:20 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c func.c init.c lex.c tree.c Log Message: lint: clean up redundant braces No functional change. To generate a diff of this commit: cvs rdiff -u -r1.488 -r1.489 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.391 -r1.392 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.180 -r1.181 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.258 -r1.259 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.603 -r1.604 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 20:45:20 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c func.c init.c lex.c tree.c Log Message: lint: clean up redundant braces No functional change. To generate a diff of this commit: cvs rdiff -u -r1.488 -r1.489 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.391 -r1.392 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.180 -r1.181 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.258 -r1.259 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.603 -r1.604 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.488 src/usr.bin/xlint/lint1/cgram.y:1.489 --- src/usr.bin/xlint/lint1/cgram.y:1.488 Thu Feb 8 19:32:12 2024 +++ src/usr.bin/xlint/lint1/cgram.y Thu Feb 8 20:45:20 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $"); #endif #include @@ -431,13 +431,12 @@ is_either(const char *s, const char *a, program: /* empty */ { /* TODO: Make this an error in C99 mode as well. */ - if (!allow_trad && !allow_c99) { + if (!allow_trad && !allow_c99) /* empty translation unit */ error(272); - } else if (allow_c90) { + else if (allow_c90) /* empty translation unit */ warning(272); - } } | translation_unit ; @@ -464,10 +463,9 @@ identifier: string: T_STRING | string T_STRING { - if (!allow_c90) { + if (!allow_c90) /* concatenated strings are illegal in traditional C */ warning(219); - } $$ = cat_strings($1, $2); } ; @@ -670,10 +668,9 @@ unary_expression: $$ = build_unary(INDIR, $2, $3); } | T_ADDITIVE sys cast_expression { - if (!allow_c90 && $1 == PLUS) { + if (!allow_c90 && $1 == PLUS) /* unary '+' is illegal in traditional C */ warning(100); - } $$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2, $3); } | T_COMPLEMENT sys cast_expression { @@ -815,31 +812,28 @@ declaration_or_error: /* K ???, C90 ???, C99 6.7, C11 ???, C23 6.7 */ declaration: begin_type_declmods end_type T_SEMI { - if (dcs->d_scl == TYPEDEF) { + if (dcs->d_scl == TYPEDEF) /* typedef declares no type name */ warning(72); - } else { + else /* empty declaration */ warning(2); - } } | begin_type_declmods end_type notype_init_declarators T_SEMI { - if (dcs->d_scl == TYPEDEF) { + if (dcs->d_scl == TYPEDEF) /* syntax error '%s' */ error(249, "missing base type for typedef"); - } else { + else /* old-style declaration; add 'int' */ error(1); - } } | begin_type_declaration_specifiers end_type T_SEMI { - if (dcs->d_scl == TYPEDEF) { + if (dcs->d_scl == TYPEDEF) /* typedef declares no type name */ warning(72); - } else if (!dcs->d_nonempty_decl) { + else if (!dcs->d_nonempty_decl) /* empty declaration */ warning(2); - } } | begin_type_declaration_specifiers end_type type_init_declarators T_SEMI @@ -1196,13 +1190,12 @@ enum_declaration: /* helper for C99 6.7 enums_with_opt_comma: /* helper for C99 6.7.2.2 */ enumerator_list | enumerator_list T_COMMA { - if (!allow_c99 && !allow_trad) { + if (!allow_c99 && !allow_trad) /* trailing ',' in enum declaration requires C99 ... */ error(54); - } else { + else /* trailing ',' in enum declaration requires C99 ... */ c99ism(54); - } $$ = $1; } ; @@ -1575,13 +1568,12 @@ vararg_parameter_type_list: /* specific } | T_ELLIPSIS { /* TODO: C99 6.7.5 makes this an error as well. */ - if (!allow_trad && !allow_c99) { + if (!allow_trad && !allow_c99) /* C90 to C17 require formal parameter before '...' */ error(84); - } else if (allow_c90) { + else if (allow_c90) /* C90 to C17 require formal parameter before '...' */ warning(84); - } $$ = (struct parameter_list){ .vararg = true }; } ; @@ -2042,13 +2034,12 @@ external_declaration: /* C99 6.9 */ * TODO: Only allow this in GCC mode, not in plain C99. * This is one of the top 10 warnings in the NetBSD build. */ - if (!allow_trad && !allow_c99) { + if (!allow_trad && !allow_c99) /* empty declaration */ error(0); - } else if (allow_c90) { + else if (allow_c90) /* empty declaration */ warning(0); - } } ; @@ -2064,13 +2055,12 @@ external_declaration: /* C99 6.9 */ top_level_declaration: /* C99 6.9 calls this 'declaration' */ begin_type
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 19:32:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: clean up comments, add debug output for Bison To generate a diff of this commit: cvs rdiff -u -r1.487 -r1.488 src/usr.bin/xlint/lint1/cgram.y 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.487 src/usr.bin/xlint/lint1/cgram.y:1.488 --- src/usr.bin/xlint/lint1/cgram.y:1.487 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/cgram.y Thu Feb 8 19:32:12 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.487 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.487 2024/02/05 23:11:22 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $"); #endif #include @@ -85,18 +85,6 @@ clear_warning_flags_loc(const char *file static void save_warning_flags_loc(const char *file, size_t line) { - /* - * There used to be an assertion that saved_lwarn is - * LWARN_NOTHING_SAVED here, but that triggered for the following - * code: - * - * void function(int x) { if (x > 0) if (x > 1) return; } - * - * It didn't trigger if the inner 'if' was enclosed in braces though. - * - * TODO: If actually needed, add support for nested suppression of - * warnings. - */ debug_step("%s:%zu: saving flags %d", file, line, lwarn); saved_lwarn = lwarn; } @@ -108,10 +96,6 @@ restore_warning_flags_loc(const char *fi if (saved_lwarn != LWARN_NOTHING_SAVED) { lwarn = saved_lwarn; debug_step("%s:%zu: restoring flags %d", file, line, lwarn); - /* - * Do not set 'saved_lwarn = LWARN_NOTHING_SAVED' here, to - * avoid triggering the assertion in save_warning_flags_loc. - */ } else clear_warning_flags_loc(file, line); } @@ -179,6 +163,12 @@ is_either(const char *s, const char *a, %printer { fprintf(yyo, "%s", function_specifier_name($$)); } +%printer { + size_t n = 0; + for (const sym_t *p = $$.first; p != NULL; p = p->s_next) + n++; + fprintf(yyo, "%zu parameter%s", n, n != 1 ? "s" : ""); +} %printer { fprintf(yyo, "%s", type_name($$)); } %printer { if ($$ == NULL) @@ -196,6 +186,19 @@ is_either(const char *s, const char *a, %printer { fprintf(yyo, "%s", type_name($$->ga_arg)); } %printer { fprintf(yyo, "%d", $$.dim); } %printer { fprintf(yyo, "%s", $$ ? "yes" : "no"); } +%printer { + if ($$.dn_len == 0) + fprintf(yyo, "(empty)"); + for (size_t i = 0; i < $$.dn_len; i++) { + const designator *dr = $$.dn_items + i; + if (dr->dr_kind == DK_MEMBER) + fprintf(yyo, ".%s", dr->dr_member->s_name); + else if (dr->dr_kind == DK_SUBSCRIPT) + fprintf(yyo, "[%zu]", dr->dr_subscript); + else + fprintf(yyo, ""); + } +} */ %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN @@ -1042,7 +1045,7 @@ braced_member_declaration_list: /* see C member_declaration_list_with_rbrace: /* see C99 6.7.2.1 */ member_declaration_list T_RBRACE | T_RBRACE { - /* XXX: This is not allowed by any C standard. */ + /* XXX: Allowed since C23. */ $$ = NULL; } ;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Feb 8 19:32:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: clean up comments, add debug output for Bison To generate a diff of this commit: cvs rdiff -u -r1.487 -r1.488 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Feb 7 08:00:37 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: use consistent variable names, reduce code for reading a byte No functional change. To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.214 src/usr.bin/xlint/lint1/lex.c:1.215 --- src/usr.bin/xlint/lint1/lex.c:1.214 Wed Feb 7 07:42:50 2024 +++ src/usr.bin/xlint/lint1/lex.c Wed Feb 7 08:00:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.214 2024/02/07 07:42:50 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.214 2024/02/07 07:42:50 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 rillig Exp $"); #endif #include @@ -423,15 +423,11 @@ init_lex(void) static int read_byte(void) { - int c; + int c = lex_input(); - if ((c = lex_input()) == EOF) - return c; - if (c == '\0') - return EOF; /* lex returns 0 on EOF. */ if (c == '\n') lex_next_line(); - return c; + return c == '\0' ? EOF : c; /* lex returns 0 on EOF. */ } static int @@ -485,16 +481,16 @@ lex_name(const char *yytext, size_t yyle // Determines whether the constant is signed in traditional C but unsigned in // C90 and later. static bool -is_unsigned_since_c90(tspec_t typ, uint64_t ui, int base) +is_unsigned_since_c90(tspec_t t, uint64_t ui, int base) { if (!(allow_trad && allow_c90)) return false; - if (typ == INT) { + if (t == INT) { if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10) return true; return ui > TARG_LONG_MAX; } - return typ == LONG && ui > TARG_LONG_MAX; + return t == LONG && ui > TARG_LONG_MAX; } static tspec_t @@ -657,17 +653,17 @@ lex_floating_constant(const char *yytext len--; char c = cp[len - 1]; - tspec_t typ; + tspec_t t; if (c == 'f' || c == 'F') { - typ = imaginary ? FCOMPLEX : FLOAT; + t = imaginary ? FCOMPLEX : FLOAT; len--; } else if (c == 'l' || c == 'L') { - typ = imaginary ? LCOMPLEX : LDOUBLE; + t = imaginary ? LCOMPLEX : LDOUBLE; len--; } else - typ = imaginary ? DCOMPLEX : DOUBLE; + t = imaginary ? DCOMPLEX : DOUBLE; - if (!allow_c90 && typ != DOUBLE) { + if (!allow_c90 && t != DOUBLE) { /* suffixes 'F' and 'L' are illegal in traditional C */ warning(98); } @@ -679,14 +675,14 @@ lex_floating_constant(const char *yytext if (errno != 0) { /* floating-point constant out of range */ warning(248); - } else if (typ == FLOAT) { + } else if (t == FLOAT) { ld = (float)ld; if (isfinite(ld) == 0) { /* floating-point constant out of range */ warning(248); ld = ld > 0 ? FLT_MAX : -FLT_MAX; } - } else if (typ == DOUBLE + } else if (t == DOUBLE || /* CONSTCOND */ LDOUBLE_SIZE == DOUBLE_SIZE) { ld = (double)ld; if (isfinite(ld) == 0) { @@ -697,7 +693,7 @@ lex_floating_constant(const char *yytext } yylval.y_val = xcalloc(1, sizeof(*yylval.y_val)); - yylval.y_val->v_tspec = typ; + yylval.y_val->v_tspec = t; yylval.y_val->u.floating = ld; return T_CON;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Wed Feb 7 08:00:37 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: use consistent variable names, reduce code for reading a byte No functional change. To generate a diff of this commit: cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Feb 6 22:47:21 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: Makefile check-msgs.lua err.c makeman Log Message: lint: tab-align message numbers in err.c By replacing block comments with end-of-line comments, the comments take up less space and thus no longer require to be indented by 6 spaces. The messages and their comments are used in 3 places: the manual page lint.7, the err-msgs.h header for debug mode, and check-msgs.lua to verify that the comments above the message IDs correspond to the actual messages. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/check-msgs.lua cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/makeman 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/Makefile diff -u src/usr.bin/xlint/lint1/Makefile:1.102 src/usr.bin/xlint/lint1/Makefile:1.103 --- src/usr.bin/xlint/lint1/Makefile:1.102 Sat Jul 29 10:45:00 2023 +++ src/usr.bin/xlint/lint1/Makefile Tue Feb 6 22:47:21 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.102 2023/07/29 10:45:00 rillig Exp $ +# $NetBSD: Makefile,v 1.103 2024/02/06 22:47:21 rillig Exp $ .include @@ -78,7 +78,7 @@ DPADD+= ${LIBL} err-msgs.h: err.c ${_MKTARGET_CREATE} sp='[[:space:]]*'; \ - from="^$$sp\(\"[^\"].*\"\)\,$$sp/\*$$sp\(Q*[0-9][0-9]*\)$$sp\*/\$$"; \ + from="^$$sp\(\"[^\"].*\"\)\,$$sp// \(Q*[0-9][0-9]*\)\$$"; \ ${TOOL_SED} -n -e "s,$$from,#define MSG_\2 \1,p" < ${.ALLSRC:M*err.c} > ${.TARGET}.tmp mv -f ${.TARGET}.tmp ${.TARGET} Index: src/usr.bin/xlint/lint1/check-msgs.lua diff -u src/usr.bin/xlint/lint1/check-msgs.lua:1.20 src/usr.bin/xlint/lint1/check-msgs.lua:1.21 --- src/usr.bin/xlint/lint1/check-msgs.lua:1.20 Sat Aug 12 18:05:51 2023 +++ src/usr.bin/xlint/lint1/check-msgs.lua Tue Feb 6 22:47:21 2024 @@ -1,5 +1,5 @@ #! /usr/bin/lua --- $NetBSD: check-msgs.lua,v 1.20 2023/08/12 18:05:51 rillig Exp $ +-- $NetBSD: check-msgs.lua,v 1.21 2024/02/06 22:47:21 rillig Exp $ --[[ @@ -16,7 +16,7 @@ local function load_messages() local f = assert(io.open("err.c")) for line in f:lines() do -local msg, id = line:match("%s*\"(.+)\",%s*/%*%s*(Q?%d+)%s*%*/$") +local msg, id = line:match("%s*\"(.+)\",%s*// (Q?%d+)$") if msg ~= nil then msgs[id] = msg end Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.224 src/usr.bin/xlint/lint1/err.c:1.225 --- src/usr.bin/xlint/lint1/err.c:1.224 Sat Feb 3 20:10:10 2024 +++ src/usr.bin/xlint/lint1/err.c Tue Feb 6 22:47:21 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.224 2024/02/03 20:10:10 rillig Exp $ */ +/* $NetBSD: err.c,v 1.225 2024/02/06 22:47:21 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.224 2024/02/03 20:10:10 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.225 2024/02/06 22:47:21 rillig Exp $"); #endif #include @@ -55,363 +55,363 @@ int sytxerr; static const char *const msgs[] = { - "empty declaration", /* 0 */ - "old-style declaration; add 'int'", /* 1 */ - "empty declaration", /* 2 */ - "'%s' declared in parameter declaration list", /* 3 */ - "illegal type combination", /* 4 */ - "modifying typedef with '%s'; only qualifiers allowed", /* 5 */ - "use 'double' instead of 'long float'", /* 6 */ - "only one storage class allowed", /* 7 */ - "illegal storage class", /* 8 */ - "only 'register' is valid as storage class in parameter", /* 9 */ - "duplicate '%s'", /* 10 */ - "bit-field initializer out of range", /* 11 */ - "compiler takes size of function", /* 12 */ - "incomplete enum type '%s'", /* 13 */ - "", /* 14 */ - "function returns illegal type '%s'", /* 15 */ - "array of function is illegal", /* 16 */ - "null dimension", /* 17 */ - "illegal use of 'void'", /* 18 */ - "void type for '%s'", /* 19 */ - "negative array dimension (%d)", /* 20 */ - "redeclaration of formal parameter '%s'", /* 21 */ - "incomplete or misplaced function definition", /* 22 */ - "undefined label '%s'", /* 23 */ - "cannot initialize function '%s'", /* 24 */ - "cannot initialize typedef '%s'", /* 25 */ - "cannot initialize extern declaration '%s'", /* 26 */ - "redeclaration of '%s'", /* 27 */ - "redefinition of '%s'", /* 28 */ - "'%s' was previously declared extern, becomes static", /* 29 */ - "redeclaration of '%s'; C90 or later require static", /* 30 */ - "'%s' has incomplete type '%s'", /* 31 */ - "type of parameter '%s'
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Feb 6 22:47:21 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: Makefile check-msgs.lua err.c makeman Log Message: lint: tab-align message numbers in err.c By replacing block comments with end-of-line comments, the comments take up less space and thus no longer require to be indented by 6 spaces. The messages and their comments are used in 3 places: the manual page lint.7, the err-msgs.h header for debug mode, and check-msgs.lua to verify that the comments above the message IDs correspond to the actual messages. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/check-msgs.lua cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/makeman Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Feb 6 21:28:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: makeman Log Message: lint.7: remove implementation details from message list >From a user's perspective, it's irrelevant whether a lint message is generated using '%s' or '%.*s'; same for the integer widths, as they are platform-dependent. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/makeman 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/makeman diff -u src/usr.bin/xlint/lint1/makeman:1.7 src/usr.bin/xlint/lint1/makeman:1.8 --- src/usr.bin/xlint/lint1/makeman:1.7 Fri Jul 21 15:00:32 2023 +++ src/usr.bin/xlint/lint1/makeman Tue Feb 6 21:28:15 2024 @@ -1,5 +1,5 @@ #!/bin/sh -# $NetBSD: makeman,v 1.7 2023/07/21 15:00:32 lukem Exp $ +# $NetBSD: makeman,v 1.8 2024/02/06 21:28:15 rillig Exp $ # # Copyright (c) 2000 The NetBSD Foundation, Inc. # All rights reserved. @@ -38,6 +38,10 @@ list_messages() { -e 's|^'"$tab"'"",.*/\* '"$2"'[0-9]+ \*/$|---'"$tab"'(no longer used)|p' \ "$1" \ | ${SED} -E \ + -e 's,%ld,%d,g' \ + -e 's,%lu,%u,g' \ + -e 's,%llu,%u,g' \ + -e 's|%.\*s|%s|g' \ -e 's|\\"|"|g' \ -e 's||\\e|g' \ -e "s|'|\\'|g" \ @@ -45,7 +49,7 @@ list_messages() { } # shellcheck disable=SC2016 -cvsid='$NetBSD: makeman,v 1.7 2023/07/21 15:00:32 lukem Exp $' +cvsid='$NetBSD: makeman,v 1.8 2024/02/06 21:28:15 rillig Exp $' date="$1" year="${date##* }" messages="$(list_messages "$2" "")"
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Feb 6 21:28:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: makeman Log Message: lint.7: remove implementation details from message list >From a user's perspective, it's irrelevant whether a lint message is generated using '%s' or '%.*s'; same for the integer widths, as they are platform-dependent. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/makeman Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Feb 5 23:11:23 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md cgram.y ckctype.c ckgetopt.c debug.c emit1.c externs1.h lint1.h op.h oper.c tree.c Log Message: lint: make function call arguments directly accessible Previously, the arguments of a function call expression were arranged in a linear tree structure, from right to left. To allow easier access to the arguments, store them in an array instead. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/README.md \ src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.486 -r1.487 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.602 -r1.603 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/README.md diff -u src/usr.bin/xlint/lint1/README.md:1.14 src/usr.bin/xlint/lint1/README.md:1.15 --- src/usr.bin/xlint/lint1/README.md:1.14 Thu Sep 14 21:08:12 2023 +++ src/usr.bin/xlint/lint1/README.md Mon Feb 5 23:11:22 2024 @@ -1,4 +1,4 @@ -[//]: # ($NetBSD: README.md,v 1.14 2023/09/14 21:08:12 rillig Exp $) +[//]: # ($NetBSD: README.md,v 1.15 2024/02/05 23:11:22 rillig Exp $) # Introduction @@ -123,34 +123,31 @@ structure: ~~~text 1: 'call' type 'int' - 2: '&' type 'pointer to function(pointer to const char, pointer to const char) returning int' - 3:'name' 'strcmp' with extern 'function(pointer to const char, pointer to const char) returning int' - 4: 'push' type 'pointer to const char' - 5:'convert' type 'pointer to const char' - 6: '&' type 'pointer to char' - 7:'string' type 'array[5] of char', lvalue, length 4, "name" - 8:'push' type 'pointer to const char' - 9: 'load' type 'pointer to const char' -10:'*' type 'pointer to const char', lvalue -11: '+' type 'pointer to pointer to const char' -12:'load' type 'pointer to pointer to const char' -13: 'name' 'names' with auto 'pointer to pointer to const char', lvalue -14:'*' type 'long' -15: 'convert' type 'long' -16:'load' type 'int' -17: 'name' 'i' with auto 'int', lvalue -18: 'constant' type 'long', value 8 + 2: '&' type 'pointer to function(pointer to const char, pointer to const char) returning int' + 3: 'name' 'strcmp' with extern 'function(pointer to const char, pointer to const char) returning int' + 4: 'load' type 'pointer to const char' + 5: '*' type 'pointer to const char', lvalue + 6: '+' type 'pointer to pointer to const char' + 7: 'load' type 'pointer to pointer to const char' + 8: 'name' 'names' with auto 'pointer to pointer to const char', lvalue + 9: '*' type 'long' +10: 'convert' type 'long' +11: 'load' type 'int' +12: 'name' 'i' with auto 'int', lvalue +13: 'constant' type 'long', value 8 +14: 'convert' type 'pointer to const char' +15: '&' type 'pointer to char' +16: 'string' type 'array[5] of char', lvalue, "name" ~~~ -| Lines | Notes| -||--| -| 4, 8 | Each argument of the function call corresponds to a `PUSH` node. | -| 5, 9 | The left operand of a `PUSH` node is the actual argument.| -| 8 | The right operand is the `PUSH` node of the previous argument. | -| 5, 9 | The arguments of a call are ordered from right to left. | -| 10, 11 | Array access is represented as `*(left + right)`.| -| 14, 18 | Array and struct offsets are in premultiplied form. | -| 18 | The size of a pointer on this platform is 8 bytes. | +| Lines | Notes | +||-| +| 1, 2, 4, 7 | A function call consists of the function and its arguments. | +| 4, 14 | The arguments of a call are ordered from left to right. | +| 5, 6 | Array access is represented as `*(left + right)`. | +| 9, 13 | Array and struct offsets are in premultiplied form. | +| 9 | The type `ptrdiff_t` on this platform is `long`, not `int`. | +| 13 | The size of a pointer on this platform is 8 bytes. | See `debug_node` for how to
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Feb 5 23:11:23 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: README.md cgram.y ckctype.c ckgetopt.c debug.c emit1.c externs1.h lint1.h op.h oper.c tree.c Log Message: lint: make function call arguments directly accessible Previously, the arguments of a function call expression were arranged in a linear tree structure, from right to left. To allow easier access to the arguments, store them in an array instead. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/README.md \ src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.486 -r1.487 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ckctype.c cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.602 -r1.603 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 19:37:02 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lint1.h main1.c Log Message: lint: remove excessive empty lines To generate a diff of this commit: cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/main1.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/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.212 src/usr.bin/xlint/lint1/lint1.h:1.213 --- src/usr.bin/xlint/lint1/lint1.h:1.212 Sat Feb 3 19:25:16 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sat Feb 3 19:37:02 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.212 2024/02/03 19:25:16 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.213 2024/02/03 19:37:02 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -180,8 +180,6 @@ struct lint1_type { #define t_params t_u._t_params - - typedef enum { SK_VCFT, /* variable, constant, function, type */ SK_MEMBER, /* member of a struct or union */ Index: src/usr.bin/xlint/lint1/main1.c diff -u src/usr.bin/xlint/lint1/main1.c:1.81 src/usr.bin/xlint/lint1/main1.c:1.82 --- src/usr.bin/xlint/lint1/main1.c:1.81 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/main1.c Sat Feb 3 19:37:02 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: main1.c,v 1.81 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: main1.c,v 1.81 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $"); #endif #include @@ -213,7 +213,6 @@ main(int argc, char *argv[]) if (argc != 2) usage(); - /* initialize output */ outopen(argv[1]);
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 19:37:02 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lint1.h main1.c Log Message: lint: remove excessive empty lines To generate a diff of this commit: cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/main1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 19:25:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c externs1.h init.c lex.c lint1.h tree.c Log Message: lint: keep strings in their source representation This allows further analysis depending on whether individual characters are escaped as octal, hexadecimal or not at all. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.69 -r1.70 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.257 -r1.258 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/lex.c \ src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.601 -r1.602 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/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.21 src/usr.bin/xlint/lint1/ckgetopt.c:1.22 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.21 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/ckgetopt.c Sat Feb 3 19:25:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.22 2024/02/03 19:25:16 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.22 2024/02/03 19:25:16 rillig Exp $"); #endif #include @@ -100,7 +100,12 @@ is_getopt_condition(const tnode_t *tn, c && last_arg->tn_left->tn_op == ADDR && last_arg->tn_left->tn_left->tn_op == STRING && (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) { - *out_options = xstrdup(str->data); + buffer buf; + buf_init(); + quoted_iterator it = { .start = 0 }; + while (quoted_next(str, )) + buf_add_char(, (char)it.value); + *out_options = buf.data; return true; } return false; Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.69 src/usr.bin/xlint/lint1/debug.c:1.70 --- src/usr.bin/xlint/lint1/debug.c:1.69 Fri Feb 2 16:25:58 2024 +++ src/usr.bin/xlint/lint1/debug.c Sat Feb 3 19:25:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.69 2024/02/02 16:25:58 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.70 2024/02/03 19:25:16 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.69 2024/02/02 16:25:58 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.70 2024/02/03 19:25:16 rillig Exp $"); #endif #include @@ -235,11 +235,10 @@ debug_node(const tnode_t *tn) // NOLINT( debug_printf("\n"); break; case STRING: - debug_printf(", length %zu", tn->tn_string->len); if (tn->tn_string->data != NULL) - // TODO: May contain \0 or control characters. - debug_printf(", \"%s\"", tn->tn_string->data); - debug_printf("\n"); + debug_printf(", %s\n", tn->tn_string->data); + else + debug_printf(", length %zu\n", tn->tn_string->len); break; default: debug_printf("\n"); Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.84 src/usr.bin/xlint/lint1/emit1.c:1.85 --- src/usr.bin/xlint/lint1/emit1.c:1.84 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/emit1.c Sat Feb 3 19:25:16 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.84 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.85 2024/02/03 19:25:16 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,9 +38,11 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.84 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.85 2024/02/03 19:25:16 rillig Exp $"); #endif +#include + #include "lint1.h" static void outtt(sym_t *, sym_t *); @@ -367,10 +369,17 @@ outcall(const tnode_t *tn, bool retval_u } else if (arg->tn_op == ADDR && arg->tn_left->tn_op == STRING && arg->tn_left->tn_string->data != NULL) { - /* constant string, write all format specifiers */ + buffer buf; + buf_init(); + quoted_iterator it = { .start = 0 }; + while (quoted_next(arg->tn_left->tn_string, )) +buf_add_char(, (char)it.value); + + /* string literal, write all format specifiers */ outchar('s'); outint(n); - outfstrg(arg->tn_left->tn_string->data); + outfstrg(buf.data); + free(buf.data); } } outchar((char)(retval_discarded ? 'd' : retval_used ? 'u' : 'i')); Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.214 src/usr.bin/xlint/lint1/externs1.h:1.215 --- src/usr.bin/xlint/lint1/externs1.h:1.214 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/externs1.h Sat Feb 3
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 19:25:16 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c externs1.h init.c lex.c lint1.h tree.c Log Message: lint: keep strings in their source representation This allows further analysis depending on whether individual characters are escaped as octal, hexadecimal or not at all. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.69 -r1.70 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.257 -r1.258 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/lex.c \ src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.601 -r1.602 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 12:57:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckbool.c ckgetopt.c decl.c emit1.c externs1.h func.c lex.c main1.c Log Message: lint: clean up comments, reduce scope of variables To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/lint1/ckbool.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.390 -r1.391 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/main1.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/ckbool.c diff -u src/usr.bin/xlint/lint1/ckbool.c:1.28 src/usr.bin/xlint/lint1/ckbool.c:1.29 --- src/usr.bin/xlint/lint1/ckbool.c:1.28 Sat Dec 30 15:37:27 2023 +++ src/usr.bin/xlint/lint1/ckbool.c Sat Feb 3 12:57:12 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckbool.c,v 1.28 2023/12/30 15:37:27 rillig Exp $ */ +/* $NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckbool.c,v 1.28 2023/12/30 15:37:27 rillig Exp $"); +__RCSID("$NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $"); #endif #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: ckbool.c,v 1.28 2023/1 /* * The option -T treats _Bool as incompatible with all other scalar types. - * See d_c99_bool_strict.c for the exact rules and for examples. + * See d_c99_bool_strict.c for the detailed rules and for examples. */ @@ -113,16 +113,15 @@ typeok_strict_bool_binary_compatible(op_ if (is_typeok_strict_bool_binary(op, ln, lt, rn, rt)) return true; - if (op == FARG) { + if (op == FARG) /* parameter %d expects '%s', gets passed '%s' */ error(334, arg, tspec_name(lt), tspec_name(rt)); - } else if (op == RETURN) { + else if (op == RETURN) /* function has return type '%s' but returns '%s' */ error(211, tspec_name(lt), tspec_name(rt)); - } else { + else /* operands of '%s' have incompatible types '%s' and '%s' */ error(107, op_name(op), tspec_name(lt), tspec_name(rt)); - } return false; } @@ -136,16 +135,12 @@ typeok_scalar_strict_bool(op_t op, const const tnode_t *ln, const tnode_t *rn) { - tspec_t lt, rt; - ln = before_conversion(ln); - lt = ln->tn_type->t_tspec; - + tspec_t lt = ln->tn_type->t_tspec; + tspec_t rt = NO_TSPEC; if (rn != NULL) { rn = before_conversion(rn); rt = rn->tn_type->t_tspec; - } else { - rt = NO_TSPEC; } if (rn != NULL && @@ -202,26 +197,16 @@ typeok_scalar_strict_bool(op_t op, const return true; } -/* - * See if the node is valid as operand of an operator that compares its - * operand with 0. - */ bool is_typeok_bool_compares_with_zero(const tnode_t *tn) { - tspec_t t; - while (tn->tn_op == COMMA) tn = tn->tn_right; tn = before_conversion(tn); - t = tn->tn_type->t_tspec; - - if (t == BOOL) - return true; - if (tn->tn_sys && is_scalar(t)) - return true; - return tn->tn_op == BITAND; + return tn->tn_type->t_tspec == BOOL + || tn->tn_op == BITAND + || (tn->tn_sys && is_scalar(tn->tn_type->t_tspec)); } bool Index: src/usr.bin/xlint/lint1/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.20 src/usr.bin/xlint/lint1/ckgetopt.c:1.21 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.20 Thu Feb 1 18:37:06 2024 +++ src/usr.bin/xlint/lint1/ckgetopt.c Sat Feb 3 12:57:12 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $"); #endif #include @@ -109,31 +109,22 @@ 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; - optptr = strchr(ck.options, opt); + char *optptr = strchr(ck.options, opt); if (optptr != NULL) *optptr = ' '; - else if (opt != '?') { + else if (opt != '?') warn: /* option '%c' should be listed in the options string */ warning(339, opt); - } } static void check_unhandled_option(void) { - const char *opt; - - lint_assert(ck.options != NULL); - - for (opt = ck.options; *opt != '\0'; opt++) { + for (const char *opt = ck.options; *opt != '\0'; opt++) { if (*opt == ' ' || *opt == ':') continue; Index: src/usr.bin/xlint/lint1/decl.c
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Feb 3 12:57:12 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckbool.c ckgetopt.c decl.c emit1.c externs1.h func.c lex.c main1.c Log Message: lint: clean up comments, reduce scope of variables To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/lint1/ckbool.c cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.390 -r1.391 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/main1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Jan 29 21:30:25 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c lex.c lint1.h tree.c Log Message: lint: do not remember content of wide string literals The plain char literals are needed for checking printf/scanf format strings; lint has no similar check for wide strings. These format strings are checked by modern compilers, making this check less relevant. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.598 -r1.599 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/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.18 src/usr.bin/xlint/lint1/ckgetopt.c:1.19 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.18 Mon Jan 29 21:04:21 2024 +++ src/usr.bin/xlint/lint1/ckgetopt.c Mon Jan 29 21:30:24 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $"); #endif #include @@ -100,7 +100,7 @@ is_getopt_condition(const tnode_t *tn, c && last_arg->tn_left->tn_op == ADDR && last_arg->tn_left->tn_left->tn_op == STRING && (str = last_arg->tn_left->tn_left->tn_string)->st_char) { - *out_options = xstrdup(str->st_mem); + *out_options = xstrdup(str->st_chars); return true; } return false; Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.66 src/usr.bin/xlint/lint1/debug.c:1.67 --- src/usr.bin/xlint/lint1/debug.c:1.66 Tue Jan 23 19:44:28 2024 +++ src/usr.bin/xlint/lint1/debug.c Mon Jan 29 21:30:24 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.66 2024/01/23 19:44:28 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.67 2024/01/29 21:30:24 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.66 2024/01/23 19:44:28 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.67 2024/01/29 21:30:24 rillig Exp $"); #endif #include @@ -238,15 +238,9 @@ debug_node(const tnode_t *tn) // NOLINT( if (tn->tn_string->st_char) debug_printf(", length %zu, \"%s\"\n", tn->tn_string->st_len, - (const char *)tn->tn_string->st_mem); - else { - size_t n = MB_CUR_MAX * (tn->tn_string->st_len + 1); - char *s = xmalloc(n); - (void)wcstombs(s, tn->tn_string->st_mem, n); - debug_printf(", length %zu, L\"%s\"\n", - tn->tn_string->st_len, s); - free(s); - } + tn->tn_string->st_chars); + else + debug_printf(", length %zu\n", tn->tn_string->st_len); break; default: debug_printf("\n"); Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.81 src/usr.bin/xlint/lint1/emit1.c:1.82 --- src/usr.bin/xlint/lint1/emit1.c:1.81 Sun Dec 3 18:17:41 2023 +++ src/usr.bin/xlint/lint1/emit1.c Mon Jan 29 21:30:24 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.81 2023/12/03 18:17:41 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.82 2024/01/29 21:30:24 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.81 2023/12/03 18:17:41 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.82 2024/01/29 21:30:24 rillig Exp $"); #endif #include "lint1.h" @@ -450,17 +450,13 @@ outqchar(char c) static void outfstrg(strg_t *strg) { - char c, oc; - bool first; - const char *cp; lint_assert(strg->st_char); - cp = strg->st_mem; + const char *cp = strg->st_chars; outchar('"'); - c = *cp++; - + char c = *cp++; while (c != '\0') { if (c != '%') { @@ -511,7 +507,7 @@ outfstrg(strg_t *strg) */ if (c != '\0') { outqchar(c); - oc = c; + char oc = c; c = *cp++; /* * handle [ for scanf. [-] means that a minus sign was @@ -522,7 +518,7 @@ outfstrg(strg_t *strg) c = *cp++; if (c == ']') c = *cp++; -first = true; +bool first = true; while (c != '\0' && c != ']') { if (c == '-') { if (!first && *cp != ']') Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.203 src/usr.bin/xlint/lint1/lex.c:1.204 --- src/usr.bin/xlint/lint1/lex.c:1.203 Sat Jan 27 20:03:14 2024 +++ src/usr.bin/xlint/lint1/lex.c Mon Jan 29 21:30:25 2024 @@ -1,4 +1,4 @@ -/* $NetBSD:
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Jan 29 21:30:25 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c lex.c lint1.h tree.c Log Message: lint: do not remember content of wide string literals The plain char literals are needed for checking printf/scanf format strings; lint has no similar check for wide strings. These format strings are checked by modern compilers, making this check less relevant. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/ckgetopt.c cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.598 -r1.599 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Jan 29 21:04:21 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c Log Message: lint: check getopt call more strictly Previously, '(c = getopt(...)) != -2' would match as well. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/ckgetopt.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/ckgetopt.c diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.17 src/usr.bin/xlint/lint1/ckgetopt.c:1.18 --- src/usr.bin/xlint/lint1/ckgetopt.c:1.17 Sun Dec 3 13:12:40 2023 +++ src/usr.bin/xlint/lint1/ckgetopt.c Mon Jan 29 21:04:21 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ckgetopt.c,v 1.17 2023/12/03 13:12:40 rillig Exp $ */ +/* $NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: ckgetopt.c,v 1.17 2023/12/03 13:12:40 rillig Exp $"); +__RCSID("$NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $"); #endif #include @@ -75,38 +75,35 @@ static struct { int switch_level; } ck; -#define NEED(cond) \ - do {\ - if (!(cond)) \ - return false; \ - } while (false) - -/* Return whether tn has the form 'getopt(argc, argv, "literal") != -1'. */ +/* Return whether tn has the form '(c = getopt(argc, argv, "str")) != -1'. */ static bool is_getopt_condition(const tnode_t *tn, char **out_options) { const tnode_t *call, *last_arg; + const strg_t *str; - NEED(tn != NULL); - NEED(tn->tn_op == NE); - NEED(tn->tn_left->tn_op == ASSIGN); - - 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); - NEED(strcmp(call->tn_left->tn_left->tn_sym->s_name, "getopt") == 0); - - NEED(call->tn_right->tn_op == PUSH); - - 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); - NEED(last_arg->tn_left->tn_left->tn_string->st_char); - - *out_options = xstrdup(last_arg->tn_left->tn_left->tn_string->st_mem); - return true; + if (tn != NULL + && tn->tn_op == NE + && tn->tn_left->tn_op == ASSIGN + && tn->tn_right->tn_op == CON + && tn->tn_right->tn_u._tn_val.v_tspec == INT + && tn->tn_right->tn_u._tn_val.u.integer == -1 + + && (call = tn->tn_left->tn_right)->tn_op == CALL + && call->tn_left->tn_op == ADDR + && call->tn_left->tn_left->tn_op == NAME + && strcmp(call->tn_left->tn_left->tn_sym->s_name, "getopt") == 0 + + && call->tn_right->tn_op == PUSH + + && (last_arg = call->tn_right->tn_left)->tn_op == CVT + && last_arg->tn_left->tn_op == ADDR + && last_arg->tn_left->tn_left->tn_op == STRING + && (str = last_arg->tn_left->tn_left->tn_string)->st_char) { + *out_options = xstrdup(str->st_mem); + return true; + } + return false; } static void
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Mon Jan 29 21:04:21 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: ckgetopt.c Log Message: lint: check getopt call more strictly Previously, '(c = getopt(...)) != -2' would match as well. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/ckgetopt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 27 15:53:28 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: split determining the type of an integer constant No functional change. To generate a diff of this commit: cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.201 src/usr.bin/xlint/lint1/lex.c:1.202 --- src/usr.bin/xlint/lint1/lex.c:1.201 Sat Jan 27 12:14:58 2024 +++ src/usr.bin/xlint/lint1/lex.c Sat Jan 27 15:53:27 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.201 2024/01/27 12:14:58 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.202 2024/01/27 15:53:27 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.201 2024/01/27 12:14:58 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.202 2024/01/27 15:53:27 rillig Exp $"); #endif #include @@ -502,6 +502,67 @@ is_unsigned_since_c90(tspec_t typ, uint6 return typ == LONG && ui > TARG_LONG_MAX; } +static tspec_t +integer_constant_type(tspec_t typ, uint64_t ui, int base, bool warned) +{ + switch (typ) { + case INT: + if (ui <= TARG_INT_MAX) { + /* ok */ + } else if (ui <= TARG_UINT_MAX && base != 10) { + typ = UINT; + } else if (ui <= TARG_LONG_MAX) { + typ = LONG; + } else { + typ = ULONG; + if (ui > TARG_ULONG_MAX && !warned) { +/* integer constant out of range */ +warning(252); + } + } + if ((typ == UINT || typ == ULONG) && !allow_c90) + typ = LONG; + break; + case UINT: + if (ui > TARG_UINT_MAX) { + typ = ULONG; + if (ui > TARG_ULONG_MAX && !warned) { +/* integer constant out of range */ +warning(252); + } + } + break; + case LONG: + if (ui > TARG_LONG_MAX && allow_c90) { + typ = ULONG; + if (ui > TARG_ULONG_MAX && !warned) { +/* integer constant out of range */ +warning(252); + } + } + break; + case ULONG: + if (ui > TARG_ULONG_MAX && !warned) { + /* integer constant out of range */ + warning(252); + } + break; + case LLONG: + if (ui > TARG_LLONG_MAX && allow_c90) + typ = ULLONG; + break; + case ULLONG: + if (ui > TARG_ULLONG_MAX && !warned) { + /* integer constant out of range */ + warning(252); + } + break; + default: + break; + } + return typ; +} + int lex_integer_constant(const char *yytext, size_t yyleng, int base) { @@ -543,7 +604,7 @@ lex_integer_constant(const char *yytext, /* suffix 'U' is illegal in traditional C */ warning(97); } - tspec_t typ = suffix_type[u_suffix][l_suffix]; + tspec_t ct = suffix_type[u_suffix][l_suffix]; bool warned = false; errno = 0; @@ -561,67 +622,13 @@ lex_integer_constant(const char *yytext, query_message(8, (int)len, cp); } - bool ansiu = is_unsigned_since_c90(typ, ui, base); - switch (typ) { - case INT: - if (ui <= TARG_INT_MAX) { - /* ok */ - } else if (ui <= TARG_UINT_MAX && base != 10) { - typ = UINT; - } else if (ui <= TARG_LONG_MAX) { - typ = LONG; - } else { - typ = ULONG; - if (ui > TARG_ULONG_MAX && !warned) { -/* integer constant out of range */ -warning(252); - } - } - if ((typ == UINT || typ == ULONG) && !allow_c90) - typ = LONG; - break; - case UINT: - if (ui > TARG_UINT_MAX) { - typ = ULONG; - if (ui > TARG_ULONG_MAX && !warned) { -/* integer constant out of range */ -warning(252); - } - } - break; - case LONG: - if (ui > TARG_LONG_MAX && allow_c90) { - typ = ULONG; - if (ui > TARG_ULONG_MAX && !warned) { -/* integer constant out of range */ -warning(252); - } - } - break; - case ULONG: - if (ui > TARG_ULONG_MAX && !warned) { - /* integer constant out of range */ - warning(252); - } - break; - case LLONG: - if (ui > TARG_LLONG_MAX && allow_c90) - typ = ULLONG; - break; - case ULLONG: - if (ui > TARG_ULLONG_MAX && !warned) { - /* integer constant out of range */ - warning(252); - } - break; - default: - break; - } + bool ansiu = is_unsigned_since_c90(ct, ui, base); - ui = (uint64_t)convert_integer((int64_t)ui, typ, 0); + tspec_t t = integer_constant_type(ct, ui, base, warned); + ui = (uint64_t)convert_integer((int64_t)ui, t, 0); yylval.y_val = xcalloc(1, sizeof(*yylval.y_val)); - yylval.y_val->v_tspec = typ; + yylval.y_val->v_tspec = t; yylval.y_val->v_unsigned_since_c90 = ansiu; yylval.y_val->u.integer = (int64_t)ui;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 27 15:53:28 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: split determining the type of an integer constant No functional change. To generate a diff of this commit: cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 27 12:14:58 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: extract signedness detection from lexing an integer constant An integer constant that is signed in traditional C but unsigned since C90 is an edge case that should not clutter the main code of determining the resulting type of the constant. The code for lexing an integer constant doesn't implement the C99 rules yet, which convert a constant to the 'long long' types if the 'long' types don't suffice. To generate a diff of this commit: cvs rdiff -u -r1.200 -r1.201 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.200 src/usr.bin/xlint/lint1/lex.c:1.201 --- src/usr.bin/xlint/lint1/lex.c:1.200 Tue Jan 23 19:44:28 2024 +++ src/usr.bin/xlint/lint1/lex.c Sat Jan 27 12:14:58 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.200 2024/01/23 19:44:28 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.201 2024/01/27 12:14:58 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.200 2024/01/23 19:44:28 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.201 2024/01/27 12:14:58 rillig Exp $"); #endif #include @@ -487,6 +487,21 @@ lex_name(const char *yytext, size_t yyle return T_NAME; } +// Determines whether the constant is signed in traditional C but unsigned in +// C90 and later. +static bool +is_unsigned_since_c90(tspec_t typ, uint64_t ui, int base) +{ + if (!(allow_trad && allow_c90)) + return false; + if (typ == INT) { + if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10) + return true; + return ui > TARG_LONG_MAX; + } + return typ == LONG && ui > TARG_LONG_MAX; +} + int lex_integer_constant(const char *yytext, size_t yyleng, int base) { @@ -546,11 +561,7 @@ lex_integer_constant(const char *yytext, query_message(8, (int)len, cp); } - /* - * If the value is too big for the current type, we must choose another - * type. - */ - bool ansiu = false; + bool ansiu = is_unsigned_since_c90(typ, ui, base); switch (typ) { case INT: if (ui <= TARG_INT_MAX) { @@ -566,17 +577,8 @@ lex_integer_constant(const char *yytext, warning(252); } } - if (typ == UINT || typ == ULONG) { - if (!allow_c90) { -typ = LONG; - } else if (allow_trad) { -/* - * Remember that the constant is unsigned only - * in C90. - */ -ansiu = true; - } - } + if ((typ == UINT || typ == ULONG) && !allow_c90) + typ = LONG; break; case UINT: if (ui > TARG_UINT_MAX) { @@ -590,8 +592,6 @@ lex_integer_constant(const char *yytext, case LONG: if (ui > TARG_LONG_MAX && allow_c90) { typ = ULONG; - if (allow_trad) -ansiu = true; if (ui > TARG_ULONG_MAX && !warned) { /* integer constant out of range */ warning(252);
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 27 12:14:58 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: lint: extract signedness detection from lexing an integer constant An integer constant that is signed in traditional C but unsigned since C90 is an edge case that should not clutter the main code of determining the resulting type of the constant. The code for lexing an integer constant doesn't implement the C99 rules yet, which convert a constant to the 'long long' types if the 'long' types don't suffice. To generate a diff of this commit: cvs rdiff -u -r1.200 -r1.201 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Jan 23 20:03:42 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c tree.c Log Message: lint: unconst parameters These were leftovers from earlier refactorings and are no longer needed. No binary change. To generate a diff of this commit: cvs rdiff -u -r1.389 -r1.390 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.597 -r1.598 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.389 src/usr.bin/xlint/lint1/decl.c:1.390 --- src/usr.bin/xlint/lint1/decl.c:1.389 Tue Jan 23 19:44:28 2024 +++ src/usr.bin/xlint/lint1/decl.c Tue Jan 23 20:03:42 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.389 2024/01/23 19:44:28 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.390 2024/01/23 20:03:42 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.389 2024/01/23 19:44:28 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.390 2024/01/23 20:03:42 rillig Exp $"); #endif #include @@ -932,7 +932,7 @@ check_type(sym_t *sym) * implementation-defined type". */ static void -check_bit_field_type(sym_t *dsym, type_t **const inout_tp, tspec_t *inout_t) +check_bit_field_type(sym_t *dsym, type_t **inout_tp, tspec_t *inout_t) { type_t *tp = *inout_tp; tspec_t t = *inout_t; @@ -976,7 +976,7 @@ check_bit_field_type(sym_t *dsym, type_t } static void -check_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **const inout_tp) +check_bit_field(sym_t *dsym, tspec_t *inout_t, type_t **inout_tp) { check_bit_field_type(dsym, inout_tp, inout_t); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.597 src/usr.bin/xlint/lint1/tree.c:1.598 --- src/usr.bin/xlint/lint1/tree.c:1.597 Tue Jan 23 19:44:28 2024 +++ src/usr.bin/xlint/lint1/tree.c Tue Jan 23 20:03:42 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.597 2024/01/23 19:44:28 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.598 2024/01/23 20:03:42 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.597 2024/01/23 19:44:28 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.598 2024/01/23 20:03:42 rillig Exp $"); #endif #include @@ -2670,11 +2670,11 @@ check_unconst_function(const type_t *lst static bool check_assign_void_pointer_compat(op_t op, int arg, - const type_t *const ltp, tspec_t const lt, - const type_t *const lstp, tspec_t const lst, - const tnode_t *const rn, - const type_t *const rtp, tspec_t const rt, - const type_t *const rstp, tspec_t const rst) + const type_t *ltp, tspec_t lt, + const type_t *lstp, tspec_t lst, + const tnode_t *rn, + const type_t *rtp, tspec_t rt, + const type_t *rstp, tspec_t rst) { if (!(lt == PTR && rt == PTR && (lst == VOID || rst == VOID || types_compatible(lstp, rstp, @@ -2713,8 +2713,8 @@ check_assign_void_pointer_compat(op_t op static bool check_assign_pointer_integer(op_t op, int arg, - const type_t *const ltp, tspec_t const lt, - const type_t *const rtp, tspec_t const rt) + const type_t *ltp, tspec_t lt, + const type_t *rtp, tspec_t rt) { if (!((lt == PTR && is_integer(rt)) || (is_integer(lt) && rt == PTR)))
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Jan 23 20:03:42 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: decl.c tree.c Log Message: lint: unconst parameters These were leftovers from earlier refactorings and are no longer needed. No binary change. To generate a diff of this commit: cvs rdiff -u -r1.389 -r1.390 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.597 -r1.598 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: christos Date: Fri Jan 19 18:23:13 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: add \e To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 src/usr.bin/xlint/lint1/lex.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/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.197 src/usr.bin/xlint/lint1/lex.c:1.198 --- src/usr.bin/xlint/lint1/lex.c:1.197 Sun Jan 7 13:42:37 2024 +++ src/usr.bin/xlint/lint1/lex.c Fri Jan 19 13:23:13 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.197 2024/01/07 18:42:37 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.198 2024/01/19 18:23:13 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.197 2024/01/07 18:42:37 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.198 2024/01/19 18:23:13 christos Exp $"); #endif #include @@ -791,6 +791,8 @@ read_escaped_backslash(int delim) return '\a'; case 'b': return '\b'; + case 'e': /* Not in the C standard yet, compilers recognize it */ + return '\e'; case 'f': return '\f'; case 'n':
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: christos Date: Fri Jan 19 18:23:13 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: lex.c Log Message: add \e To generate a diff of this commit: cvs rdiff -u -r1.197 -r1.198 src/usr.bin/xlint/lint1/lex.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 13 11:24:57 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y init.c Log Message: lint: clean up grammar for initializers To generate a diff of this commit: cvs rdiff -u -r1.482 -r1.483 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.255 -r1.256 src/usr.bin/xlint/lint1/init.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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.482 src/usr.bin/xlint/lint1/cgram.y:1.483 --- src/usr.bin/xlint/lint1/cgram.y:1.482 Sat Jan 13 01:23:39 2024 +++ src/usr.bin/xlint/lint1/cgram.y Sat Jan 13 11:24:57 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.482 2024/01/13 01:23:39 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.483 2024/01/13 11:24:57 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.482 2024/01/13 01:23:39 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.483 2024/01/13 11:24:57 rillig Exp $"); #endif #include @@ -295,7 +295,6 @@ is_either(const char *s, const char *a, %type generic_assoc_list %type generic_association %type postfix_expression -/* No type for comma_opt. */ %type gcc_statement_expr_list %type gcc_statement_expr_item %type point_or_arrow @@ -373,7 +372,6 @@ is_either(const char *s, const char *a, /* No type for braced_initializer. */ /* No type for initializer. */ /* No type for initializer_list. */ -/* No type for initializer_list_item. */ /* No type for designation. */ /* No type for designator_list. */ /* No type for designator. */ @@ -591,11 +589,6 @@ postfix_expression: } ; -comma_opt: /* helper for 'postfix_expression' */ - /* empty */ -| T_COMMA -; - /* * The inner part of a GCC statement-expression of the form ({ ... }). * @@ -1636,7 +1629,8 @@ braced_initializer: c23ism(353); } /* K ---, C90 ---, C99 6.7.8, C11 6.7.9, C23 6.7.10 */ -| init_lbrace initializer_list comma_opt init_rbrace +| init_lbrace initializer_list init_rbrace +| init_lbrace initializer_list T_COMMA init_rbrace ; initializer: /* C99 6.7.8 "Initialization" */ @@ -1646,23 +1640,21 @@ initializer: /* C99 6.7.8 "Initializat | init_lbrace init_rbrace { /* XXX: Empty braces are not covered by C99 6.7.8. */ } -| init_lbrace initializer_list comma_opt init_rbrace +| init_lbrace initializer_list init_rbrace +| init_lbrace initializer_list T_COMMA init_rbrace /* XXX: What is this error handling for? */ | error ; initializer_list: /* C99 6.7.8 "Initialization" */ - initializer_list_item -| initializer_list T_COMMA initializer_list_item -; - -initializer_list_item: /* helper */ - designation initializer -| initializer + initializer +| designation initializer +| initializer_list T_COMMA initializer +| initializer_list T_COMMA designation initializer ; designation: /* C99 6.7.8 "Initialization" */ - /* empty */ { + { begin_designation(); } designator_list T_ASSIGN | identifier T_COLON { Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.255 src/usr.bin/xlint/lint1/init.c:1.256 --- src/usr.bin/xlint/lint1/init.c:1.255 Thu Jan 11 23:26:39 2024 +++ src/usr.bin/xlint/lint1/init.c Sat Jan 13 11:24:57 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $ */ +/* $NetBSD: init.c,v 1.256 2024/01/13 11:24:57 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.256 2024/01/13 11:24:57 rillig Exp $"); #endif #include @@ -992,10 +992,9 @@ begin_designation(void) if (in->in_err) return; - brace_level *bl = in->in_brace_level; - lint_assert(bl != NULL); - bl->bl_designation.dn_len = 0; - designation_debug(>bl_designation); + designation *dn = >in_brace_level->bl_designation; + dn->dn_len = 0; + designation_debug(dn); } void
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 13 11:24:57 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y init.c Log Message: lint: clean up grammar for initializers To generate a diff of this commit: cvs rdiff -u -r1.482 -r1.483 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.255 -r1.256 src/usr.bin/xlint/lint1/init.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 13 01:23:39 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: inline simple grammar rules To generate a diff of this commit: cvs rdiff -u -r1.481 -r1.482 src/usr.bin/xlint/lint1/cgram.y 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.481 src/usr.bin/xlint/lint1/cgram.y:1.482 --- src/usr.bin/xlint/lint1/cgram.y:1.481 Fri Jan 12 08:33:39 2024 +++ src/usr.bin/xlint/lint1/cgram.y Sat Jan 13 01:23:39 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.481 2024/01/12 08:33:39 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.482 2024/01/13 01:23:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.481 2024/01/12 08:33:39 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.482 2024/01/13 01:23:39 rillig Exp $"); #endif #include @@ -328,7 +328,6 @@ is_either(const char *s, const char *a, %type struct_or_union_specifier %type struct_or_union %type braced_member_declaration_list -/* No type for member_declaration_lbrace. */ %type member_declaration_list_with_rbrace %type member_declaration_list %type member_declaration @@ -339,7 +338,6 @@ is_either(const char *s, const char *a, %type enum_specifier /* No type for enum. */ %type enum_declaration -/* No type for enum_decl_lbrace. */ %type enums_with_opt_comma %type enumerator_list %type enumerator @@ -361,7 +359,6 @@ is_either(const char *s, const char *a, %type direct_param_declarator %type direct_notype_param_declarator %type param_list -/* No type for id_list_lparen. */ %type array_size_opt %type identifier_list %type type_name @@ -378,7 +375,6 @@ is_either(const char *s, const char *a, /* No type for initializer_list. */ /* No type for initializer_list_item. */ /* No type for designation. */ -/* No type for begin_designation. */ /* No type for designator_list. */ /* No type for designator. */ /* No type for static_assert_declaration. */ @@ -406,7 +402,6 @@ is_either(const char *s, const char *a, /* No type for while_expr. */ /* No type for do_statement. */ /* No type for do. */ -%type do_while_expr /* No type for for_start. */ /* No type for for_exprs. */ /* No type for jump_statement. */ @@ -1040,14 +1035,10 @@ struct_or_union: ; braced_member_declaration_list: /* see C99 6.7.2.1 */ - member_declaration_lbrace member_declaration_list_with_rbrace { - $$ = $2; - } -; - -member_declaration_lbrace: /* see C99 6.7.2.1 */ T_LBRACE { set_symtyp(FVFT); + } member_declaration_list_with_rbrace { + $$ = $3; } ; @@ -1194,15 +1185,11 @@ enum:/* helper for C99 6.7.2.2 */ ; enum_declaration: /* helper for C99 6.7.2.2 */ - enum_decl_lbrace enums_with_opt_comma T_RBRACE { - $$ = $2; - } -; - -enum_decl_lbrace: /* helper for C99 6.7.2.2 */ T_LBRACE { set_symtyp(FVFT); enumval = 0; + } enums_with_opt_comma T_RBRACE { + $$ = $3; } ; @@ -1437,17 +1424,13 @@ direct_notype_param_declarator: ; param_list: - id_list_lparen identifier_list T_RPAREN { - $$ = (struct parameter_list){ .first = $2 }; - } -| abstract_decl_param_list -; - -id_list_lparen: T_LPAREN { block_level++; begin_declaration_level(DLK_PROTO_PARAMS); + } identifier_list T_RPAREN { + $$ = (struct parameter_list){ .first = $3 }; } +| abstract_decl_param_list ; array_size_opt: @@ -1679,7 +1662,9 @@ initializer_list_item: /* helper */ ; designation: /* C99 6.7.8 "Initialization" */ - begin_designation designator_list T_ASSIGN + /* empty */ { + begin_designation(); + } designator_list T_ASSIGN | identifier T_COLON { /* GCC style struct or union member name in initializer */ gnuism(315); @@ -1688,12 +1673,6 @@ designation: /* C99 6.7.8 "Initializat } ; -begin_designation: /* lint-specific helper */ - /* empty */ { - begin_designation(); - } -; - designator_list: /* C99 6.7.8 "Initialization" */ designator | designator_list designator @@ -1933,8 +1912,8 @@ iteration_statement: /* C99 6.8.5 */ clear_warning_flags(); stmt_while_expr_stmt(); } -| do_statement do_while_expr { - stmt_do_while_expr($2); +| do_statement T_WHILE T_LPAREN expression T_RPAREN T_SEMI { + stmt_do_while_expr($4); suppress_fallthrough = false; } | do error { @@ -1974,12 +1953,6 @@ do:/* see C99 6.8.5 */ } ; -do_while_expr: /* see C99 6.8.5 */ - T_WHILE T_LPAREN expression T_RPAREN T_SEMI { - $$ = $3; - } -; - for_start: /* see C99 6.8.5 */ T_FOR T_LPAREN { begin_declaration_level(DLK_AUTO);
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 13 01:23:39 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: inline simple grammar rules To generate a diff of this commit: cvs rdiff -u -r1.481 -r1.482 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Jan 12 08:33:39 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: clean up grammar for array size To generate a diff of this commit: cvs rdiff -u -r1.480 -r1.481 src/usr.bin/xlint/lint1/cgram.y 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.480 src/usr.bin/xlint/lint1/cgram.y:1.481 --- src/usr.bin/xlint/lint1/cgram.y:1.480 Thu Jan 11 23:26:39 2024 +++ src/usr.bin/xlint/lint1/cgram.y Fri Jan 12 08:33:39 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.481 2024/01/12 08:33:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.481 2024/01/12 08:33:39 rillig Exp $"); #endif #include @@ -363,7 +363,6 @@ is_either(const char *s, const char *a, %type param_list /* No type for id_list_lparen. */ %type array_size_opt -%type array_size %type identifier_list %type type_name %type abstract_declaration @@ -1461,28 +1460,26 @@ array_size_opt: $$.has_dim = false; /* TODO: maybe change to true */ $$.dim = 0; /* just as a placeholder */ } -| array_size { - $$.has_dim = true; - $$.dim = $1 == NULL ? 0 : to_int_constant($1, false); - } -; - -array_size: - type_qualifier_list_opt T_SCLASS constant_expression { +| type_qualifier_list_opt T_SCLASS constant_expression { /* C11 6.7.6.3p7 */ if ($2 != STATIC) yyerror("Bad attribute"); /* static array size requires C11 or later */ c11ism(343); - $$ = $3; + $$.has_dim = true; + $$.dim = $3 == NULL ? 0 : to_int_constant($3, false); } | type_qualifier { /* C11 6.7.6.2 */ if (!$1.tq_restrict) yyerror("Bad attribute"); - $$ = NULL; + $$.has_dim = true; + $$.dim = 0; + } +| constant_expression { + $$.has_dim = true; + $$.dim = $1 == NULL ? 0 : to_int_constant($1, false); } -| constant_expression ; identifier_list: /* C99 6.7.5 */
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Fri Jan 12 08:33:39 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: clean up grammar for array size To generate a diff of this commit: cvs rdiff -u -r1.480 -r1.481 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Jan 11 23:26:40 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y init.c lint1.h tree.c Log Message: lint: clean up enum constants for designators In intializers and offsetof, both struct and union members are handled in the same way, thus there is no need to distinguish them. To generate a diff of this commit: cvs rdiff -u -r1.479 -r1.480 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.254 -r1.255 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.207 -r1.208 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.594 -r1.595 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.479 src/usr.bin/xlint/lint1/cgram.y:1.480 --- src/usr.bin/xlint/lint1/cgram.y:1.479 Thu Jan 11 23:06:19 2024 +++ src/usr.bin/xlint/lint1/cgram.y Thu Jan 11 23:26:39 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.480 2024/01/11 23:26:39 rillig Exp $"); #endif #include @@ -512,17 +512,17 @@ primary_expression: member_designator: identifier { $$ = (designation) { .dn_len = 0 }; - designation_push(&$$, DK_STRUCT /* or union */, getsym($1), 0); + designation_push(&$$, DK_MEMBER, getsym($1), 0); } | member_designator T_LBRACK range T_RBRACK { $$ = $1; - designation_push(&$$, DK_ARRAY, NULL, $3.lo); + designation_push(&$$, DK_SUBSCRIPT, NULL, $3.lo); } | member_designator T_POINT { set_symtyp(FMEMBER); } identifier { $$ = $1; - designation_push(&$$, DK_STRUCT /* or union */, getsym($4), 0); + designation_push(&$$, DK_MEMBER, getsym($4), 0); } ; Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.254 src/usr.bin/xlint/lint1/init.c:1.255 --- src/usr.bin/xlint/lint1/init.c:1.254 Tue Jan 9 23:46:54 2024 +++ src/usr.bin/xlint/lint1/init.c Thu Jan 11 23:26:39 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.254 2024/01/09 23:46:54 rillig Exp $ */ +/* $NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.254 2024/01/09 23:46:54 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.255 2024/01/11 23:26:39 rillig Exp $"); #endif #include @@ -311,7 +311,7 @@ designator_type(const designator *dr, co switch (tp->t_tspec) { case STRUCT: case UNION: - if (dr->dr_kind != DK_STRUCT && dr->dr_kind != DK_UNION) { + if (dr->dr_kind != DK_MEMBER) { const sym_t *fmem = first_named_member(tp); /* syntax error '%s' */ error(249, "designator '[...]' is only for arrays"); @@ -321,7 +321,7 @@ designator_type(const designator *dr, co lint_assert(dr->dr_member != NULL); return dr->dr_member->s_type; case ARRAY: - if (dr->dr_kind != DK_ARRAY) { + if (dr->dr_kind != DK_SUBSCRIPT) { /* syntax error '%s' */ error(249, "designator '.member' is only for struct/union"); @@ -344,13 +344,13 @@ static void designator_debug(const designator *dr) { - if (dr->dr_kind == DK_STRUCT || dr->dr_kind == DK_UNION) { + if (dr->dr_kind == DK_MEMBER) { lint_assert(dr->dr_subscript == 0); debug_printf(".%s", dr->dr_member != NULL ? dr->dr_member->s_name : ""); - } else if (dr->dr_kind == DK_ARRAY) { + } else if (dr->dr_kind == DK_SUBSCRIPT) { lint_assert(dr->dr_member == NULL); debug_printf("[%zu]", dr->dr_subscript); } else { @@ -421,10 +421,9 @@ designation_descend(designation *dn, con const sym_t *member = first_named_member(tp); if (member == NULL) return false; - designation_push(dn, - tp->t_tspec == STRUCT ? DK_STRUCT : DK_UNION, member, 0); + designation_push(dn, DK_MEMBER, member, 0); } else if (tp->t_tspec == ARRAY) - designation_push(dn, DK_ARRAY, NULL, 0); + designation_push(dn, DK_SUBSCRIPT, NULL, 0); else designation_push(dn, DK_SCALAR, NULL, 0); return true; @@ -550,10 +549,10 @@ static void warn_too_many_initializers(designator_kind kind, const type_t *tp) { - if (kind == DK_STRUCT || kind == DK_UNION) { + if (kind == DK_MEMBER) { /* too many struct/union initializers */ error(172); - } else if (kind == DK_ARRAY) { + } else if (kind == DK_SUBSCRIPT) { lint_assert(tp->t_tspec == ARRAY); lint_assert(!tp->t_incomplete_array); /* too many array initializers, expected %d */ @@ -816,8 +815,7 @@ proceed:; return; } - designation_push(>bl_designation, - tp->t_tspec == STRUCT ? DK_STRUCT : DK_UNION, member, 0); + designation_push(>bl_designation, DK_MEMBER,
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Jan 11 23:26:40 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y init.c lint1.h tree.c Log Message: lint: clean up enum constants for designators In intializers and offsetof, both struct and union members are handled in the same way, thus there is no need to distinguish them. To generate a diff of this commit: cvs rdiff -u -r1.479 -r1.480 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.254 -r1.255 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.207 -r1.208 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.594 -r1.595 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Jan 11 23:06:19 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y externs1.h tree.c Log Message: lint: correctly set system-header flag on cast-expression When a cast-expression comes partly from a system header, determine at the ')' whether the whole cast-expression comes from the system header. Previously, it was based on the operand, which contradicted the documentation of tn_sys. Mainly affects strict bool mode (where expressions from system headers are handled more leniently), as well as query 9 for parenthesized return expressions. Discovered upon manual inspection, as calling expr_alloc_tnode should never be necessary when creating an expression node with operands; there's build_op for that purpose. To generate a diff of this commit: cvs rdiff -u -r1.478 -r1.479 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.593 -r1.594 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.478 src/usr.bin/xlint/lint1/cgram.y:1.479 --- src/usr.bin/xlint/lint1/cgram.y:1.478 Tue Jan 9 23:46:54 2024 +++ src/usr.bin/xlint/lint1/cgram.y Thu Jan 11 23:06:19 2024 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.478 2024/01/09 23:46:54 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.478 2024/01/09 23:46:54 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.479 2024/01/11 23:06:19 rillig Exp $"); #endif #include @@ -724,8 +724,8 @@ unary_expression: /* K 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */ cast_expression: unary_expression -| T_LPAREN type_name T_RPAREN cast_expression { - $$ = cast($4, $2); +| T_LPAREN type_name T_RPAREN sys cast_expression { + $$ = cast($5, $4, $2); } ; Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.210 src/usr.bin/xlint/lint1/externs1.h:1.211 --- src/usr.bin/xlint/lint1/externs1.h:1.210 Tue Jan 9 23:46:54 2024 +++ src/usr.bin/xlint/lint1/externs1.h Thu Jan 11 23:06:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.210 2024/01/09 23:46:54 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.211 2024/01/11 23:06:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -291,7 +291,7 @@ void convert_constant(op_t, int, const t tnode_t *build_sizeof(const type_t *); tnode_t *build_offsetof(const type_t *, designation); tnode_t *build_alignof(const type_t *); -tnode_t *cast(tnode_t *, type_t *); +tnode_t *cast(tnode_t *, bool, type_t *); tnode_t *build_function_argument(tnode_t *, tnode_t *); tnode_t *build_function_call(tnode_t *, bool, tnode_t *); val_t *integer_constant(tnode_t *, bool); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.593 src/usr.bin/xlint/lint1/tree.c:1.594 --- src/usr.bin/xlint/lint1/tree.c:1.593 Thu Jan 11 20:25:04 2024 +++ src/usr.bin/xlint/lint1/tree.c Thu Jan 11 23:06:19 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.593 2024/01/11 20:25:04 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.594 2024/01/11 23:06:19 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.593 2024/01/11 20:25:04 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.594 2024/01/11 23:06:19 rillig Exp $"); #endif #include @@ -4017,7 +4017,7 @@ build_alignof(const type_t *tp) } static tnode_t * -cast_to_union(tnode_t *otn, type_t *ntp) +cast_to_union(tnode_t *otn, bool sys, type_t *ntp) { if (!allow_gcc) { @@ -4030,12 +4030,8 @@ cast_to_union(tnode_t *otn, type_t *ntp) m != NULL; m = m->s_next) { if (types_compatible(m->s_type, otn->tn_type, false, false, NULL)) { - tnode_t *ntn = expr_alloc_tnode(); - ntn->tn_op = CVT; - ntn->tn_type = ntp; + tnode_t *ntn = build_op(CVT, sys, ntp, otn, NULL); ntn->tn_cast = true; - ntn->tn_left = otn; - ntn->tn_right = NULL; return ntn; } } @@ -4046,7 +4042,7 @@ cast_to_union(tnode_t *otn, type_t *ntp) } tnode_t * -cast(tnode_t *tn, type_t *tp) +cast(tnode_t *tn, bool sys, type_t *tp) { if (tn == NULL) @@ -4065,7 +4061,7 @@ cast(tnode_t *tn, type_t *tp) * scalar type to a scalar type. */ } else if (nt == UNION) - return cast_to_union(tn, tp); + return cast_to_union(tn, sys, tp); else if (nt == STRUCT || nt == ARRAY || nt == FUNC) { /* Casting to a struct is an undocumented GCC extension. */ if (!(allow_gcc && nt == STRUCT)) @@ -4099,6 +4095,7 @@ cast(tnode_t *tn, type_t *tp) tn = convert(CVT, 0, tp, tn); tn->tn_cast = true; + tn->tn_sys = sys; return tn;
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Jan 11 23:06:19 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: cgram.y externs1.h tree.c Log Message: lint: correctly set system-header flag on cast-expression When a cast-expression comes partly from a system header, determine at the ')' whether the whole cast-expression comes from the system header. Previously, it was based on the operand, which contradicted the documentation of tn_sys. Mainly affects strict bool mode (where expressions from system headers are handled more leniently), as well as query 9 for parenthesized return expressions. Discovered upon manual inspection, as calling expr_alloc_tnode should never be necessary when creating an expression node with operands; there's build_op for that purpose. To generate a diff of this commit: cvs rdiff -u -r1.478 -r1.479 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.593 -r1.594 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Jan 7 12:20:42 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix memory allocation names, eliminate double negation To generate a diff of this commit: cvs rdiff -u -r1.589 -r1.590 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.589 src/usr.bin/xlint/lint1/tree.c:1.590 --- src/usr.bin/xlint/lint1/tree.c:1.589 Sat Jan 6 15:05:24 2024 +++ src/usr.bin/xlint/lint1/tree.c Sun Jan 7 12:20:42 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.589 2024/01/06 15:05:24 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.590 2024/01/07 12:20:42 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.589 2024/01/06 15:05:24 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.590 2024/01/07 12:20:42 rillig Exp $"); #endif #include @@ -536,13 +536,13 @@ build_string(strg_t *strg) n->tn_type = tp; n->tn_lvalue = true; - n->tn_string = expr_zero_alloc(sizeof(*n->tn_string), "type.string"); + n->tn_string = expr_zero_alloc(sizeof(*n->tn_string), "tnode.string"); n->tn_string->st_char = strg->st_char; n->tn_string->st_len = len; size_t chsize = strg->st_char ? sizeof(char) : sizeof(wchar_t); size_t size = (len + 1) * chsize; - n->tn_string->st_mem = expr_zero_alloc(size, "type.string.data"); + n->tn_string->st_mem = expr_zero_alloc(size, "tnode.string.data"); (void)memcpy(n->tn_string->st_mem, strg->st_mem, size); free(strg->st_mem); free(strg); @@ -759,18 +759,18 @@ balance(op_t op, tnode_t **lnp, tnode_t } static tnode_t * -build_address(bool sys, tnode_t *tn, bool noign) +build_address(bool sys, tnode_t *tn, bool force) { tspec_t t; - if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { + if (!force && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { if (!allow_c90) /* '&' before array or function: ignored */ warning(127); return tn; } - /* eliminate &* */ + /* eliminate '&*' */ if (tn->tn_op == INDIR && tn->tn_left->tn_type->t_tspec == PTR && tn->tn_left->tn_type->t_subt == tn->tn_type) {
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sun Jan 7 12:20:42 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix memory allocation names, eliminate double negation To generate a diff of this commit: cvs rdiff -u -r1.589 -r1.590 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 6 14:21:26 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: remove redundant comments To generate a diff of this commit: cvs rdiff -u -r1.587 -r1.588 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.587 src/usr.bin/xlint/lint1/tree.c:1.588 --- src/usr.bin/xlint/lint1/tree.c:1.587 Sun Dec 3 18:17:41 2023 +++ src/usr.bin/xlint/lint1/tree.c Sat Jan 6 14:21:26 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.587 2023/12/03 18:17:41 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.588 2024/01/06 14:21:26 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.587 2023/12/03 18:17:41 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.588 2024/01/06 14:21:26 rillig Exp $"); #endif #include @@ -707,10 +707,6 @@ usual_arithmetic_conversion_c90(tspec_t if (lt == FLOAT || rt == FLOAT) return FLOAT; - /* - * If type A has more bits than type B, it should be able to hold all - * possible values of type B. - */ if (size_in_bits(lt) > size_in_bits(rt)) return lt; if (size_in_bits(lt) < size_in_bits(rt)) @@ -762,9 +758,6 @@ balance(op_t op, tnode_t **lnp, tnode_t *rnp = apply_usual_arithmetic_conversions(op, *rnp, t); } -/* - * Create a tree node for the unary & operator - */ static tnode_t * build_address(bool sys, tnode_t *tn, bool noign) { @@ -938,9 +931,6 @@ fold(tnode_t *tn) return cn; } -/* - * Create a new node for one of the operators POINT and ARROW. - */ static tnode_t * build_struct_access(op_t op, bool sys, tnode_t *ln, tnode_t *rn) { @@ -1035,9 +1025,6 @@ subt_size_in_bytes(type_t *tp) (int64_t)(elem * elsz_in_bits / CHAR_SIZE)); } -/* - * Create a node for INCAFT, INCBEF, DECAFT and DECBEF. - */ static tnode_t * build_prepost_incdec(op_t op, bool sys, tnode_t *ln) { @@ -1080,11 +1067,6 @@ check_enum_array_index(const tnode_t *ln if (max_enum_value == max_array_index) return; - /* - * If the name of the largest enum constant contains 'MAX' or 'NUM', - * that constant is typically not part of the allowed enum values but a - * marker for the number of actual enum values. - */ if (max_enum_value == max_array_index + 1 && (strstr(max_ec->s_name, "MAX") != NULL || strstr(max_ec->s_name, "max") != NULL || @@ -1097,14 +1079,10 @@ check_enum_array_index(const tnode_t *ln print_previous_declaration(max_ec); } -/* - * Create a node for operators PLUS and MINUS. - */ static tnode_t * build_plus_minus(op_t op, bool sys, tnode_t *ln, tnode_t *rn) { - /* If pointer and integer, move the pointer to the left. */ if (rn->tn_type->t_tspec == PTR && is_integer(ln->tn_type->t_tspec)) { tnode_t *tmp = ln; ln = rn; @@ -1150,9 +1128,6 @@ build_plus_minus(op_t op, bool sys, tnod return build_op(op, sys, ln->tn_type, ln, rn); } -/* - * Create a node for operators SHL and SHR. - */ static tnode_t * build_bit_shift(op_t op, bool sys, tnode_t *ln, tnode_t *rn) { @@ -1207,7 +1182,6 @@ merge_qualifiers(type_t *tp1, const type static tnode_t * build_colon(bool sys, tnode_t *ln, tnode_t *rn) { - tspec_t lt = ln->tn_type->t_tspec; tspec_t rt = rn->tn_type->t_tspec; @@ -1220,7 +1194,6 @@ build_colon(bool sys, tnode_t *ln, tnode } else if (lt == VOID || rt == VOID) { tp = gettyp(VOID); } else if (is_struct_or_union(lt)) { - /* Both types must be identical. */ lint_assert(is_struct_or_union(rt)); lint_assert(ln->tn_type->t_sou == rn->tn_type->t_sou); if (is_incomplete(ln->tn_type)) { @@ -1316,7 +1289,6 @@ is_assignment(op_t op) op == INIT; } -/* Create a node for an assignment operator (both '=' and 'op='). */ static tnode_t * build_assignment(op_t op, bool sys, tnode_t *ln, tnode_t *rn) { @@ -1378,9 +1350,6 @@ build_assignment(op_t op, bool sys, tnod return build_op(op, sys, ln->tn_type, ln, rn); } -/* - * Create a node for REAL, IMAG - */ static tnode_t * build_real_imag(op_t op, bool sys, tnode_t *ln) { @@ -1683,16 +1652,8 @@ build_binary(tnode_t *ln, op_t op, bool if (ln == NULL || (mp->m_binary && rn == NULL)) return NULL; - /* - * Apply class conversions to the left operand, but only if its value - * is needed or compared with zero. - */ if (mp->m_value_context || mp->m_compares_with_zero) ln = cconv(ln); - /* - * The right operand is almost always in a test or value context, - * except if it is a struct or union member. - */ if (mp->m_binary && op != ARROW && op != POINT) rn = cconv(rn); @@ -1713,11 +1674,6 @@ build_binary(tnode_t *ln, op_t op, bool rn = promote(op, false, rn); } - /* - * If the result of the operation is different for signed or unsigned - * operands and one of the
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Jan 6 14:21:26 UTC 2024 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: remove redundant comments To generate a diff of this commit: cvs rdiff -u -r1.587 -r1.588 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Dec 2 21:53:15 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: extract nonportable char comparison to separate function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.582 -r1.583 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.582 src/usr.bin/xlint/lint1/tree.c:1.583 --- src/usr.bin/xlint/lint1/tree.c:1.582 Sat Dec 2 21:47:05 2023 +++ src/usr.bin/xlint/lint1/tree.c Sat Dec 2 21:53:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.582 2023/12/02 21:47:05 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.583 2023/12/02 21:53:15 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.582 2023/12/02 21:47:05 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.583 2023/12/02 21:53:15 rillig Exp $"); #endif #include @@ -576,6 +576,33 @@ is_out_of_char_range(const tnode_t *tn) tn->tn_val.u.integer < 1 << (CHAR_SIZE - 1)); } +static bool +check_nonportable_char_comparison(op_t op, + const tnode_t *ln, tspec_t lt, + const tnode_t *rn, tspec_t rt) +{ + if (!(hflag || pflag)) + return true; + + if (lt == CHAR && is_out_of_char_range(rn)) { + char buf[128]; + (void)snprintf(buf, sizeof(buf), "%s %d", + op_name(op), (int)rn->tn_val.u.integer); + /* nonportable character comparison '%s' */ + warning(230, buf); + return false; + } + if (rt == CHAR && is_out_of_char_range(ln)) { + char buf[128]; + (void)snprintf(buf, sizeof(buf), "%d %s ?", + (int)ln->tn_val.u.integer, op_name(op)); + /* nonportable character comparison '%s' */ + warning(230, buf); + return false; + } + return true; +} + static void check_integer_comparison(op_t op, tnode_t *ln, tnode_t *rn) { @@ -604,24 +631,8 @@ check_integer_comparison(op_t op, tnode_ } } - if (hflag || pflag) { - if (lt == CHAR && is_out_of_char_range(rn)) { - char buf[128]; - (void)snprintf(buf, sizeof(buf), "%s %d", - op_name(op), (int)rn->tn_val.u.integer); - /* nonportable character comparison '%s' */ - warning(230, buf); - return; - } - if (rt == CHAR && is_out_of_char_range(ln)) { - char buf[128]; - (void)snprintf(buf, sizeof(buf), "%d %s ?", - (int)ln->tn_val.u.integer, op_name(op)); - /* nonportable character comparison '%s' */ - warning(230, buf); - return; - } - } + if (!check_nonportable_char_comparison(op, ln, lt, rn, rt)) + return; if (is_uinteger(lt) && !is_uinteger(rt) && rn->tn_op == CON && rn->tn_val.u.integer <= 0) {
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Dec 2 21:53:15 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: lint: extract nonportable char comparison to separate function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.582 -r1.583 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Dec 2 21:47:05 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: debug.c decl.c lex.c lint1.h tree.c Log Message: lint: rename NOSCL to NO_SCL For symmetry with NO_TSPEC. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.379 -r1.380 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.192 -r1.193 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.202 -r1.203 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.581 -r1.582 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.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Sat Dec 2 21:47:05 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: debug.c decl.c lex.c lint1.h tree.c Log Message: lint: rename NOSCL to NO_SCL For symmetry with NO_TSPEC. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.379 -r1.380 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.192 -r1.193 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.202 -r1.203 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.581 -r1.582 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/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.63 src/usr.bin/xlint/lint1/debug.c:1.64 --- src/usr.bin/xlint/lint1/debug.c:1.63 Tue Oct 17 19:29:09 2023 +++ src/usr.bin/xlint/lint1/debug.c Sat Dec 2 21:47:05 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.63 2023/10/17 19:29:09 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.64 2023/12/02 21:47:05 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.63 2023/10/17 19:29:09 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.64 2023/12/02 21:47:05 rillig Exp $"); #endif #include @@ -385,7 +385,7 @@ debug_sym(const char *prefix, const sym_ debug_word(sym->s_osdef, "old-style"); debug_word(sym->s_inline, "inline"); debug_word(sym->s_ext_sym != NULL, "has-external"); - debug_word(sym->s_scl != NOSCL, scl_name(sym->s_scl)); + debug_word(sym->s_scl != NO_SCL, scl_name(sym->s_scl)); debug_word(sym->s_keyword == NULL, def_name(sym->s_def)); if (sym->s_def_pos.p_file != NULL) @@ -441,7 +441,7 @@ debug_decl_level(const decl_level *dl) { debug_printf("kind=%s", decl_level_kind_name(dl->d_kind)); - if (dl->d_scl != NOSCL) + if (dl->d_scl != NO_SCL) debug_printf(" %s", scl_name(dl->d_scl)); if (dl->d_type != NULL) debug_printf(" '%s'", type_name(dl->d_type)); Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.379 src/usr.bin/xlint/lint1/decl.c:1.380 --- src/usr.bin/xlint/lint1/decl.c:1.379 Thu Sep 14 21:53:02 2023 +++ src/usr.bin/xlint/lint1/decl.c Sat Dec 2 21:47:05 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.379 2023/09/14 21:53:02 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.380 2023/12/02 21:47:05 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.379 2023/09/14 21:53:02 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.380 2023/12/02 21:47:05 rillig Exp $"); #endif #include @@ -206,7 +206,7 @@ dcs_add_storage_class(scl_t sc) warning(83); } - if (dcs->d_scl == NOSCL) + if (dcs->d_scl == NO_SCL) dcs->d_scl = sc; else if ((dcs->d_scl == EXTERN && sc == THREAD_LOCAL) || (dcs->d_scl == THREAD_LOCAL && sc == EXTERN)) @@ -607,7 +607,7 @@ dcs_begin_type(void) dcs->d_complex_mod = NO_TSPEC; dcs->d_sign_mod = NO_TSPEC; dcs->d_rank_mod = NO_TSPEC; - dcs->d_scl = NOSCL; + dcs->d_scl = NO_SCL; dcs->d_type = NULL; dcs->d_redeclared_symbol = NULL; dcs->d_qual = (type_qualifiers) { .tq_const = false }; @@ -630,14 +630,14 @@ dcs_adjust_storage_class(void) if (dcs->d_scl == REG || dcs->d_scl == AUTO) { /* illegal storage class */ error(8); - dcs->d_scl = NOSCL; + dcs->d_scl = NO_SCL; } } else if (dcs->d_kind == DLK_OLD_STYLE_PARAMS || dcs->d_kind == DLK_PROTO_PARAMS) { - if (dcs->d_scl != NOSCL && dcs->d_scl != REG) { + if (dcs->d_scl != NO_SCL && dcs->d_scl != REG) { /* only 'register' is valid as storage class ... */ error(9); - dcs->d_scl = NOSCL; + dcs->d_scl = NO_SCL; } } } @@ -1431,9 +1431,9 @@ check_function_definition(sym_t *sym, bo sym_t * declarator_name(sym_t *sym) { - scl_t sc = NOSCL; + scl_t sc = NO_SCL; - if (sym->s_scl == NOSCL) + if (sym->s_scl == NO_SCL) dcs->d_redeclared_symbol = NULL; else if (sym->s_defparam) { sym->s_defparam = false; @@ -1458,7 +1458,7 @@ declarator_name(sym_t *sym) * or this is a function definition. */ sc = dcs->d_scl; - if (sc == NOSCL || sc == THREAD_LOCAL) { + if (sc == NO_SCL || sc == THREAD_LOCAL) { sc = EXTERN; sym->s_def = TDEF; } else if (sc == STATIC) @@ -1474,13 +1474,13 @@ declarator_name(sym_t *sym) sym->s_param = true; /* FALLTHROUGH */ case DLK_OLD_STYLE_PARAMS: - lint_assert(dcs->d_scl == NOSCL || dcs->d_scl == REG); + lint_assert(dcs->d_scl == NO_SCL || dcs->d_scl == REG); sym->s_register = dcs->d_scl == REG; sc = AUTO; sym->s_def = DEF; break; case DLK_AUTO: - if ((sc = dcs->d_scl) == NOSCL) { + if ((sc = dcs->d_scl) == NO_SCL) { /* * XXX somewhat ugly because we don't know whether this * is AUTO or EXTERN (functions). If we are wrong, it @@ -1504,7
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Oct 17 19:33:16 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: resolve shift/reduce conflict in labels with attributes To generate a diff of this commit: cvs rdiff -u -r1.475 -r1.476 src/usr.bin/xlint/lint1/cgram.y 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.475 src/usr.bin/xlint/lint1/cgram.y:1.476 --- src/usr.bin/xlint/lint1/cgram.y:1.475 Tue Oct 17 19:29:09 2023 +++ src/usr.bin/xlint/lint1/cgram.y Tue Oct 17 19:33:16 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.475 2023/10/17 19:29:09 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.476 2023/10/17 19:33:16 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.475 2023/10/17 19:29:09 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.476 2023/10/17 19:33:16 rillig Exp $"); #endif #include @@ -132,7 +132,7 @@ is_either(const char *s, const char *a, %} -%expect 104 +%expect 103 %union { val_t *y_val; @@ -386,7 +386,9 @@ is_either(const char *s, const char *a, /* No type for init_rbrace. */ %type asm_or_symbolrename_opt /* No type for statement. */ +/* No type for no_attr_statement. */ /* No type for non_expr_statement. */ +/* No type for no_attr_non_expr_statement. */ /* No type for labeled_statement. */ /* No type for label. */ /* No type for compound_statement. */ @@ -1752,9 +1754,20 @@ statement: | non_expr_statement ; +/* Helper to avoid shift/reduce conflict in 'label: __attribute__ ;'. */ +no_attr_statement: + expression_statement +| no_attr_non_expr_statement +; + non_expr_statement: /* helper for C99 6.8 */ gcc_attribute_specifier /* ((__fallthrough__)) */ T_SEMI -| labeled_statement +| no_attr_non_expr_statement +; + +/* Helper to avoid shift/reduce conflict in 'label: __attribute__ ;'. */ +no_attr_non_expr_statement: + labeled_statement | compound_statement | selection_statement | iteration_statement @@ -1765,7 +1778,7 @@ non_expr_statement: /* helper for C99 6 ; labeled_statement: /* C99 6.8.1 */ - label gcc_attribute_specifier_list_opt statement + label gcc_attribute_specifier_list_opt no_attr_statement ; label:
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Oct 17 19:33:16 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y Log Message: lint: resolve shift/reduce conflict in labels with attributes To generate a diff of this commit: cvs rdiff -u -r1.475 -r1.476 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Oct 17 19:29:09 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y debug.c Log Message: lint: fix debug output of convert/cast operators The default name of the 'CVT' operator is 'convert', therefore the override is only needed for 'cast'. To generate a diff of this commit: cvs rdiff -u -r1.474 -r1.475 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/lint1/debug.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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.474 src/usr.bin/xlint/lint1/cgram.y:1.475 --- src/usr.bin/xlint/lint1/cgram.y:1.474 Thu Sep 14 22:20:08 2023 +++ src/usr.bin/xlint/lint1/cgram.y Tue Oct 17 19:29:09 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.475 2023/10/17 19:29:09 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.475 2023/10/17 19:29:09 rillig Exp $"); #endif #include @@ -159,7 +159,7 @@ is_either(const char *s, const char *a, /* for Bison: %printer { if (is_integer($$->v_tspec)) - fprintf(yyo, "%lld", (unsigned long long)$$->u.integer); + fprintf(yyo, "%lld", (long long)$$->u.integer); else fprintf(yyo, "%Lg", $$->u.floating); } @@ -2280,8 +2280,8 @@ cgram_declare(sym_t *decl, bool has_init } /* - * Discard all input tokens up to and including the next - * unmatched right paren + * Discard all input tokens up to and including the next unmatched right + * parenthesis. */ static void read_until_rparen(void) Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.62 src/usr.bin/xlint/lint1/debug.c:1.63 --- src/usr.bin/xlint/lint1/debug.c:1.62 Wed Sep 13 20:31:58 2023 +++ src/usr.bin/xlint/lint1/debug.c Tue Oct 17 19:29:09 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.62 2023/09/13 20:31:58 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.63 2023/10/17 19:29:09 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.62 2023/09/13 20:31:58 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.63 2023/10/17 19:29:09 rillig Exp $"); #endif #include @@ -187,16 +187,15 @@ debug_type(const type_t *tp) void debug_node(const tnode_t *tn) // NOLINT(misc-no-recursion) { - op_t op; if (tn == NULL) { debug_step("null"); return; } - op = tn->tn_op; + op_t op = tn->tn_op; debug_printf("'%s'", - op == CVT && !tn->tn_cast ? "convert" : op_name(op)); + op == CVT && tn->tn_cast ? "cast" : op_name(op)); if (op == NAME) debug_printf(" '%s' with %s", tn->tn_sym->s_name,
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Tue Oct 17 19:29:09 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y debug.c Log Message: lint: fix debug output of convert/cast operators The default name of the 'CVT' operator is 'convert', therefore the override is only needed for 'cast'. To generate a diff of this commit: cvs rdiff -u -r1.474 -r1.475 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.62 -r1.63 src/usr.bin/xlint/lint1/debug.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 22:48:49 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: op.h Log Message: lint: reduce pointer dereferences and relocations No functional change. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint1/op.h 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/op.h diff -u src/usr.bin/xlint/lint1/op.h:1.24 src/usr.bin/xlint/lint1/op.h:1.25 --- src/usr.bin/xlint/lint1/op.h:1.24 Thu Sep 14 22:20:08 2023 +++ src/usr.bin/xlint/lint1/op.h Thu Sep 14 22:48:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: op.h,v 1.24 2023/09/14 22:20:08 rillig Exp $ */ +/* $NetBSD: op.h,v 1.25 2023/09/14 22:48:49 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -57,7 +57,7 @@ typedef struct { bool m_bad_on_enum: 1; bool m_warn_if_operand_eq: 1; bool m_has_operands: 1; - const char *m_name; + const char m_name[8]; } mod_t; typedef enum {
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 22:48:49 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: op.h Log Message: lint: reduce pointer dereferences and relocations No functional change. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint1/op.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 22:20:09 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y op.h oper.c scan.l Log Message: lint: remove pseudo operators INC and DEC These operators were not used in expressions, they were only used as additional token info. Use a plain bool instead. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.473 -r1.474 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.139 -r1.140 src/usr.bin/xlint/lint1/scan.l Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 22:20:09 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: cgram.y op.h oper.c scan.l Log Message: lint: remove pseudo operators INC and DEC These operators were not used in expressions, they were only used as additional token info. Use a plain bool instead. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.473 -r1.474 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.139 -r1.140 src/usr.bin/xlint/lint1/scan.l 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.473 src/usr.bin/xlint/lint1/cgram.y:1.474 --- src/usr.bin/xlint/lint1/cgram.y:1.473 Thu Sep 14 21:53:02 2023 +++ src/usr.bin/xlint/lint1/cgram.y Thu Sep 14 22:20:08 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.473 2023/09/14 21:53:02 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.473 2023/09/14 21:53:02 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.474 2023/09/14 22:20:08 rillig Exp $"); #endif #include @@ -138,6 +138,7 @@ is_either(const char *s, const char *a, val_t *y_val; sbuf_t *y_name; sym_t *y_sym; + bool y_inc; op_t y_op; scl_t y_scl; tspec_t y_tspec; @@ -168,6 +169,7 @@ is_either(const char *s, const char *a, debug_sym("", $$, ""); debug_pop_indented(indented); } +%printer { fprintf(yyo, "%s", $$ ? "++" : "--"); } %printer { fprintf(yyo, "%s", op_name($$)); } %printer { fprintf(yyo, "%s", scl_name($$)); } %printer { fprintf(yyo, "%s", tspec_name($$)); } @@ -197,7 +199,7 @@ is_either(const char *s, const char *a, %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN %token T_POINT T_ARROW %token T_COMPLEMENT T_LOGNOT -%token T_INCDEC +%token T_INCDEC %token T_SIZEOF %token T_BUILTIN_OFFSETOF %token T_TYPEOF @@ -551,7 +553,7 @@ postfix_expression: $$ = build_member_access($1, $2, $3, $4); } | postfix_expression T_INCDEC sys { - $$ = build_unary($2 == INC ? INCAFT : DECAFT, $3, $1); + $$ = build_unary($2 ? INCAFT : DECAFT, $3, $1); } | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */ sym_t *tmp = mktempsym($2); @@ -643,7 +645,7 @@ argument_expression_list: unary_expression: postfix_expression | T_INCDEC sys unary_expression { - $$ = build_unary($1 == INC ? INCBEF : DECBEF, $2, $3); + $$ = build_unary($1 ? INCBEF : DECBEF, $2, $3); } | T_AMPER sys cast_expression { $$ = build_unary(ADDR, $2, $3); @@ -2244,6 +2246,7 @@ cgram_to_string(int token, YYSTYPE val) switch (token) { case T_INCDEC: + return val.y_inc ? "++" : "--"; case T_MULTIPLICATIVE: case T_ADDITIVE: case T_SHIFT: Index: src/usr.bin/xlint/lint1/op.h diff -u src/usr.bin/xlint/lint1/op.h:1.23 src/usr.bin/xlint/lint1/op.h:1.24 --- src/usr.bin/xlint/lint1/op.h:1.23 Thu Sep 14 21:08:12 2023 +++ src/usr.bin/xlint/lint1/op.h Thu Sep 14 22:20:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: op.h,v 1.23 2023/09/14 21:08:12 rillig Exp $ */ +/* $NetBSD: op.h,v 1.24 2023/09/14 22:20:08 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -66,8 +66,6 @@ typedef enum { POINT, NOT, COMPL, - INC, /* does not appear in the tree */ - DEC, /* does not appear in the tree */ INCBEF, DECBEF, INCAFT, Index: src/usr.bin/xlint/lint1/oper.c diff -u src/usr.bin/xlint/lint1/oper.c:1.13 src/usr.bin/xlint/lint1/oper.c:1.14 --- src/usr.bin/xlint/lint1/oper.c:1.13 Thu Sep 14 21:08:12 2023 +++ src/usr.bin/xlint/lint1/oper.c Thu Sep 14 22:20:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: oper.c,v 1.13 2023/09/14 21:08:12 rillig Exp $ */ +/* $NetBSD: oper.c,v 1.14 2023/09/14 22:20:08 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -68,8 +68,6 @@ const mod_t modtab[NOPS] = { {X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "." }, {_,X,X,X,_,_,_,X,X,_,_,_,_,_,_,_,_,X,_,X, "!" }, {_,_,_,_,_,X,_,_,X,X,_,_,_,_,_,_,_,X,X,X, "~" }, - {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "++" }, - {_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X, "--" }, /* * The '++' and '--' operators are conceptually unary operators, but * lint implements them as binary operators due to the pre-multiplied Index: src/usr.bin/xlint/lint1/scan.l diff -u src/usr.bin/xlint/lint1/scan.l:1.139 src/usr.bin/xlint/lint1/scan.l:1.140 --- src/usr.bin/xlint/lint1/scan.l:1.139 Thu Jul 13 08:40:38 2023 +++ src/usr.bin/xlint/lint1/scan.l Thu Sep 14 22:20:08 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.139 2023/07/13 08:40:38 rillig Exp $ */ +/* $NetBSD: scan.l,v 1.140 2023/09/14 22:20:08 rillig Exp $ */ /* * Copyright (c) 1996
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 21:08:12 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: README.md lint1.h op.h oper.c Removed Files: src/usr.bin/xlint/lint1: ops.def Log Message: lint: remove preprocessor magic from definition of operators No binary change. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.31 -r0 src/usr.bin/xlint/lint1/ops.def 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/README.md diff -u src/usr.bin/xlint/lint1/README.md:1.13 src/usr.bin/xlint/lint1/README.md:1.14 --- src/usr.bin/xlint/lint1/README.md:1.13 Wed Aug 2 18:51:25 2023 +++ src/usr.bin/xlint/lint1/README.md Thu Sep 14 21:08:12 2023 @@ -1,4 +1,4 @@ -[//]: # ($NetBSD: README.md,v 1.13 2023/08/02 18:51:25 rillig Exp $) +[//]: # ($NetBSD: README.md,v 1.14 2023/09/14 21:08:12 rillig Exp $) # Introduction @@ -105,7 +105,7 @@ it needs to be copied using `block_dup_t When lint parses an expression, it builds a tree of nodes representing the AST. Each node has an operator that defines which other members may be accessed. -The operators and their properties are defined in `ops.def`. +The operators and their properties are defined in `oper.c`. Some examples for operators: | Operator | Meaning| Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.201 src/usr.bin/xlint/lint1/lint1.h:1.202 --- src/usr.bin/xlint/lint1/lint1.h:1.201 Wed Sep 13 20:31:58 2023 +++ src/usr.bin/xlint/lint1/lint1.h Thu Sep 14 21:08:12 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.201 2023/09/13 20:31:58 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.202 2023/09/14 21:08:12 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -111,7 +111,7 @@ typedef struct { * Set if an integer constant is unsigned only in C90 and later, but * not in traditional C. * - * See the operators table in ops.def, columns "l r". + * See the operators table in oper.c, columns "l r". */ bool v_unsigned_since_c90; bool v_char_constant; Index: src/usr.bin/xlint/lint1/op.h diff -u src/usr.bin/xlint/lint1/op.h:1.22 src/usr.bin/xlint/lint1/op.h:1.23 --- src/usr.bin/xlint/lint1/op.h:1.22 Wed Sep 13 20:31:58 2023 +++ src/usr.bin/xlint/lint1/op.h Thu Sep 14 21:08:12 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: op.h,v 1.22 2023/09/13 20:31:58 rillig Exp $ */ +/* $NetBSD: op.h,v 1.23 2023/09/14 21:08:12 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -34,7 +34,7 @@ #include /* - * Various information about operators; see ops.def. + * Various information about operators. */ typedef struct { bool m_binary: 1; @@ -60,17 +60,87 @@ typedef struct { const char *m_name; } mod_t; -extern const mod_t modtab[]; +typedef enum { + NOOP, + ARROW, + POINT, + NOT, + COMPL, + INC, /* does not appear in the tree */ + DEC, /* does not appear in the tree */ + INCBEF, + DECBEF, + INCAFT, + DECAFT, + UPLUS, + UMINUS, + INDIR, + ADDR, -#define begin_ops() typedef enum { -#define op(name, repr, \ - is_binary, is_logical, takes_bool, requires_bool, \ - is_integer, is_complex, is_arithmetic, is_scalar, \ - can_fold, is_value, unused, balances_operands, \ - side_effects, left_unsigned, right_unsigned, \ - precedence_confusion, is_comparison, \ - valid_on_enum, bad_on_enum, warn_if_eq, \ - has_operands) \ - name, -#define end_ops() } op_t; -#include "ops.def" + MULT, + DIV, + MOD, + PLUS, + MINUS, + SHL, + SHR, + + LT, + LE, + GT, + GE, + EQ, + NE, + + BITAND, + BITXOR, + BITOR, + LOGAND, + LOGOR, + QUEST, + COLON, + + ASSIGN, + MULASS, + DIVASS, + MODASS, + ADDASS, + SUBASS, + SHLASS, + SHRASS, + ANDASS, + XORASS, + ORASS, + + NAME, + CON, + STRING, + FSEL, + CALL, + COMMA, + CVT, + ICALL, + LOAD, + /* + * PUSH is a virtual node that is used to concatenate arguments in a + * function call expression. The PUSH nodes are ordered from right to + * left. For example, the function call f(17, 23) is represented as + * CALL(f, PUSH(23, PUSH(17, NULL))). + */ + PUSH, + RETURN, + REAL, + IMAG, + + INIT, /* does not appear in the tree */ + CASE, /* does not appear in the tree */ + /* + * FARG is only used temporarily in check_prototype_argument to check + * type compatibility and conversion for function arguments. + */ + FARG, /* does not appear in the tree */ +} op_t; + +#define NOPS ((int)FARG + 1) + +extern const mod_t modtab[NOPS]; Index: src/usr.bin/xlint/lint1/oper.c diff -u src/usr.bin/xlint/lint1/oper.c:1.12 src/usr.bin/xlint/lint1/oper.c:1.13 --- src/usr.bin/xlint/lint1/oper.c:1.12 Wed Sep 13 20:31:58 2023 +++
CVS commit: src/usr.bin/xlint/lint1
Module Name:src Committed By: rillig Date: Thu Sep 14 21:08:12 UTC 2023 Modified Files: src/usr.bin/xlint/lint1: README.md lint1.h op.h oper.c Removed Files: src/usr.bin/xlint/lint1: ops.def Log Message: lint: remove preprocessor magic from definition of operators No binary change. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/README.md cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.31 -r0 src/usr.bin/xlint/lint1/ops.def Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.