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: do not pre-multiply pointer expres...



details:   https://anonhg.NetBSD.org/src/rev/608983769114
branches:  trunk
changeset: 366439:608983769114
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 26 18:08:33 2022 +0000

description:
lint: do not pre-multiply pointer expressions 'ptr + int'

In the AST, it is confusing to see that 'stderr == __sF + 304', it
should rather be 'stderr == __sF + 2'.

No functional change.

diffstat:

 usr.bin/xlint/lint1/tree.c |  45 ++++++++++-----------------------------------
 1 files changed, 10 insertions(+), 35 deletions(-)

diffs (88 lines):

diff -r d418780fa23b -r 608983769114 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Thu May 26 17:23:09 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Thu May 26 18:08:33 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.447 2022/05/26 17:23:09 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.448 2022/05/26 18:08:33 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.447 2022/05/26 17:23:09 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.448 2022/05/26 18:08:33 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3102,12 +3102,7 @@
                tnode_t *elsz = subt_size_in_bytes(ln->tn_type);
                if (rn->tn_type->t_tspec != elsz->tn_type->t_tspec)
                        rn = convert(NOOP, 0, elsz->tn_type, rn);
-
-               tnode_t *prod = new_tnode(MULT, sys, rn->tn_type, rn, elsz);
-               if (rn->tn_op == CON)
-                       prod = fold(prod);
-
-               return new_tnode(op, sys, ln->tn_type, ln, prod);
+               return new_tnode(op, sys, ln->tn_type, ln, rn);
        }
 
        /* pointer - pointer */
@@ -3116,14 +3111,10 @@
                lint_assert(op == MINUS);
 
                type_t *ptrdiff = gettyp(PTRDIFF_TSPEC);
-               tnode_t *raw_diff = new_tnode(op, sys, ptrdiff, ln, rn);
+               tnode_t *diff = new_tnode(MINUS, sys, ptrdiff, ln, rn);
                if (ln->tn_op == CON && rn->tn_op == CON)
-                       raw_diff = fold(raw_diff);
-
-               tnode_t *elsz = subt_size_in_bytes(ln->tn_type);
-               balance(NOOP, &raw_diff, &elsz);
-
-               return new_tnode(DIV, sys, ptrdiff, raw_diff, elsz);
+                       diff = fold(diff);
+               return diff;
        }
 
        return new_tnode(op, sys, ln->tn_type, ln, rn);
@@ -4391,13 +4382,8 @@
 static void
 check_array_index(tnode_t *tn, bool amper)
 {
-       int     dim;
-       tnode_t *ln, *rn;
-       int     elsz;
-       int64_t con;
-
-       ln = tn->tn_left;
-       rn = tn->tn_right;
+       tnode_t *ln = tn->tn_left;
+       tnode_t *rn = tn->tn_right;
 
        /* We can only check constant indices. */
        if (rn->tn_op != CON)
@@ -4418,19 +4404,8 @@
        if (is_incomplete(ln->tn_left->tn_type) && rn->tn_val->v_quad >= 0)
                return;
 
-       /* Get the size of one array element */
-       if ((elsz = length_in_bits(ln->tn_type->t_subt, NULL)) == 0)
-               return;
-       elsz /= CHAR_SIZE;
-
-       /* Change the unit of the index from bytes to element size. */
-       if (is_uinteger(rn->tn_type->t_tspec)) {
-               con = (uint64_t)rn->tn_val->v_quad / elsz;
-       } else {
-               con = rn->tn_val->v_quad / elsz;
-       }
-
-       dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0);
+       int64_t con = rn->tn_val->v_quad;
+       int dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0);
 
        if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) {
                /* array subscript cannot be negative: %ld */



Home | Main Index | Thread Index | Old Index