Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: clean up duplicate and dead code f...
details: https://anonhg.NetBSD.org/src/rev/3a022a22a360
branches: trunk
changeset: 377217:3a022a22a360
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 01 09:31:55 2023 +0000
description:
lint: clean up duplicate and dead code for integer constants
No functional change.
diffstat:
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(-)
diffs (138 lines):
diff -r e0640147faf7 -r 3a022a22a360 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sat Jul 01 09:21:47 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sat Jul 01 09:31:55 2023 +0000
@@ -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 <sys/cdefs.h>
#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 <sys/param.h>
@@ -3195,7 +3195,10 @@ to_int_constant(tnode_t *tn, bool requir
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 requir
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 -r e0640147faf7 -r 3a022a22a360 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sat Jul 01 09:21:47 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sat Jul 01 09:31:55 2023 +0000
@@ -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 -r e0640147faf7 -r 3a022a22a360 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Sat Jul 01 09:21:47 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c Sat Jul 01 09:31:55 2023 +0000
@@ -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 <sys/cdefs.h>
#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 <stdlib.h>
@@ -533,7 +533,7 @@ check_case_label(tnode_t *tn, control_st
* 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 -r e0640147faf7 -r 3a022a22a360 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sat Jul 01 09:21:47 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sat Jul 01 09:31:55 2023 +0000
@@ -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 <sys/cdefs.h>
#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 <float.h>
@@ -4328,7 +4328,7 @@ build_function_call(tnode_t *func, bool
* type, an error message is printed.
*/
val_t *
-constant(tnode_t *tn, bool required)
+integer_constant(tnode_t *tn, bool required)
{
if (tn != NULL)
Home |
Main Index |
Thread Index |
Old Index