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: fix wrong errors about sizeof of a...



details:   https://anonhg.NetBSD.org/src/rev/b1fc1ca91225
branches:  trunk
changeset: 366535:b1fc1ca91225
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 23:24:09 2022 +0000

description:
lint: fix wrong errors about sizeof of a bit-field (since 2022-05-26)

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c   |  29 ++---------------------------
 tests/usr.bin/xlint/lint1/msg_132.exp |  28 ++--------------------------
 usr.bin/xlint/lint1/tree.c            |  20 +++++++++++++-------
 3 files changed, 17 insertions(+), 60 deletions(-)

diffs (143 lines):

diff -r 98ea0105530d -r b1fc1ca91225 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Sun May 29 23:09:43 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Sun May 29 23:24:09 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.14 2022/05/29 23:09:43 rillig Exp $      */
+/*     $NetBSD: msg_132.c,v 1.15 2022/05/29 23:24:09 rillig Exp $      */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -205,37 +205,12 @@
 unsigned char
 test_bit_fields(struct bit_fields s, unsigned long m)
 {
-       /* expect+4: error: cannot take size/alignment of bit-field [145] */
-       /* expect+3: error: cannot take size/alignment of bit-field [145] */
-       /* expect+2: error: cannot take size/alignment of bit-field [145] */
-       /* expect+1: error: cannot take size/alignment of bit-field [145] */
+       /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
        s.bits_3 = s.bits_32 & m;
 
-       /* expect+9: error: cannot take size/alignment of bit-field [145] */
-       /* expect+8: error: cannot take size/alignment of bit-field [145] */
-       /* expect+7: error: cannot take size/alignment of bit-field [145] */
-       /* expect+6: error: cannot take size/alignment of bit-field [145] */
-       /* expect+5: error: cannot take size/alignment of bit-field [145] */
-       /* expect+4: error: cannot take size/alignment of bit-field [145] */
-       /* expect+3: error: cannot take size/alignment of bit-field [145] */
-       /* expect+2: error: cannot take size/alignment of bit-field [145] */
-       /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
        s.bits_5 = s.bits_3 & m;
-
-       /* expect+9: error: cannot take size/alignment of bit-field [145] */
-       /* expect+8: error: cannot take size/alignment of bit-field [145] */
-       /* expect+7: error: cannot take size/alignment of bit-field [145] */
-       /* expect+6: error: cannot take size/alignment of bit-field [145] */
-       /* expect+5: error: cannot take size/alignment of bit-field [145] */
-       /* expect+4: error: cannot take size/alignment of bit-field [145] */
-       /* expect+3: error: cannot take size/alignment of bit-field [145] */
-       /* expect+2: error: cannot take size/alignment of bit-field [145] */
-       /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
        s.bits_32 = s.bits_5 & m;
 
-       /* expect+4: error: cannot take size/alignment of bit-field [145] */
-       /* expect+3: error: cannot take size/alignment of bit-field [145] */
-       /* expect+2: error: cannot take size/alignment of bit-field [145] */
        /* expect+1: warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132] */
        return s.bits_32 & m;
 }
diff -r 98ea0105530d -r b1fc1ca91225 tests/usr.bin/xlint/lint1/msg_132.exp
--- a/tests/usr.bin/xlint/lint1/msg_132.exp     Sun May 29 23:09:43 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.exp     Sun May 29 23:24:09 2022 +0000
@@ -27,29 +27,5 @@
 msg_132.c(141): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
 msg_132.c(193): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
 msg_132.c(195): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(212): error: cannot take size/alignment of bit-field [145]
-msg_132.c(212): error: cannot take size/alignment of bit-field [145]
-msg_132.c(212): error: cannot take size/alignment of bit-field [145]
-msg_132.c(212): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): error: cannot take size/alignment of bit-field [145]
-msg_132.c(223): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): error: cannot take size/alignment of bit-field [145]
-msg_132.c(234): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(240): error: cannot take size/alignment of bit-field [145]
-msg_132.c(240): error: cannot take size/alignment of bit-field [145]
-msg_132.c(240): error: cannot take size/alignment of bit-field [145]
-msg_132.c(240): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]
+msg_132.c(209): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(215): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]
diff -r 98ea0105530d -r b1fc1ca91225 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun May 29 23:09:43 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun May 29 23:24:09 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.449 2022/05/26 20:17:40 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.450 2022/05/29 23:24:09 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.449 2022/05/26 20:17:40 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.450 2022/05/29 23:24:09 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -113,14 +113,20 @@
            (ic->bclr & ((uint64_t)1 << 63)) == 0;
 }
 
+static unsigned
+ic_length_in_bits(const type_t *tp)
+{
+
+       lint_assert(is_integer(tp->t_tspec));
+       return tp->t_bitfield ? tp->t_flen : size_in_bits(tp->t_tspec);
+}
+
 static integer_constraints
 ic_any(const type_t *tp)
 {
        integer_constraints c;
 
-       lint_assert(is_integer(tp->t_tspec));
-       unsigned int sz = type_size_in_bits(tp);
-       uint64_t vbits = value_bits(sz);
+       uint64_t vbits = value_bits(ic_length_in_bits(tp));
        if (is_uinteger(tp->t_tspec)) {
                c.smin = INT64_MIN;
                c.smax = INT64_MAX;
@@ -160,7 +166,7 @@
 ic_cvt(const type_t *ntp, const type_t *otp, integer_constraints a)
 {
 
-       if (type_size_in_bits(ntp) > type_size_in_bits(otp) &&
+       if (ic_length_in_bits(ntp) > ic_length_in_bits(otp) &&
            is_uinteger(otp->t_tspec))
                return a;
        return ic_any(ntp);
@@ -2394,7 +2400,7 @@
        debug_step("%s: type '%s'", __func__, type_name(tp));
        debug_node(tn);
 
-       uint64_t nmask = value_bits(type_size_in_bits(tp));
+       uint64_t nmask = value_bits(ic_length_in_bits(tp));
        if (!is_uinteger(tp->t_tspec))
                nmask >>= 1;
 



Home | Main Index | Thread Index | Old Index