Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: demonstrate wrong size...



details:   https://anonhg.NetBSD.org/src/rev/95183d630c05
branches:  trunk
changeset: 376687:95183d630c05
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 28 21:41:27 2023 +0000

description:
tests/lint: demonstrate wrong size calculation in anonymous union

diffstat:

 tests/usr.bin/xlint/lint1/expr_sizeof.c |  29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diffs (40 lines):

diff -r dd9655109aa0 -r 95183d630c05 tests/usr.bin/xlint/lint1/expr_sizeof.c
--- a/tests/usr.bin/xlint/lint1/expr_sizeof.c   Wed Jun 28 20:51:31 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c   Wed Jun 28 21:41:27 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expr_sizeof.c,v 1.5 2023/03/28 14:44:34 rillig Exp $   */
+/*     $NetBSD: expr_sizeof.c,v 1.6 2023/06/28 21:41:27 rillig Exp $   */
 # 3 "expr_sizeof.c"
 
 /*
@@ -73,3 +73,30 @@ variable_length_array(int n)
        /* expect+1: error: negative array dimension (-4) [20] */
        typedef int sizeof_local_arr[-(int)sizeof(local_arr)];
 }
+
+/*
+ * Ensure that anonymous structs and unions are handled correctly.  They were
+ * added in C11, and lint did not properly support them until 2023.
+ */
+void
+anonymous_struct_and_union(void)
+{
+       struct {
+               union {
+                       unsigned char uc16[16];
+                       unsigned char uc32[32];
+               };
+       } su_16_32;
+       /* FIXME: Must be 32, not 48. */
+       /* expect+1: error: negative array dimension (-48) [20] */
+       typedef int sizeof_su_16_32[-(int)sizeof(su_16_32)];
+
+       union {
+               struct {
+                       unsigned char uc16[16];
+                       unsigned char uc32[32];
+               };
+       } us_16_32;
+       /* expect+1: error: negative array dimension (-48) [20] */
+       typedef int sizeof_us_16_32[-(int)sizeof(us_16_32)];
+}



Home | Main Index | Thread Index | Old Index