Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint lint: clarify the meaning of 'portable size in...



details:   https://anonhg.NetBSD.org/src/rev/393da1f95b2c
branches:  trunk
changeset: 377344:393da1f95b2c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 08 09:35:35 2023 +0000

description:
lint: clarify the meaning of 'portable size in bits' of a type

No functional change.

diffstat:

 usr.bin/xlint/common/inittyp.c |  16 +++++-----------
 usr.bin/xlint/common/lint.h    |   8 ++++----
 usr.bin/xlint/lint1/decl.c     |   7 +++----
 usr.bin/xlint/lint1/tree.c     |  41 +++++++++++++++++++++++++++--------------
 4 files changed, 39 insertions(+), 33 deletions(-)

diffs (243 lines):

diff -r eb3a5e0b496d -r 393da1f95b2c usr.bin/xlint/common/inittyp.c
--- a/usr.bin/xlint/common/inittyp.c    Sat Jul 08 09:08:20 2023 +0000
+++ b/usr.bin/xlint/common/inittyp.c    Sat Jul 08 09:35:35 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inittyp.c,v 1.37 2023/07/03 07:03:19 rillig Exp $      */
+/*     $NetBSD: inittyp.c,v 1.38 2023/07/08 09:35:35 rillig Exp $      */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: inittyp.c,v 1.37 2023/07/03 07:03:19 rillig Exp $");
+__RCSID("$NetBSD: inittyp.c,v 1.38 2023/07/08 09:35:35 rillig Exp $");
 #endif
 
 #if defined(IS_LINT1)
@@ -49,12 +49,9 @@
 #define INT_RSIZE      (/*CONSTCOND*/INTPTR_TSPEC == LONG ? 3 : 4)
 
 #ifdef IS_LINT1
-#define typeinfo( \
-           name, signed_type, unsigned_type, \
-           size_in_bits, portable_size_in_bits, \
-           c) \
+#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rank, c) \
        { /*CONSTCOND*/ \
-               size_in_bits, portable_size_in_bits, \
+               size_in_bits, rank, \
                signed_type, unsigned_type, \
                (c) == 's' || (c) == 'u', \
                (c) == 'u' || (c) == 'p', \
@@ -67,10 +64,7 @@
                name, \
        }
 #else
-#define typeinfo( \
-           name, signed_type, unsigned_type, \
-           size_in_bits, portable_size_in_bits, \
-           c) \
+#define typeinfo(name, signed_type, unsigned_type, size_in_bits, rank, c) \
        { /*CONSTCOND*/ \
                signed_type, unsigned_type, \
                (c) == 's' || (c) == 'u', \
diff -r eb3a5e0b496d -r 393da1f95b2c usr.bin/xlint/common/lint.h
--- a/usr.bin/xlint/common/lint.h       Sat Jul 08 09:08:20 2023 +0000
+++ b/usr.bin/xlint/common/lint.h       Sat Jul 08 09:35:35 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lint.h,v 1.39 2023/07/06 07:59:00 rillig Exp $ */
+/*     $NetBSD: lint.h,v 1.40 2023/07/08 09:35:35 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -95,8 +95,9 @@ typedef enum {
 typedef        struct {
 #ifdef IS_LINT1
        unsigned int tt_size_in_bits;
-       unsigned int tt_portable_size_in_bits; /* different from
-                                        * tt_size_in_bits if pflag is set */
+       unsigned int tt_rank;   /* relative size of the type; depends on
+                                * portable mode, as well as on whether sizeof
+                                * has type 'int' or 'long' */
 #endif
        tspec_t tt_signed_counterpart;
        tspec_t tt_unsigned_counterpart;
@@ -119,7 +120,6 @@ type_properties(tspec_t t) {
 }
 
 #define size_in_bits(t)                (type_properties(t)->tt_size_in_bits)
-#define portable_size_in_bits(t) (type_properties(t)->tt_portable_size_in_bits)
 #define signed_type(t)         (type_properties(t)->tt_signed_counterpart)
 #define unsigned_type(t)       (type_properties(t)->tt_unsigned_counterpart)
 #define is_integer(t)          (type_properties(t)->tt_is_integer)
diff -r eb3a5e0b496d -r 393da1f95b2c usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jul 08 09:08:20 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jul 08 09:35:35 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.343 2023/07/07 19:45:22 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.344 2023/07/08 09:35:35 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.343 2023/07/07 19:45:22 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.344 2023/07/08 09:35:35 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -100,8 +100,7 @@ initdecl(void)
 
        if (!pflag) {
                for (size_t i = 0; i < NTSPEC; i++)
-                       ttab[i].tt_portable_size_in_bits =
-                           ttab[i].tt_size_in_bits;
+                       ttab[i].tt_rank = ttab[i].tt_size_in_bits;
        }
 
        if (Tflag) {
diff -r eb3a5e0b496d -r 393da1f95b2c usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jul 08 09:08:20 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jul 08 09:35:35 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.549 2023/07/07 20:19:08 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.550 2023/07/08 09:35:35 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.549 2023/07/07 20:19:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.550 2023/07/08 09:35:35 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -95,7 +95,16 @@ width_in_bits(const type_t *tp)
        lint_assert(is_integer(tp->t_tspec));
        return tp->t_bitfield
            ? tp->t_bit_field_width
-           : portable_size_in_bits(tp->t_tspec);
+           // FIXME: The rank of a type is only intended as a relative size,
+           // its value is not to be taken literally.
+           : type_properties(tp->t_tspec)->tt_rank;
+}
+
+static int
+portable_rank_cmp(tspec_t t1, tspec_t t2) {
+       unsigned int r1 = type_properties(t1)->tt_rank;
+       unsigned int r2 = type_properties(t2)->tt_rank;
+       return (int)r1 - (int)r2;
 }
 
 static bool
@@ -1349,7 +1358,7 @@ build_assignment(op_t op, bool sys, tnod
        }
 
        if (op == SHLASS && hflag && allow_trad && allow_c90
-           && portable_size_in_bits(lt) < portable_size_in_bits(rt))
+           && portable_rank_cmp(lt, rt) < 0)
                /* semantics of '%s' change in ANSI C; ... */
                warning(118, "<<=");
 
@@ -2284,7 +2293,7 @@ typeok_shr(const mod_t *mp,
                }
        } else if (allow_trad && allow_c90 &&
                   !is_uinteger(olt) && !is_uinteger(ort) &&
-                  portable_size_in_bits(lt) < portable_size_in_bits(rt)) {
+           portable_rank_cmp(lt, rt) < 0) {
                /*
                 * In traditional C the left operand would be extended
                 * (possibly sign-extended) and then shifted.
@@ -2307,7 +2316,7 @@ typeok_shl(const mod_t *mp, tspec_t lt, 
         * width of the right operand. For SHL this may result in
         * different results.
         */
-       if (portable_size_in_bits(lt) < portable_size_in_bits(rt)) {
+       if (portable_rank_cmp(lt, rt) < 0) {
                /*
                 * XXX If both operands are constant, make sure
                 * that there is really a difference between
@@ -3315,7 +3324,7 @@ should_warn_about_prototype_conversion(t
                return false;
 
        if (is_floating(nt) != is_floating(ot) ||
-           portable_size_in_bits(nt) != portable_size_in_bits(ot)) {
+           portable_rank_cmp(nt, ot) != 0) {
                /* representation and/or width change */
                if (!is_integer(ot))
                        return true;
@@ -3323,7 +3332,7 @@ should_warn_about_prototype_conversion(t
                 * XXX: Investigate whether this rule makes sense; see
                 * tests/usr.bin/xlint/lint1/platform_long.c.
                 */
-               return portable_size_in_bits(ot) > portable_size_in_bits(INT);
+               return portable_rank_cmp(ot, INT) > 0;
        }
 
        if (!hflag)
@@ -3417,7 +3426,7 @@ convert_integer_from_integer(op_t op, in
                return;
 
        if (Pflag && pflag && aflag > 0 &&
-           portable_size_in_bits(nt) > portable_size_in_bits(ot) &&
+           portable_rank_cmp(nt, ot) > 0 &&
            is_uinteger(nt) != is_uinteger(ot)) {
                if (op == FARG) {
                        /* conversion to '%s' may sign-extend ... */
@@ -3428,7 +3437,7 @@ convert_integer_from_integer(op_t op, in
                }
        }
 
-       if (Pflag && portable_size_in_bits(nt) > portable_size_in_bits(ot) &&
+       if (Pflag && portable_rank_cmp(nt, ot) > 0 &&
            (tn->tn_op == PLUS || tn->tn_op == MINUS || tn->tn_op == MULT ||
             tn->tn_op == SHL)) {
                /* suggest cast from '%s' to '%s' on op '%s' to ... */
@@ -3437,9 +3446,13 @@ convert_integer_from_integer(op_t op, in
        }
 
        if (aflag > 0 &&
-           portable_size_in_bits(nt) < portable_size_in_bits(ot) &&
+           portable_rank_cmp(nt, ot) < 0 &&
            (ot == LONG || ot == ULONG || ot == LLONG || ot == ULLONG ||
             aflag > 1) &&
+            // XXX: The portable_rank_cmp above aims at portable mode,
+            // independent of the current platform, while can_represent acts
+            // on the actual types from the current platform.  This mix is
+            // inconsistent.
            !can_represent(tp, tn)) {
                if (op == FARG) {
                        /* conversion from '%s' to '%s' may lose ... */
@@ -3465,7 +3478,7 @@ convert_integer_from_pointer(op_t op, ts
                return;
        if (op != CVT)
                return;         /* We already got an error. */
-       if (portable_size_in_bits(nt) >= portable_size_in_bits(PTR))
+       if (portable_rank_cmp(nt, PTR) >= 0)
                return;
 
        if (pflag && size_in_bits(nt) >= size_in_bits(PTR)) {
@@ -3556,7 +3569,7 @@ should_warn_about_pointer_cast(const typ
        if (is_struct_or_union(nst) && nstp->t_sou != ostp->t_sou)
                return true;
 
-       return portable_size_in_bits(nst) != portable_size_in_bits(ost);
+       return portable_rank_cmp(nst, ost) != 0;
 }
 
 static void
@@ -3941,7 +3954,7 @@ convert_constant(op_t op, int arg, const
        if (allow_trad && allow_c90 && v->v_unsigned_since_c90 &&
            (is_floating(nt) || (
                (is_integer(nt) && !is_uinteger(nt) &&
-                portable_size_in_bits(nt) > portable_size_in_bits(ot))))) {
+                   portable_rank_cmp(nt, ot) > 0)))) {
                /* ANSI C treats constant as unsigned */
                warning(157);
                v->v_unsigned_since_c90 = false;



Home | Main Index | Thread Index | Old Index