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: extend tests for sizeo...



details:   https://anonhg.NetBSD.org/src/rev/feba680573a9
branches:  trunk
changeset: 377188:feba680573a9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 30 16:39:17 2023 +0000

description:
tests/lint: extend tests for sizeof and alignof

diffstat:

 tests/usr.bin/xlint/lint1/d_alignof.c   |  11 +++++++-
 tests/usr.bin/xlint/lint1/expr_sizeof.c |  39 ++++++++++++++++++++++++++++++++-
 2 files changed, 47 insertions(+), 3 deletions(-)

diffs (89 lines):

diff -r 45f343f193db -r feba680573a9 tests/usr.bin/xlint/lint1/d_alignof.c
--- a/tests/usr.bin/xlint/lint1/d_alignof.c     Fri Jun 30 15:19:09 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.c     Fri Jun 30 16:39:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_alignof.c,v 1.10 2023/06/30 09:26:03 rillig Exp $    */
+/*     $NetBSD: d_alignof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $    */
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -108,6 +108,9 @@ alignof_variants(void)
        /* expect+1: error: cannot take size/alignment of incomplete type [143] */
        typedef int incomplete_enum[-(int)__alignof(enum incomplete_enum)];
 
+       /* expect+1: error: cannot take size/alignment of incomplete type [143] */
+       typedef int incomplete_array[-(int)__alignof(int[])];
+
        struct bit_fields {
                _Bool bit_field:1;
        };
@@ -117,7 +120,11 @@ alignof_variants(void)
         */
        /* expect+2: error: cannot initialize typedef '00000000_tmp' [25] */
        /* expect+1: error: cannot take size/alignment of bit-field [145] */
-       typedef int bit_field[-(int)__alignof((struct bit_fields){0}.bit_field)];
+       typedef int bit_field_1[-(int)__alignof((struct bit_fields){0}.bit_field)];
+
+       struct bit_fields bit_fields;
+       /* expect+1: error: cannot take size/alignment of bit-field [145] */
+       typedef int bit_field_2[-(int)__alignof(bit_fields.bit_field)];
 
        /* expect+1: error: cannot take size/alignment of void [146] */
        typedef int plain_void[-(int)__alignof(void)];
diff -r 45f343f193db -r feba680573a9 tests/usr.bin/xlint/lint1/expr_sizeof.c
--- a/tests/usr.bin/xlint/lint1/expr_sizeof.c   Fri Jun 30 15:19:09 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c   Fri Jun 30 16:39:17 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expr_sizeof.c,v 1.10 2023/06/30 15:19:09 rillig Exp $  */
+/*     $NetBSD: expr_sizeof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $  */
 # 3 "expr_sizeof.c"
 
 /*
@@ -11,6 +11,7 @@
 /*
  * A sizeof expression can either take a type name or an expression.
  */
+
 void sink(unsigned long);
 
 struct {
@@ -164,3 +165,39 @@ anonymous_struct_and_union(void)
        /* expect+1: error: negative array dimension (-48) [20] */
        typedef int sizeof_us_16_32[-(int)sizeof(us_16_32)];
 }
+
+
+void
+sizeof_errors(void)
+{
+       /* expect+1: error: cannot take size/alignment of void [146] */
+       typedef int sizeof_void[-(int)sizeof(void)];
+
+       /*
+        * A 'void array' gets replaced with an 'int array' before
+        * type_size_in_bits gets to see it, thus the 256 * 4 = 1024.
+        */
+       /* expect+2: error: illegal use of 'void' [18] */
+       /* expect+1: error: negative array dimension (-1024) [20] */
+       typedef int sizeof_void_array[-(int)sizeof(void[256])];
+
+       /* expect+1: warning: enum 'incomplete_enum' never defined [235] */
+       enum incomplete_enum;
+       /* expect+2: warning: cannot take size/alignment of incomplete type [143] */
+       /* expect+1: error: negative array dimension (-4) [20] */
+       typedef int sizeof_incomplete_enum[-(int)sizeof(enum incomplete_enum)];
+}
+
+
+/*
+ * Due to the 'double' member, the alignment of this struct is 8, so the size
+ * has to be 24 (or at least divisible by 8), otherwise the 'double' member
+ * would not get the correct alignment in an array of this struct.
+ */
+struct s24 {
+       char c0;
+       double d8;
+       char c16;
+};
+/* expect+1: error: negative array dimension (-24) [20] */
+typedef int sizeof_s24[-(int)sizeof(struct s24)];



Home | Main Index | Thread Index | Old Index