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 tests/lint: demonstrate bugs in anonymou...
details: https://anonhg.NetBSD.org/src/rev/e2c0efba9f5b
branches: trunk
changeset: 377179:e2c0efba9f5b
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 30 07:18:02 2023 +0000
description:
tests/lint: demonstrate bugs in anonymous struct/union handling
diffstat:
tests/usr.bin/xlint/lint1/expr_sizeof.c | 42 ++++++++++++++++++++++++++++++++-
usr.bin/xlint/lint1/decl.c | 6 +++-
2 files changed, 45 insertions(+), 3 deletions(-)
diffs (85 lines):
diff -r 8ad59c199b21 -r e2c0efba9f5b tests/usr.bin/xlint/lint1/expr_sizeof.c
--- a/tests/usr.bin/xlint/lint1/expr_sizeof.c Fri Jun 30 02:03:58 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c Fri Jun 30 07:18:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_sizeof.c,v 1.6 2023/06/28 21:41:27 rillig Exp $ */
+/* $NetBSD: expr_sizeof.c,v 1.7 2023/06/30 07:18:02 rillig Exp $ */
# 3 "expr_sizeof.c"
/*
@@ -74,6 +74,46 @@ variable_length_array(int n)
typedef int sizeof_local_arr[-(int)sizeof(local_arr)];
}
+void
+bit_fields(void)
+{
+ struct {
+ _Bool flag0:1;
+ _Bool flag1:1;
+ _Bool flag2:1;
+ } flags;
+ /* expect+1: error: negative array dimension (-1) [20] */
+ typedef int sizeof_flags[-(int)sizeof(flags)];
+
+ struct {
+ struct {
+ _Bool flag0:1;
+ _Bool flag1:1;
+ _Bool flag2:1;
+ };
+ } anonymous_flags;
+ /* FIXME: sizeof must be 1, not 0. */
+ typedef int sizeof_anonymous_flags[-(int)sizeof(anonymous_flags)];
+
+ struct {
+ unsigned int bits0:16;
+ unsigned int bits1:16;
+ } same_storage_unit;
+ /* expect+1: error: negative array dimension (-4) [20] */
+ typedef int sizeof_same_storage_unit[-(int)sizeof(same_storage_unit)];
+
+ // Detect whether a bit-field can span multiple storage units.
+ // If so, the size is 12, if not, the size is 16.
+ struct {
+ unsigned int bits0:24;
+ unsigned int bits1:24;
+ unsigned int bits2:24;
+ unsigned int bits3:24;
+ } cross_storage_unit;
+ /* expect+1: error: negative array dimension (-16) [20] */
+ typedef int sizeof_cross_storage_unit[-(int)sizeof(cross_storage_unit)];
+}
+
/*
* Ensure that anonymous structs and unions are handled correctly. They were
* added in C11, and lint did not properly support them until 2023.
diff -r 8ad59c199b21 -r e2c0efba9f5b usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Fri Jun 30 02:03:58 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c Fri Jun 30 07:18:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.323 2023/06/29 22:52:44 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.324 2023/06/30 07:18:02 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.323 2023/06/29 22:52:44 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.324 2023/06/30 07:18:02 rillig Exp $");
#endif
#include <sys/param.h>
@@ -463,8 +463,10 @@ bit_field_width(sym_t **mem)
width += (*mem)->s_type->t_bit_field_width;
*mem = (*mem)->s_next;
}
+
// XXX: Why INT_SIZE? C99 6.7.2.1p4 allows bit-fields to have type
// XXX: _Bool or another implementation-defined type.
+ // XXX: Why round down instead of up? See expr_sizeof.c, anonymous_flags.
return width - width % INT_SIZE;
}
Home |
Main Index |
Thread Index |
Old Index