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 <sys/cdefs.h> #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 <limits.h> @@ -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&R ???, 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 end_type notype_init_declarators T_SEMI { /* TODO: Make this an error in C99 mode as well. */ - if (!allow_trad && !allow_c99) { + if (!allow_trad && !allow_c99) /* old-style declaration; add 'int' */ error(1); - } else if (allow_c90) { + else if (allow_c90) /* old-style declaration; add 'int' */ warning(1); - } } | declaration | error T_SEMI { @@ -2113,17 +2103,15 @@ function_definition: /* C99 6.9.1 */ func_declarator: begin_type end_type notype_declarator { - if (!allow_trad) { + if (!allow_trad) /* old-style declaration; add 'int' */ error(1); - } $$ = $3; } | begin_type_declmods end_type notype_declarator { - if (!allow_trad) { + if (!allow_trad) /* old-style declaration; add 'int' */ error(1); - } $$ = $3; } | begin_type_declaration_specifiers end_type type_declarator { @@ -2154,20 +2142,18 @@ arg_declaration: } | begin_type_declmods end_type notype_init_declarators T_SEMI | begin_type_declaration_specifiers end_type T_SEMI { - if (!dcs->d_nonempty_decl) { + if (!dcs->d_nonempty_decl) /* empty declaration */ warning(2); - } else { + else /* '%s' declared in parameter declaration list */ warning(3, type_name(dcs->d_type)); - } } | begin_type_declaration_specifiers end_type type_init_declarators T_SEMI { - if (dcs->d_nonempty_decl) { + if (dcs->d_nonempty_decl) /* '%s' declared in parameter declaration list */ warning(3, type_name(dcs->d_type)); - } } | begin_type_declmods error | begin_type_declaration_specifiers error Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.391 src/usr.bin/xlint/lint1/decl.c:1.392 --- src/usr.bin/xlint/lint1/decl.c:1.391 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/decl.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.391 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.392 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: decl.c,v 1.391 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.392 2024/02/08 20:45:20 rillig Exp $"); #endif #include <sys/param.h> @@ -195,10 +195,9 @@ dcs_add_storage_class(scl_t sc) { if (dcs->d_type != NULL || dcs->d_abstract_type != NO_TSPEC || - dcs->d_sign_mod != NO_TSPEC || dcs->d_rank_mod != NO_TSPEC) { + dcs->d_sign_mod != NO_TSPEC || dcs->d_rank_mod != NO_TSPEC) /* storage class after type is obsolescent */ warning(83); - } if (dcs->d_scl == NO_SCL) dcs->d_scl = sc; @@ -674,10 +673,9 @@ dcs_merge_declaration_specifiers(void) l = NO_TSPEC; t = LDOUBLE; } - if (t == LDOUBLE && !allow_c90) { + if (t == LDOUBLE && !allow_c90) /* 'long double' is illegal in traditional C */ warning(266); - } if (l == LONG && t == DCOMPLEX) { l = NO_TSPEC; t = LCOMPLEX; @@ -701,14 +699,12 @@ dcs_end_type(void) dcs_merge_declaration_specifiers(); - if (dcs->d_multiple_storage_classes) { + if (dcs->d_multiple_storage_classes) /* only one storage class allowed */ error(7); - } - if (dcs->d_invalid_type_combination) { + if (dcs->d_invalid_type_combination) /* illegal type combination */ error(4); - } dcs_adjust_storage_class(); @@ -757,10 +753,9 @@ length_in_bits(const type_t *tp, const c } if (is_struct_or_union(tp->t_tspec)) { - if (is_incomplete(tp) && name != NULL) { + if (is_incomplete(tp) && name != NULL) /* '%s' has incomplete type '%s' */ error(31, name, type_name(tp)); - } return (int)(elem * tp->t_sou->sou_size_in_bits); } @@ -1099,10 +1094,9 @@ declare_member(sym_t *dsym) * type the bit-field is packed in (it's ok) */ int sz = length_in_bits(dsym->s_type, dsym->s_name); - if (sz == 0 && t == ARRAY && dsym->s_type->t_dim == 0) { + if (sz == 0 && t == ARRAY && dsym->s_type->t_dim == 0) /* zero-sized array '%s' in struct requires C99 or later */ c99ism(39, dsym->s_name); - } dcs_add_member(dsym); @@ -1235,13 +1229,13 @@ block_derive_array(type_t *stp, bool dim tp->t_subt = gettyp(CHAR); } #endif - if (len < 0) { + if (len < 0) /* negative array dimension (%d) */ error(20, len); - } else if (len == 0 && dim) { + else if (len == 0 && dim) /* zero sized array requires C99 or later */ c99ism(322); - } else if (len == 0 && !dim) + else if (len == 0 && !dim) tp->t_incomplete_array = true; debug_step("%s: '%s'", __func__, type_name(tp)); @@ -1299,10 +1293,9 @@ check_prototype_parameters(sym_t *args) for (sym_t *sym = dcs->d_first_dlsym; sym != NULL; sym = sym->s_level_next) { scl_t sc = sym->s_scl; - if (sc == STRUCT_TAG || sc == UNION_TAG || sc == ENUM_TAG) { + if (sc == STRUCT_TAG || sc == UNION_TAG || sc == ENUM_TAG) /* dubious tag declaration '%s %s' */ warning(85, tag_name(sc), sym->s_name); - } } for (sym_t *arg = args; arg != NULL; arg = arg->s_next) { @@ -1405,10 +1398,9 @@ check_function_definition(sym_t *sym, bo { if (sym->s_osdef) { - if (msg) { + if (msg) /* incomplete or misplaced function definition */ error(22); - } sym->s_osdef = false; sym->u.s_old_style_params = NULL; } @@ -1550,10 +1542,9 @@ new_tag(sym_t *tag, scl_t scl, bool decl warning(44, tag_name(scl), tag->s_name); tag = pushdown(tag); - } else if (tag->s_scl != scl) { + } else if (tag->s_scl != scl) /* base type is really '%s %s' */ warning(45, tag_name(tag->s_scl), tag->s_name); - } dcs->d_enclosing->d_nonempty_decl = true; } else if (decl) { /* "struct a { ... } " */ @@ -1566,10 +1557,9 @@ new_tag(sym_t *tag, scl_t scl, bool decl /* base type is really '%s %s' */ warning(45, tag_name(tag->s_scl), tag->s_name); /* XXX: Why is this warning suppressed in C90 mode? */ - if (allow_trad || allow_c99) { + if (allow_trad || allow_c99) /* declaration of '%s %s' introduces ... */ warning(44, tag_name(scl), tag->s_name); - } tag = pushdown(tag); dcs->d_enclosing->d_nonempty_decl = true; } @@ -1699,13 +1689,12 @@ complete_struct_or_union(sym_t *first_me else sou->sou_size_in_bits = dcs->d_sou_size_in_bits; - if (sou->sou_size_in_bits == 0) { + if (sou->sou_size_in_bits == 0) /* zero sized %s is a C99 feature */ c99ism(47, tspec_name(tp->t_tspec)); - } else if (!has_named_member(tp)) { + else if (!has_named_member(tp)) /* '%s' has no named members */ warning(65, type_name(tp)); - } debug_step("%s: '%s'", __func__, type_name(tp)); return tp; } @@ -1735,10 +1724,10 @@ enumeration_constant(sym_t *sym, int val if (sym->s_scl != NO_SCL) { if (sym->s_block_level == block_level) { /* no hflag, because this is illegal */ - if (sym->s_param) { + if (sym->s_param) /* enumeration constant '%s' hides parameter */ warning(57, sym->s_name); - } else { + else { /* redeclaration of '%s' */ error(27, sym->s_name); /* @@ -1761,10 +1750,9 @@ enumeration_constant(sym_t *sym, int val sym->s_type = dcs->d_tag_type; sym->u.s_enum_constant = val; - if (impl && val == TARG_INT_MIN) { + if (impl && val == TARG_INT_MIN) /* enumeration value '%s' overflows */ warning(48, sym->s_name); - } enumval = val == TARG_INT_MAX ? TARG_INT_MIN : val + 1; debug_sym("enumeration_constant: ", sym, "\n"); @@ -1798,10 +1786,9 @@ check_extern_declaration(const sym_t *sy sym->s_type->t_tspec == FUNC && sym->s_scl == EXTERN && sym->s_def == DECL && - !in_system_header) { + !in_system_header) /* redundant 'extern' in function declaration of '%s' */ query_message(13, sym->s_name); - } } /* @@ -1823,10 +1810,10 @@ check_init(sym_t *sym) return true; } if (sym->s_scl == EXTERN && sym->s_def == DECL) { - if (dcs->d_kind == DLK_EXTERN) { + if (dcs->d_kind == DLK_EXTERN) /* cannot initialize extern declaration '%s' */ warning(26, sym->s_name); - } else { + else { /* cannot initialize extern declaration '%s' */ error(26, sym->s_name); return true; @@ -1880,11 +1867,9 @@ check_old_style_definition(const sym_t * } end: - if (msg && rflag) { + if (msg && rflag) /* old-style definition */ message_at(300, &rdsym->s_def_pos); - } - return msg; } @@ -2015,17 +2000,17 @@ declare(sym_t *decl, bool has_initialize declare_extern(decl, has_initializer, renaming); else if (dcs->d_kind == DLK_OLD_STYLE_PARAMS || dcs->d_kind == DLK_PROTO_PARAMS) { - if (renaming != NULL) { + if (renaming != NULL) /* symbol renaming can't be used on function ... */ error(310); - } else + else (void)declare_parameter(decl, has_initializer); } else { lint_assert(dcs->d_kind == DLK_AUTO); - if (renaming != NULL) { + if (renaming != NULL) /* symbol renaming can't be used on automatic ... */ error(311); - } else + else declare_local(decl, has_initializer); } debug_printf("%s: ", __func__); @@ -2324,10 +2309,9 @@ declare_parameter(sym_t *sym, bool has_i sym->s_param = true; } - if (has_initializer) { + if (has_initializer) /* cannot initialize parameter '%s' */ error(52, sym->s_name); - } if (sym->s_type == NULL) /* for c(void()) */ sym->s_type = gettyp(VOID); @@ -2527,10 +2511,9 @@ check_func_old_style_parameters(void) old_param = old_param->s_next; } } - if (msg && rflag) { + if (msg && rflag) /* prototype declaration */ message_at(285, &dcs->d_redeclared_symbol->s_def_pos); - } /* from now on the prototype is valid */ funcsym->s_osdef = false; @@ -2578,20 +2561,16 @@ check_local_redeclaration(const sym_t *d * produced below */ if (!allow_c90) { - if (hflag) { + if (hflag) /* declaration of '%s' hides ... */ warning(91, dsym->s_name); - } rmsym(rdsym); } } - } else if (rdsym->s_block_level < block_level) { - if (hflag) { - /* declaration of '%s' hides earlier one */ - warning(95, dsym->s_name); - } - } + } else if (rdsym->s_block_level < block_level && hflag) + /* declaration of '%s' hides earlier one */ + warning(95, dsym->s_name); if (rdsym->s_block_level == block_level) { /* redeclaration of '%s' */ @@ -2664,10 +2643,9 @@ declare_local(sym_t *dsym, bool has_init dsym->s_scl = EXTERN; } - if (dsym->s_scl == EXTERN) { + if (dsym->s_scl == EXTERN) /* nested 'extern' declaration of '%s' */ warning(352, dsym->s_name); - } if (dsym->s_type->t_tspec == FUNC) { if (dsym->s_scl == STATIC) { @@ -2735,10 +2713,9 @@ declare_local(sym_t *dsym, bool has_init set_first_typedef(dsym->s_type, dsym); } - if (dsym->s_scl == STATIC && any_query_enabled) { + if (dsym->s_scl == STATIC && any_query_enabled) /* static variable '%s' in function */ query_message(11, dsym->s_name); - } debug_printf("%s: ", __func__); debug_sym("", dsym, "\n"); @@ -2884,10 +2861,9 @@ check_parameter_usage(bool novar, const if (novar) return; - if (!arg->s_used && !vflag) { + if (!arg->s_used && !vflag) /* parameter '%s' unused in function '%s' */ warning_at(231, &arg->s_def_pos, arg->s_name, funcsym->s_name); - } } static void @@ -3028,14 +3004,12 @@ check_global_variable_size(const sym_t * if (sym->s_def != TDEF) return; - if (sym->s_type->t_tspec == FUNC) { + if (sym->s_type->t_tspec == FUNC) /* Maybe a syntax error after a function declaration. */ return; - } - if (sym->s_def == TDEF && sym->s_type->t_tspec == VOID) { + if (sym->s_def == TDEF && sym->s_type->t_tspec == VOID) /* Prevent an internal error in length_in_bits below. */ return; - } pos_t cpos = curr_pos; curr_pos = sym->s_def_pos; @@ -3064,34 +3038,30 @@ check_unused_static_global_variable(cons if (!sym->s_inline) /* static function '%s' unused */ warning_at(236, &sym->s_def_pos, sym->s_name); - } else { + } else /* static function '%s' declared but not defined */ warning_at(290, &sym->s_def_pos, sym->s_name); - } - } else if (!sym->s_set) { + } else if (!sym->s_set) /* static variable '%s' unused */ warning_at(226, &sym->s_def_pos, sym->s_name); - } else { + else /* static variable '%s' set but not used */ warning_at(307, &sym->s_def_pos, sym->s_name); - } } static void check_static_global_variable(const sym_t *sym) { - if (sym->s_type->t_tspec == FUNC && sym->s_used && sym->s_def != DEF) { + if (sym->s_type->t_tspec == FUNC && sym->s_used && sym->s_def != DEF) /* static function '%s' called but not defined */ error_at(225, &sym->s_use_pos, sym->s_name); - } if (!sym->s_used) check_unused_static_global_variable(sym); - if (allow_c90 && sym->s_def == TDEF && sym->s_type->t_const) { + if (allow_c90 && sym->s_def == TDEF && sym->s_type->t_const) /* const object '%s' should have initializer */ warning_at(227, &sym->s_def_pos, sym->s_name); - } } static void @@ -3143,13 +3113,12 @@ print_previous_declaration(const sym_t * if (!rflag) return; - if (psym->s_def == DEF || psym->s_def == TDEF) { + if (psym->s_def == DEF || psym->s_def == TDEF) /* previous definition of '%s' */ message_at(261, &psym->s_def_pos, psym->s_name); - } else { + else /* previous declaration of '%s' */ message_at(260, &psym->s_def_pos, psym->s_name); - } } /* Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.86 src/usr.bin/xlint/lint1/emit1.c:1.87 --- src/usr.bin/xlint/lint1/emit1.c:1.86 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/emit1.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.86 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.86 2024/02/05 23:11:22 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $"); #endif #include <stdlib.h> @@ -346,16 +346,15 @@ outcall(const tnode_t *tn, bool retval_u * explicitly test the sign */ int64_t si = arg->tn_val.u.integer; - if (si == 0) { + if (si == 0) /* zero constant */ outchar('z'); - } else if (!msb(si, t)) { + else if (!msb(si, t)) /* positive if cast to signed */ outchar('p'); - } else { + else /* negative if cast to signed */ outchar('n'); - } outint((int)n); } } else if (arg->tn_op == ADDR && Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.180 src/usr.bin/xlint/lint1/func.c:1.181 --- src/usr.bin/xlint/lint1/func.c:1.180 Sat Feb 3 12:57:12 2024 +++ src/usr.bin/xlint/lint1/func.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.180 2024/02/03 12:57:12 rillig Exp $ */ +/* $NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.180 2024/02/03 12:57:12 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $"); #endif #include <stdlib.h> @@ -621,10 +621,9 @@ stmt_switch_expr(tnode_t *tn) } if (tn != NULL && !allow_c90) { tspec_t t = tn->tn_type->t_tspec; - if (t == LONG || t == ULONG || t == LLONG || t == ULLONG) { + if (t == LONG || t == ULONG || t == LLONG || t == ULLONG) /* switch expression must be of type 'int' in ... */ warning(271); - } } /* @@ -678,10 +677,9 @@ stmt_switch_expr_stmt(void) } for (cl = cstmt->c_case_labels; cl != NULL; cl = cl->cl_next) nclab++; - if (hflag && eflag && nclab < nenum && !cstmt->c_default) { + if (hflag && eflag && nclab < nenum && !cstmt->c_default) /* enumeration value(s) not handled in switch */ warning(206); - } } check_getopt_end_switch(); @@ -934,10 +932,9 @@ check_return_value(bool sys, tnode_t *tn while (rn->tn_op == CVT || rn->tn_op == PLUS) rn = rn->tn_left; if (rn->tn_op == ADDR && rn->tn_left->tn_op == NAME && - rn->tn_left->tn_sym->s_scl == AUTO) { + rn->tn_left->tn_sym->s_scl == AUTO) /* '%s' returns pointer to automatic object */ warning(302, funcsym->s_name); - } } expr(retn, true, false, true, false); @@ -990,31 +987,27 @@ void global_clean_up_decl(bool silent) { if (nargusg != -1) { - if (!silent) { + if (!silent) /* comment ** %s ** must precede function definition */ warning_at(282, &argsused_pos, "ARGSUSED"); - } nargusg = -1; } if (nvararg != -1) { - if (!silent) { + if (!silent) /* comment ** %s ** must precede function definition */ warning_at(282, &vapos, "VARARGS"); - } nvararg = -1; } if (printflike_argnum != -1) { - if (!silent) { + if (!silent) /* comment ** %s ** must precede function definition */ warning_at(282, &printflike_pos, "PRINTFLIKE"); - } printflike_argnum = -1; } if (scanflike_argnum != -1) { - if (!silent) { + if (!silent) /* comment ** %s ** must precede function definition */ warning_at(282, &scanflike_pos, "SCANFLIKE"); - } scanflike_argnum = -1; } @@ -1041,10 +1034,9 @@ argsused(int n) warning(280, "ARGSUSED"); return; } - if (nargusg != -1) { + if (nargusg != -1) /* duplicate comment ** %s ** */ warning(281, "ARGSUSED"); - } nargusg = n != -1 ? n : 0; argsused_pos = curr_pos; } @@ -1057,10 +1049,9 @@ varargs(int n) warning(280, "VARARGS"); return; } - if (nvararg != -1) { + if (nvararg != -1) /* duplicate comment ** %s ** */ warning(281, "VARARGS"); - } nvararg = n != -1 ? n : 0; vapos = curr_pos; } @@ -1077,10 +1068,9 @@ printflike(int n) warning(280, "PRINTFLIKE"); return; } - if (printflike_argnum != -1) { + if (printflike_argnum != -1) /* duplicate comment ** %s ** */ warning(281, "PRINTFLIKE"); - } printflike_argnum = n != -1 ? n : 0; printflike_pos = curr_pos; } @@ -1097,10 +1087,9 @@ scanflike(int n) warning(280, "SCANFLIKE"); return; } - if (scanflike_argnum != -1) { + if (scanflike_argnum != -1) /* duplicate comment ** %s ** */ warning(281, "SCANFLIKE"); - } scanflike_argnum = n != -1 ? n : 0; scanflike_pos = curr_pos; } Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.258 src/usr.bin/xlint/lint1/init.c:1.259 --- src/usr.bin/xlint/lint1/init.c:1.258 Sat Feb 3 19:25:16 2024 +++ src/usr.bin/xlint/lint1/init.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.258 2024/02/03 19:25:16 rillig Exp $ */ +/* $NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.258 2024/02/03 19:25:16 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $"); #endif #include <stdlib.h> @@ -330,10 +330,9 @@ designator_type(const designator *dr, co lint_assert(dr->dr_subscript < (size_t)tp->t_dim); return tp->t_subt; default: - if (dr->dr_kind != DK_SCALAR) { + if (dr->dr_kind != DK_SCALAR) /* syntax error '%s' */ error(249, "scalar type cannot use designator"); - } return tp; } } @@ -549,18 +548,17 @@ static void warn_too_many_initializers(designator_kind kind, const type_t *tp) { - if (kind == DK_MEMBER) { + if (kind == DK_MEMBER) /* too many struct/union initializers */ error(172); - } else if (kind == DK_SUBSCRIPT) { + else if (kind == DK_SUBSCRIPT) { lint_assert(tp->t_tspec == ARRAY); lint_assert(!tp->t_incomplete_array); /* too many array initializers, expected %d */ error(173, tp->t_dim); - } else { + } else /* too many initializers */ error(174); - } } static bool @@ -715,10 +713,9 @@ initialization_lbrace(initialization *in if (!allow_c90 && outer_bl == NULL) check_trad_no_auto_aggregate(in->in_sym); - if (!allow_c90 && tp->t_tspec == UNION) { + if (!allow_c90 && tp->t_tspec == UNION) /* initialization of union is illegal in traditional C */ warning(238); - } if (is_struct_or_union(tp->t_tspec) && tp->t_sou->sou_incomplete) { /* initialization of incomplete type '%s' */ @@ -894,10 +891,9 @@ initialization_init_array_from_string(in continue; } - if (!tp->t_incomplete_array && (size_t)tp->t_dim < len) { + if (!tp->t_incomplete_array && (size_t)tp->t_dim < len) /* string literal too long (%lu) for target array (%lu) */ warning(187, (unsigned long)len, (unsigned long)tp->t_dim); - } brace_level *bl = in->in_brace_level; if (bl != NULL && bl->bl_designation.dn_len == 0) Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.215 src/usr.bin/xlint/lint1/lex.c:1.216 --- src/usr.bin/xlint/lint1/lex.c:1.215 Wed Feb 7 08:00:36 2024 +++ src/usr.bin/xlint/lint1/lex.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.216 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.216 2024/02/08 20:45:20 rillig Exp $"); #endif #include <ctype.h> @@ -587,10 +587,9 @@ lex_integer_constant(const char *yytext, if (u_suffix > 1) u_suffix = 1; } - if (!allow_c90 && u_suffix > 0) { + 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; @@ -604,10 +603,9 @@ lex_integer_constant(const char *yytext, warned = true; } - if (any_query_enabled && base == 8 && ui != 0) { + if (any_query_enabled && base == 8 && ui != 0) /* octal number '%.*s' */ query_message(8, (int)len, cp); - } bool ansiu = is_unsigned_since_c90(ct, ui, base); @@ -663,19 +661,18 @@ lex_floating_constant(const char *yytext } else t = imaginary ? DCOMPLEX : DOUBLE; - if (!allow_c90 && t != DOUBLE) { + if (!allow_c90 && t != DOUBLE) /* suffixes 'F' and 'L' are illegal in traditional C */ warning(98); - } errno = 0; char *eptr; long double ld = strtold(cp, &eptr); lint_assert(eptr == cp + len); - if (errno != 0) { + if (errno != 0) /* floating-point constant out of range */ warning(248); - } else if (t == FLOAT) { + else if (t == FLOAT) { ld = (float)ld; if (isfinite(ld) == 0) { /* floating-point constant out of range */ @@ -975,13 +972,12 @@ lex_character_constant(void) */ /* too many characters in character constant */ error(71); - } else if (n > 1) { + } else if (n > 1) /* multi-character character constant */ warning(294); - } else if (n == 0 && !it.unescaped_newline) { + else if (n == 0 && !it.unescaped_newline) /* empty character constant */ error(73); - } int64_t cval = n == 1 ? convert_integer((int64_t)val, CHAR, CHAR_SIZE) @@ -1014,10 +1010,10 @@ lex_wide_character_constant(void) } wchar_t wc = 0; - if (n == 0) { + if (n == 0) /* empty character constant */ error(73); - } else if (n > nmax) { + else if (n > nmax) { n = nmax; /* too many characters in character constant */ error(71); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.603 src/usr.bin/xlint/lint1/tree.c:1.604 --- src/usr.bin/xlint/lint1/tree.c:1.603 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/tree.c Thu Feb 8 20:45:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.603 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.603 2024/02/05 23:11:22 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $"); #endif #include <float.h> @@ -469,13 +469,12 @@ build_name_call(sym_t *sym) */ if (allow_gcc && is_gcc_bool_builtin(sym->s_name)) sym->s_type = gettyp(BOOL); - } else if (allow_c99) { + } else if (allow_c99) /* function '%s' implicitly declared to return int */ error(215, sym->s_name); - } else if (!allow_trad) { + else if (!allow_trad) /* function '%s' implicitly declared to return int */ warning(215, sym->s_name); - } /* XXX if !allow_c90, the symbol should be exported to level 0 */ sym->s_type = block_derive_type(sym->s_type, FUNC); @@ -645,10 +644,9 @@ check_integer_comparison(op_t op, tnode_ /* operator '%s' compares '%s' with '%s' */ warning(162, op_name(op), type_name(ln->tn_type), "negative constant"); - } else if (op == LT || op == GE) { + } else if (op == LT || op == GE) /* operator '%s' compares '%s' with '%s' */ warning(162, op_name(op), type_name(ln->tn_type), "0"); - } return; } if (is_uinteger(rt) && !is_uinteger(lt) && @@ -657,10 +655,9 @@ check_integer_comparison(op_t op, tnode_ /* operator '%s' compares '%s' with '%s' */ warning(162, op_name(op), "negative constant", type_name(rn->tn_type)); - } else if (op == GT || op == LE) { + } else if (op == GT || op == LE) /* operator '%s' compares '%s' with '%s' */ warning(162, op_name(op), "0", type_name(rn->tn_type)); - } return; } } @@ -846,18 +843,16 @@ fold_constant_integer(tnode_t *tn) /* operator '%s' produces integer overflow */ warning(141, op_name(DIV)); si = sl; - } else { + } else si = utyp ? (int64_t)(ul / ur) : sl / sr; - } break; case MOD: if (sr == 0) { /* modulus by 0 */ error(140); si = 0; - } else { + } else si = utyp ? (int64_t)(ul % ur) : sl % sr; - } break; case PLUS: si = utyp ? (int64_t)(ul + ur) : sl + sr; @@ -946,9 +941,9 @@ build_struct_access(op_t op, bool sys, t bool lvalue = op == ARROW || ln->tn_lvalue; - if (op == POINT) { + if (op == POINT) ln = build_address(sys, ln, true); - } else if (ln->tn_type->t_tspec != PTR) { + else if (ln->tn_type->t_tspec != PTR) { lint_assert(!allow_c90); lint_assert(is_integer(ln->tn_type->t_tspec)); ln = convert(NOOP, 0, expr_derive_type(gettyp(VOID), PTR), ln); @@ -1004,25 +999,22 @@ subt_size_in_bytes(type_t *tp) error(136); break; case ENUM: - if (is_incomplete(tp)) { + if (is_incomplete(tp)) /* cannot do pointer arithmetic on operand of ... */ warning(136); - } /* FALLTHROUGH */ default: - if ((elsz_in_bits = size_in_bits(tp->t_tspec)) == 0) { + if ((elsz_in_bits = size_in_bits(tp->t_tspec)) == 0) /* cannot do pointer arithmetic on operand of ... */ error(136); - } else { + else lint_assert(elsz_in_bits != -1); - } break; } - if (elem == 0 && elsz_in_bits != 0) { + if (elem == 0 && elsz_in_bits != 0) /* cannot do pointer arithmetic on operand of unknown size */ error(136); - } if (elsz_in_bits == 0) elsz_in_bits = CHAR_SIZE; @@ -1192,14 +1184,14 @@ build_colon(bool sys, tnode_t *ln, tnode tspec_t rt = rn->tn_type->t_tspec; type_t *tp; - if (is_arithmetic(lt) && is_arithmetic(rt)) { + if (is_arithmetic(lt) && is_arithmetic(rt)) /* The operands were already balanced in build_binary. */ tp = ln->tn_type; - } else if (lt == BOOL && rt == BOOL) { + else if (lt == BOOL && rt == BOOL) tp = ln->tn_type; - } else if (lt == VOID || rt == VOID) { + else if (lt == VOID || rt == VOID) tp = gettyp(VOID); - } else if (is_struct_or_union(lt)) { + else if (is_struct_or_union(lt)) { 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)) { @@ -1216,15 +1208,15 @@ build_colon(bool sys, tnode_t *ln, tnode if (lt != PTRDIFF_TSPEC) ln = convert(NOOP, 0, gettyp(PTRDIFF_TSPEC), ln); tp = rn->tn_type; - } else if (lt == PTR && is_null_pointer(rn)) { + } else if (lt == PTR && is_null_pointer(rn)) tp = merge_qualifiers(ln->tn_type, rn->tn_type); - } else if (rt == PTR && is_null_pointer(ln)) { + else if (rt == PTR && is_null_pointer(ln)) tp = merge_qualifiers(rn->tn_type, ln->tn_type); - } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) { + else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) tp = merge_qualifiers(ln->tn_type, rn->tn_type); - } else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) { + else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) tp = merge_qualifiers(rn->tn_type, ln->tn_type); - } else { + else { /* * XXX For now we simply take the left type. This is probably * wrong, if one type contains a function prototype and the @@ -1322,13 +1314,12 @@ build_assignment(op_t op, bool sys, tnod lint_assert(lt == rt); lint_assert(ln->tn_type->t_sou == rn->tn_type->t_sou); if (is_incomplete(ln->tn_type)) { - if (op == RETURN) { + if (op == RETURN) /* cannot return incomplete type */ error(212); - } else { + else /* unknown operand size, op '%s' */ error(138, op_name(op)); - } return NULL; } } @@ -1769,10 +1760,9 @@ build_binary(tnode_t *ln, op_t op, bool (ln->tn_op == CON || (mp->m_binary && op != QUEST && rn->tn_op == CON)) && /* XXX: rn->tn_system_dependent should be checked as well */ - !ln->tn_system_dependent) { + !ln->tn_system_dependent) /* constant in conditional context */ warning(161); - } if (mp->m_fold_constant_operands && ln->tn_op == CON) { if (!mp->m_binary || rn->tn_op == CON) { @@ -1931,42 +1921,38 @@ struct_or_union_member(tnode_t *tn, op_t * struct/union, but the right operand is not member of it. */ if (sou != NULL) { - if (eq && !allow_c90) { + if (eq && !allow_c90) /* illegal use of member '%s' */ warning(102, msym->s_name); - } else { + else /* illegal use of member '%s' */ error(102, msym->s_name); - } return msym; } if (eq) { if (op == POINT) { - if (!allow_c90) { + if (!allow_c90) /* left operand of '.' must be struct ... */ warning(103, type_name(tn->tn_type)); - } else { + else /* left operand of '.' must be struct ... */ error(103, type_name(tn->tn_type)); - } } else { - if (!allow_c90 && tn->tn_type->t_tspec == PTR) { + if (!allow_c90 && tn->tn_type->t_tspec == PTR) /* left operand of '->' must be pointer ... */ warning(104, type_name(tn->tn_type)); - } else { + else /* left operand of '->' must be pointer ... */ error(104, type_name(tn->tn_type)); - } } } else { - if (!allow_c90) { + if (!allow_c90) /* non-unique member requires struct/union %s */ error(105, op == POINT ? "object" : "pointer"); - } else { + else /* unacceptable operand of '%s' */ error(111, op_name(op)); - } } return msym; @@ -1980,10 +1966,9 @@ build_member_access(tnode_t *ln, op_t op if (ln == NULL) return NULL; - if (op == ARROW) { + if (op == ARROW) /* must do this before struct_or_union_member is called */ ln = cconv(ln); - } msym = struct_or_union_member(ln, op, getsym(member)); return build_binary(ln, op, sys, build_name(msym, false)); } @@ -2089,18 +2074,16 @@ typeok_incdec(op_t op, const tnode_t *tn /* operand has scalar type (checked in typeok) */ if (!tn->tn_lvalue) { if (tn->tn_op == CVT && tn->tn_cast && - tn->tn_left->tn_op == LOAD) { + tn->tn_left->tn_op == LOAD) /* a cast does not yield an lvalue */ error(163); - } /* %soperand of '%s' must be lvalue */ error(114, "", op_name(op)); return false; } - if (tp->t_const && allow_c90) { + if (tp->t_const && allow_c90) /* %soperand of '%s' must be modifiable lvalue */ warning(115, "", op_name(op)); - } return true; } @@ -2111,10 +2094,9 @@ typeok_address(op_t op, const tnode_t *t /* ok, a warning comes later (in build_address()) */ } else if (!tn->tn_lvalue) { if (tn->tn_op == CVT && tn->tn_cast && - tn->tn_left->tn_op == LOAD) { + tn->tn_left->tn_op == LOAD) /* a cast does not yield an lvalue */ error(163); - } /* %soperand of '%s' must be lvalue */ error(114, "", op_name(op)); return false; @@ -2159,13 +2141,13 @@ warn_incompatible_types(op_t op, if (lt == VOID || (binary && rt == VOID)) { /* void type illegal in expression */ error(109); - } else if (op == ASSIGN) { + } else if (op == ASSIGN) /* cannot assign to '%s' from '%s' */ error(171, type_name(ltp), type_name(rtp)); - } else if (binary) { + else if (binary) /* operands of '%s' have incompatible types '%s' and '%s' */ error(107, op_name(op), type_name(ltp), type_name(rtp)); - } else { + else { lint_assert(rt == NO_TSPEC); /* operand of '%s' has invalid type '%s' */ error(108, op_name(op), type_name(ltp)); @@ -2218,13 +2200,12 @@ typeok_shr(op_t op, if (!ic_maybe_signed(ln->tn_type, &lc)) return; - if (ln->tn_op != CON) { + if (ln->tn_op != CON) /* bitwise '%s' on signed value possibly nonportable */ warning(117, op_name(op)); - } else if (ln->tn_val.u.integer < 0) { + else if (ln->tn_val.u.integer < 0) /* bitwise '%s' on signed value nonportable */ warning(120, op_name(op)); - } } else if (allow_trad && allow_c90 && !is_uinteger(olt) && is_uinteger(ort)) { /* The left operand would become unsigned in traditional C. */ @@ -2273,13 +2254,13 @@ typeok_shift(const type_t *ltp, tspec_t if (rn->tn_op != CON) return; - if (!is_uinteger(rt) && rn->tn_val.u.integer < 0) { + if (!is_uinteger(rt) && rn->tn_val.u.integer < 0) /* negative shift */ warning(121); - } else if ((uint64_t)rn->tn_val.u.integer == size_in_bits(lt)) { + else if ((uint64_t)rn->tn_val.u.integer == size_in_bits(lt)) /* shift amount %u equals bit-size of '%s' */ warning(267, (unsigned)rn->tn_val.u.integer, type_name(ltp)); - } else if ((uint64_t)rn->tn_val.u.integer > size_in_bits(lt)) { + else if ((uint64_t)rn->tn_val.u.integer > size_in_bits(lt)) { /* shift amount %llu is greater than bit-size %llu of '%s' */ warning(122, (unsigned long long)rn->tn_val.u.integer, (unsigned long long)size_in_bits(lt), @@ -2307,19 +2288,19 @@ warn_incompatible_pointers(op_t op, cons tspec_t rt = rtp->t_subt->t_tspec; if (is_struct_or_union(lt) && is_struct_or_union(rt)) { - if (op == RETURN) { + if (op == RETURN) /* illegal structure pointer combination */ warning(244); - } else { + else { /* incompatible structure pointers: '%s' '%s' '%s' */ warning(245, type_name(ltp), op_name(op), type_name(rtp)); } } else { - if (op == RETURN) { + if (op == RETURN) /* illegal combination of '%s' and '%s' */ warning(184, type_name(ltp), type_name(rtp)); - } else { + else { /* illegal combination of '%s' and '%s', op '%s' */ warning(124, type_name(ltp), type_name(rtp), op_name(op)); @@ -2492,10 +2473,9 @@ typeok_assign(op_t op, const tnode_t *ln if (!ln->tn_lvalue) { if (ln->tn_op == CVT && ln->tn_cast && - ln->tn_left->tn_op == LOAD) { + ln->tn_left->tn_op == LOAD) /* a cast does not yield an lvalue */ error(163); - } /* %soperand of '%s' must be lvalue */ error(114, "left ", op_name(op)); return false; @@ -3354,13 +3334,12 @@ convert_integer_from_integer(op_t op, in if (Pflag && pflag && aflag > 0 && portable_rank_cmp(nt, ot) > 0 && is_uinteger(nt) != is_uinteger(ot)) { - if (op == FARG) { + if (op == FARG) /* conversion to '%s' may sign-extend ... */ warning(297, type_name(tp), arg); - } else { + else /* conversion to '%s' may sign-extend ... */ warning(131, type_name(tp)); - } } if (Pflag && portable_rank_cmp(nt, ot) > 0 && @@ -3695,10 +3674,9 @@ static void convert_constant_check_range_bitor(size_t nsz, size_t osz, const val_t *v, uint64_t xmask, op_t op) { - if (nsz < osz && (v->u.integer & xmask) != 0) { + if (nsz < osz && (v->u.integer & xmask) != 0) /* constant truncated by conversion, op '%s' */ warning(306, op_name(op)); - } } static void @@ -3715,30 +3693,28 @@ convert_constant_check_range_bitand(size type_name(tp), op_name(op)); } else if (nsz < osz && (v->u.integer & xmask) != xmask && - (v->u.integer & xmask) != 0) { + (v->u.integer & xmask) != 0) /* constant truncated by conversion, op '%s' */ warning(306, op_name(op)); - } } static void convert_constant_check_range_signed(op_t op, int arg) { - if (op == ASSIGN) { + if (op == ASSIGN) /* assignment of negative constant to unsigned type */ warning(164); - } else if (op == INIT) { + else if (op == INIT) /* initialization of unsigned with negative constant */ warning(221); - } else if (op == FARG) { + else if (op == FARG) /* conversion of negative constant to unsigned type, ... */ warning(296, arg); - } else if (modtab[op].m_comparison) { + else if (modtab[op].m_comparison) { /* handled by check_integer_comparison() */ - } else { + } else /* conversion of negative constant to unsigned type */ warning(222); - } } /* @@ -3968,9 +3944,8 @@ type_size_in_bits(const type_t *tp) /* cannot take size/alignment of incomplete type */ error(143); elsz = 1; - } else { + } else elsz = tp->t_sou->sou_size_in_bits; - } break; case ENUM: if (is_incomplete(tp)) { @@ -3979,10 +3954,9 @@ type_size_in_bits(const type_t *tp) } /* FALLTHROUGH */ default: - if (tp->t_bitfield) { + if (tp->t_bitfield) /* cannot take size/alignment of bit-field */ error(145); - } elsz = size_in_bits(tp->t_tspec); lint_assert(elsz > 0); break; @@ -4090,11 +4064,10 @@ cast(tnode_t *tn, bool sys, type_t *tp) } else goto invalid_cast; - if (any_query_enabled && types_compatible(tp, tn->tn_type, - false, false, NULL)) { + if (any_query_enabled + && types_compatible(tp, tn->tn_type, false, false, NULL)) /* no-op cast from '%s' to '%s' */ query_message(6, type_name(tn->tn_type), type_name(tp)); - } tn = convert(CVT, 0, tp, tn); tn->tn_cast = true; @@ -4286,9 +4259,8 @@ integer_constant(tnode_t *tn, bool requi return v; } v->u.integer = (int64_t)tn->tn_val.u.floating; - } else { + } else v->u.integer = 1; - } if (required) /* integral constant expression expected */ @@ -4401,13 +4373,12 @@ check_array_index(tnode_t *tn, bool ampe int dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0); - if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) { + if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) /* array subscript cannot be negative: %ld */ warning(167, (long)con); - } else if (dim > 0 && (uint64_t)con >= (uint64_t)dim) { + else if (dim > 0 && (uint64_t)con >= (uint64_t)dim) /* array subscript cannot be > %d: %ld */ warning(168, dim - 1, (long)con); - } } static void