Module Name: src Committed By: rillig Date: Thu May 26 18:08:33 UTC 2022
Modified Files: src/usr.bin/xlint/lint1: tree.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.447 -r1.448 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.447 src/usr.bin/xlint/lint1/tree.c:1.448 --- src/usr.bin/xlint/lint1/tree.c:1.447 Thu May 26 17:23:09 2022 +++ src/usr.bin/xlint/lint1/tree.c Thu May 26 18:08:33 2022 @@ -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 @@ build_plus_minus(op_t op, bool sys, tnod 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 @@ build_plus_minus(op_t op, bool sys, tnod 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 @@ check_expr_misc(const tnode_t *tn, bool 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 @@ check_array_index(tnode_t *tn, bool ampe 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 */