Module Name: src Committed By: rillig Date: Wed May 1 05:49:33 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_132.c src/usr.bin/xlint/lint1: tree.c Log Message: lint: fix warning about out-of-bounds bit-field value To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/tests/usr.bin/xlint/lint1/msg_132.c cvs rdiff -u -r1.637 -r1.638 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/tests/usr.bin/xlint/lint1/msg_132.c diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.39 src/tests/usr.bin/xlint/lint1/msg_132.c:1.40 --- src/tests/usr.bin/xlint/lint1/msg_132.c:1.39 Wed May 1 05:38:11 2024 +++ src/tests/usr.bin/xlint/lint1/msg_132.c Wed May 1 05:49:33 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_132.c,v 1.39 2024/05/01 05:38:11 rillig Exp $ */ +/* $NetBSD: msg_132.c,v 1.40 2024/05/01 05:49:33 rillig Exp $ */ # 3 "msg_132.c" // Test for message: conversion from '%s' to '%s' may lose accuracy [132] @@ -265,13 +265,13 @@ test_ic_shr(u64_t x) unsigned char test_bit_fields(unsigned long long m) { - /* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned int:3' may lose accuracy [132] */ + /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned int:3' may lose accuracy [132] */ bits.u3 = bits.u32 & m; bits.u5 = bits.u3 & m; bits.u32 = bits.u5 & m; - /* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned char' may lose accuracy [132] */ + /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */ return bits.u32 & m; } @@ -450,6 +450,7 @@ binary_operators_on_bit_fields(void) cond = (s.u15 | s.u48 | s.u64) != 0; cond = (s.u64 | s.u48 | s.u15) != 0; - /* expect+1: warning: conversion of 'int' to 'int:4' is out of range [119] */ + // Before tree.c from 1.638 from 2024-05-01, lint wrongly warned: + // warning: conversion of 'int' to 'int:4' is out of range [119] s32 = 8 - bits.u3; } Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.637 src/usr.bin/xlint/lint1/tree.c:1.638 --- src/usr.bin/xlint/lint1/tree.c:1.637 Sat Apr 27 12:46:37 2024 +++ src/usr.bin/xlint/lint1/tree.c Wed May 1 05:49:33 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.637 2024/04/27 12:46:37 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.638 2024/05/01 05:49: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.637 2024/04/27 12:46:37 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.638 2024/05/01 05:49:33 rillig Exp $"); #endif #include <float.h> @@ -763,12 +763,14 @@ balance(op_t op, tnode_t **lnp, tnode_t if (t != rt) *rnp = apply_usual_arithmetic_conversions(op, *rnp, t); - unsigned lw = (*lnp)->tn_type->t_bit_field_width; - unsigned rw = (*rnp)->tn_type->t_bit_field_width; - if (lw < rw) - *lnp = convert(NOOP, 0, (*rnp)->tn_type, *lnp); - if (rw < lw) - *rnp = convert(NOOP, 0, (*lnp)->tn_type, *rnp); + if (is_integer(t)) { + unsigned lw = width_in_bits((*lnp)->tn_type); + unsigned rw = width_in_bits((*rnp)->tn_type); + if (lw < rw) + *lnp = convert(NOOP, 0, (*rnp)->tn_type, *lnp); + if (rw < lw) + *rnp = convert(NOOP, 0, (*lnp)->tn_type, *rnp); + } } static tnode_t *