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: include the width of bit-fields in...



details:   https://anonhg.NetBSD.org/src/rev/8fa8085ddfd9
branches:  trunk
changeset: 368295:8fa8085ddfd9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 03 14:35:54 2022 +0000

description:
lint: include the width of bit-fields in the type name

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c |   6 +++---
 usr.bin/xlint/common/tyname.c       |  11 +++++++++--
 usr.bin/xlint/lint1/decl.c          |  16 +++++++++++-----
 3 files changed, 23 insertions(+), 10 deletions(-)

diffs (105 lines):

diff -r 15adc3b7b8af -r 8fa8085ddfd9 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Sun Jul 03 14:15:38 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Sun Jul 03 14:35:54 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.20 2022/07/02 09:48:18 rillig Exp $      */
+/*     $NetBSD: msg_132.c,v 1.21 2022/07/03 14:35:54 rillig Exp $      */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -233,13 +233,13 @@
 unsigned char
 test_bit_fields(struct bit_fields s, unsigned long long m)
 {
-       /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132] */
+       /* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned int:3' may lose accuracy [132] */
        s.bits_3 = s.bits_32 & m;
 
        s.bits_5 = s.bits_3 & m;
        s.bits_32 = s.bits_5 & m;
 
-       /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */
+       /* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned char' may lose accuracy [132] */
        return s.bits_32 & m;
 }
 
diff -r 15adc3b7b8af -r 8fa8085ddfd9 usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sun Jul 03 14:15:38 2022 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sun Jul 03 14:35:54 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.52 2022/06/21 22:10:30 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.53 2022/07/03 14:35:54 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.52 2022/06/21 22:10:30 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.53 2022/07/03 14:35:54 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -269,6 +269,13 @@
 #endif
        buf_add(&buf, tspec_name(t));
 
+#ifdef IS_LINT1
+       if (tp->t_bitfield) {
+               buf_add(&buf, ":");
+               buf_add_int(&buf, (int)tp->t_flen);
+       }
+#endif
+
        switch (t) {
        case PTR:
                buf_add(&buf, " to ");
diff -r 15adc3b7b8af -r 8fa8085ddfd9 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Jul 03 14:15:38 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Jul 03 14:35:54 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.293 2022/06/22 19:23:17 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.294 2022/07/03 14:35:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.293 2022/06/22 19:23:17 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.294 2022/07/03 14:35:54 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1052,11 +1052,15 @@
                if (!bitfieldtype_ok) {
                        /* TODO: Make this an error in C99 mode as well. */
                        if (!allow_trad && !allow_c99) {
+                               type_t *btp = block_dup_type(tp);
+                               btp->t_bitfield = false;
                                /* bit-field type '%s' invalid in ANSI C */
-                               warning(273, type_name(tp));
+                               warning(273, type_name(btp));
                        } else if (pflag) {
+                               type_t *btp = block_dup_type(tp);
+                               btp->t_bitfield = false;
                                /* nonportable bit-field type '%s' */
-                               warning(34, type_name(tp));
+                               warning(34, type_name(btp));
                        }
                }
        } else if (t == INT && dcs->d_sign_mod == NOTSPEC) {
@@ -1067,8 +1071,10 @@
        } else if (!(t == INT || t == UINT || t == BOOL ||
                     (is_integer(t) && (bitfieldtype_ok || allow_gcc)))) {
 
+               type_t *btp = block_dup_type(tp);
+               btp->t_bitfield = false;
                /* illegal bit-field type '%s' */
-               warning(35, type_name(tp));
+               warning(35, type_name(btp));
 
                unsigned int sz = tp->t_flen;
                dsym->s_type = tp = block_dup_type(gettyp(t = INT));



Home | Main Index | Thread Index | Old Index