Module Name:    src
Committed By:   rillig
Date:           Wed May  1 12:36:56 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: decl.c decl_enum.c

Log Message:
tests/lint: test large enum constants and offsetof with array members


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_enum.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/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.28 src/tests/usr.bin/xlint/lint1/decl.c:1.29
--- src/tests/usr.bin/xlint/lint1/decl.c:1.28	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/decl.c	Wed May  1 12:36:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.28 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.29 2024/05/01 12:36:56 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -241,3 +241,24 @@ get_x(struct point3d { struct point3d_nu
 	static struct point3d_number z;
 	return arg.x.v + local.x.v + z.v;
 }
+
+// Expressions of the form '(size_t)&null_ptr->member' are used by several
+// C implementations to implement the offsetof macro.  Dereferencing a null
+// pointer invokes undefined behavior, though, even in this form.
+void
+offsetof_on_array_member(void)
+{
+	struct s1 {
+		int padding, plain, arr[2];
+	};
+
+	struct s2 {
+		unsigned int off_plain:(unsigned long)&((struct s1 *)0)->plain;
+		// FIXME: offsetof must work for array members as well.
+		/* expect+1: error: integral constant expression expected [55] */
+		unsigned int off_arr:(unsigned long)&((struct s1 *)0)->arr;
+		// FIXME: offsetof must work for array members as well.
+		/* expect+1: error: integral constant expression expected [55] */
+		unsigned int off_arr_element:(unsigned long)&((struct s1 *)0)->arr[0];
+	};
+}

Index: src/tests/usr.bin/xlint/lint1/decl_enum.c
diff -u src/tests/usr.bin/xlint/lint1/decl_enum.c:1.4 src/tests/usr.bin/xlint/lint1/decl_enum.c:1.5
--- src/tests/usr.bin/xlint/lint1/decl_enum.c:1.4	Fri Jun 30 21:39:54 2023
+++ src/tests/usr.bin/xlint/lint1/decl_enum.c	Wed May  1 12:36:56 2024
@@ -1,10 +1,22 @@
-/*	$NetBSD: decl_enum.c,v 1.4 2023/06/30 21:39:54 rillig Exp $	*/
+/*	$NetBSD: decl_enum.c,v 1.5 2024/05/01 12:36:56 rillig Exp $	*/
 # 3 "decl_enum.c"
 
 /*
  * Tests for enum declarations.
  */
 
+
+// Initializing an enum from a 64-bit value cuts off the upper bits.
+// TIME_MIN thus gets truncated from 0x8000_0000_0000_0000 to 0.
+// TIME_MAX thus gets truncated from 0x7fff_ffff_ffff_ffff to -1.
+enum {
+	/* expect+1: warning: integral constant too large [56] */
+	TIME_MIN = (long long)(1ULL << 63),
+	/* expect+1: warning: integral constant too large [56] */
+	TIME_MAX = (long long)~(1ULL << 63),
+};
+
+
 /* cover 'enumerator_list: error' */
 enum {
 	/* expect+1: error: syntax error 'goto' [249] */

Reply via email to