Module Name: src
Committed By: rillig
Date: Sun May 29 23:24:09 UTC 2022
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c msg_132.exp
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: fix wrong errors about sizeof of a bit-field (since 2022-05-26)
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/msg_132.exp
cvs rdiff -u -r1.449 -r1.450 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.14 src/tests/usr.bin/xlint/lint1/msg_132.c:1.15
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.14 Sun May 29 23:09:43 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.c Sun May 29 23:24:09 2022
@@ -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 @@ struct bit_fields {
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;
}
Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.13 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.14
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.13 Sun May 29 23:09:43 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp Sun May 29 23:24:09 2022
@@ -27,29 +27,5 @@ msg_132.c(125): warning: function 'cover
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]
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.449 src/usr.bin/xlint/lint1/tree.c:1.450
--- src/usr.bin/xlint/lint1/tree.c:1.449 Thu May 26 20:17:40 2022
+++ src/usr.bin/xlint/lint1/tree.c Sun May 29 23:24:09 2022
@@ -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_maybe_signed(const type_t *tp, const
(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 @@ static integer_constraints
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 @@ can_represent(const type_t *tp, const tn
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;