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: extract condition for message 259 ...



details:   https://anonhg.NetBSD.org/src/rev/4c5747b12571
branches:  trunk
changeset: 1023279:4c5747b12571
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 31 19:17:45 2021 +0000

description:
lint: extract condition for message 259 into separate function

No functional change.

diffstat:

 usr.bin/xlint/lint1/tree.c |  50 +++++++++++++++++++++++----------------------
 1 files changed, 26 insertions(+), 24 deletions(-)

diffs (92 lines):

diff -r 10ead96c8860 -r 4c5747b12571 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Aug 31 18:59:26 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Aug 31 19:17:45 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.363 2021/08/29 17:01:27 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.364 2021/08/31 19:17:45 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.363 2021/08/29 17:01:27 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.364 2021/08/31 19:17:45 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1975,19 +1975,29 @@
 
 /*
  * The types differ in sign or base type (char, short, int, long, long long,
- * float, double, long double).
+ * int128_t, float, double, long double).
  *
  * If they differ only in sign and the argument is representable in both
  * types, print no warning.
  */
-static void
-check_prototype_conversion_integer(const tnode_t *tn, const tnode_t *ptn,
-                                  const type_t *tp, tspec_t nt, tspec_t ot,
-                                  int arg)
+static bool
+should_warn_about_prototype_conversion(
+    int arg,
+    const type_t *tp, tspec_t nt,
+    const tnode_t *tn, tspec_t ot,
+    const tnode_t *ptn)
 {
 
+       if (is_floating(nt) != is_floating(ot) ||
+           portable_size_in_bits(nt) != portable_size_in_bits(ot)) {
+               /* representation and/or width change */
+               if (!is_integer(ot))
+                       return true;
+               return portable_size_in_bits(ot) > portable_size_in_bits(INT);
+       }
+
        if (!hflag)
-               return;
+               return false;
 
        /*
         * If the types differ only in sign and the argument has the same
@@ -1996,11 +2006,9 @@
        if (ptn->tn_op == CON && is_integer(nt) &&
            signed_type(nt) == signed_type(ot) &&
            !msb(ptn->tn_val->v_quad, ot))
-               return;
-
-       /* argument #%d is converted from '%s' to '%s' ... */
-       warning(259,
-           arg, type_name(tn->tn_type), type_name(tp));
+               return false;
+
+       return true;
 }
 
 /*
@@ -2037,17 +2045,11 @@
        if (nt == ot || (nt == ENUM && ot == INT))
                return;
 
-       if (is_floating(nt) != is_floating(ot) ||
-           portable_size_in_bits(nt) != portable_size_in_bits(ot)) {
-               /* representation and/or width change */
-               if (!is_integer(ot) ||
-                   portable_size_in_bits(ot) > portable_size_in_bits(INT)) {
-                       /* argument #%d is converted from '%s' to '%s' ... */
-                       warning(259,
-                           arg, type_name(tn->tn_type), type_name(tp));
-               }
-       } else
-               check_prototype_conversion_integer(tn, ptn, tp, nt, ot, arg);
+       if (should_warn_about_prototype_conversion(
+           arg, tp, nt, tn, ot, ptn)) {
+               /* argument #%d is converted from '%s' to '%s' ... */
+               warning(259, arg, type_name(tn->tn_type), type_name(tp));
+       }
 }
 
 /*



Home | Main Index | Thread Index | Old Index