From 2358dced517f1f730f1e2a987b7c660821827b37 Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 1 Jul 2023 09:31:55 +0000 Subject: lint: clean up duplicate and dead code for integer constants No functional change. --- usr.bin/xlint/lint1/decl.c | 40 +++++++++++++--------------------------- usr.bin/xlint/lint1/externs1.h | 4 ++-- usr.bin/xlint/lint1/func.c | 6 +++--- usr.bin/xlint/lint1/tree.c | 6 +++--- 4 files changed, 21 insertions(+), 35 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 23babec3e9e..28fbeee6faf 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.330 2023/06/30 21:39:54 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.331 2023/07/01 09:31:55 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.330 2023/06/30 21:39:54 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.331 2023/07/01 09:31:55 rillig Exp $"); #endif #include @@ -3195,7 +3195,10 @@ to_int_constant(tnode_t *tn, bool required) if (tn == NULL) return 1; - val_t *v = constant(tn, required); + val_t *v = integer_constant(tn, required); + bool is_unsigned = is_uinteger(v->v_tspec); + int64_t val = v->v_quad; + free(v); /* * Abstract declarations are used inside expression. To free @@ -3206,28 +3209,11 @@ to_int_constant(tnode_t *tn, bool required) if (tn->tn_op != CON && dcs->d_kind != DLK_ABSTRACT) expr_free_all(); - tspec_t t = v->v_tspec; - int i; - if (t == FLOAT || t == DOUBLE || t == LDOUBLE) { - i = (int)v->v_ldbl; - /* integral constant expression expected */ - error(55); - } else { - i = (int)v->v_quad; - if (is_uinteger(t)) { - if ((uint64_t)v->v_quad > (uint64_t)TARG_INT_MAX) { - /* integral constant too large */ - warning(56); - } - } else { - if (v->v_quad > (int64_t)TARG_INT_MAX || - v->v_quad < (int64_t)TARG_INT_MIN) { - /* integral constant too large */ - warning(56); - } - } - } - - free(v); - return i; + bool out_of_bounds = is_unsigned + ? (uint64_t)val > (uint64_t)TARG_INT_MAX + : val > (int64_t)TARG_INT_MAX || val < (int64_t)TARG_INT_MIN; + if (out_of_bounds) + /* integral constant too large */ + warning(56); + return (int)val; } diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index d68dfce3cec..72d0a95bc4d 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.184 2023/07/01 06:09:24 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.185 2023/07/01 09:31:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -269,7 +269,7 @@ tnode_t *build_alignof(const type_t *); tnode_t *cast(tnode_t *, type_t *); tnode_t *build_function_argument(tnode_t *, tnode_t *); tnode_t *build_function_call(tnode_t *, bool, tnode_t *); -val_t *constant(tnode_t *, bool); +val_t *integer_constant(tnode_t *, bool); void expr(tnode_t *, bool, bool, bool, bool); void check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool); bool constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *); diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c index 7634e0515b2..37e26dbdcf9 100644 --- a/usr.bin/xlint/lint1/func.c +++ b/usr.bin/xlint/lint1/func.c @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.160 2023/06/30 21:39:54 rillig Exp $ */ +/* $NetBSD: func.c,v 1.161 2023/07/01 09:31:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.160 2023/06/30 21:39:54 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.161 2023/07/01 09:31:55 rillig Exp $"); #endif #include @@ -533,7 +533,7 @@ check_case_label(tnode_t *tn, control_statement *cs) * get the value of the expression and convert it * to the type of the switch expression */ - v = constant(tn, true); + v = integer_constant(tn, true); (void)memset(&nv, 0, sizeof(nv)); convert_constant(CASE, 0, cs->c_switch_type, &nv, v); free(v); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index e5f2ff55dd7..d58762a1b1e 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.540 2023/07/01 09:21:31 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.541 2023/07/01 09:31:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.540 2023/07/01 09:21:31 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.541 2023/07/01 09:31:55 rillig Exp $"); #endif #include @@ -4328,7 +4328,7 @@ build_function_call(tnode_t *func, bool sys, tnode_t *args) * type, an error message is printed. */ val_t * -constant(tnode_t *tn, bool required) +integer_constant(tnode_t *tn, bool required) { if (tn != NULL) -- cgit