Module Name: src
Committed By: rillig
Date: Sun Jan 15 00:53:19 UTC 2023
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
src/tests/usr.bin/xlint/lint1: expr_sizeof.c
Log Message:
tests/lint: add test for parsing sizeof expressions
To generate a diff of this commit:
cvs rdiff -u -r1.1240 -r1.1241 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.130 -r1.131 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_sizeof.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1240 src/distrib/sets/lists/tests/mi:1.1241
--- src/distrib/sets/lists/tests/mi:1.1240 Sun Jan 15 00:34:10 2023
+++ src/distrib/sets/lists/tests/mi Sun Jan 15 00:53:19 2023
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1240 2023/01/15 00:34:10 rillig Exp $
+# $NetBSD: mi,v 1.1241 2023/01/15 00:53:19 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6553,6 +6553,7 @@
./usr/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_range.exp tests-obsolete obsolete,atf
+./usr/tests/usr.bin/xlint/lint1/expr_sizeof.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.exp tests-obsolete obsolete,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute.c tests-usr.bin-tests compattestfile,atf
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.130 src/tests/usr.bin/xlint/lint1/Makefile:1.131
--- src/tests/usr.bin/xlint/lint1/Makefile:1.130 Wed Jan 4 05:25:08 2023
+++ src/tests/usr.bin/xlint/lint1/Makefile Sun Jan 15 00:53:19 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.130 2023/01/04 05:25:08 rillig Exp $
+# $NetBSD: Makefile,v 1.131 2023/01/15 00:53:19 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 349 # see lint1/err.c
@@ -111,6 +111,7 @@ FILES+= expr_promote.exp-ln
FILES+= expr_promote_trad.c
FILES+= expr_promote_trad.exp-ln
FILES+= expr_range.c
+FILES+= expr_sizeof.c
FILES+= feat_stacktrace.c
FILES+= gcc_attribute.c
FILES+= gcc_attribute_aligned.c
Added files:
Index: src/tests/usr.bin/xlint/lint1/expr_sizeof.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.1
--- /dev/null Sun Jan 15 00:53:19 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c Sun Jan 15 00:53:19 2023
@@ -0,0 +1,51 @@
+/* $NetBSD: expr_sizeof.c,v 1.1 2023/01/15 00:53:19 rillig Exp $ */
+# 3 "expr_sizeof.c"
+
+/*
+ * C99 6.5.3.4 "The sizeof operator"
+ * C11 6.5.3.4 "The sizeof operator"
+ */
+
+/*
+ * A sizeof expression can either take a type name or an expression.
+ */
+void sink(unsigned long);
+
+struct {
+ int member;
+} s, *ps;
+
+/*
+ * In a sizeof expression taking a type name, the type name must be enclosed
+ * in parentheses.
+ */
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_int[-(int)sizeof(int)];
+
+/*
+ * In a sizeof expression taking an expression, the expression may or may not
+ * be enclosed in parentheses, like any other expression.
+ */
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_paren_zero[-(int)sizeof(0)];
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_zero[-(int)sizeof 0];
+
+/*
+ * Even though 's' is not a constant expression, 'sizeof s' is.
+ */
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_global_var[-(int)sizeof s];
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_paren_global_var[-(int)sizeof(s)];
+
+/*
+ * Even though 'sizeof(s)' may look like a function call expression, the
+ * parentheses around 's' are ordinary parentheses and do not influence the
+ * associativity. Therefore, the '.' following the '(s)' takes precedence
+ * over the 'sizeof'. Same for the '->' following the '(ps)'.
+ */
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_paren_global_struct_member[-(int)sizeof(s).member];
+/* expect+1: error: negative array dimension (-4) [20] */
+typedef int sizeof_paren_global_ptr_struct_member[-(int)sizeof(ps)->member];