Module Name: src
Committed By: rillig
Date: Thu May 12 20:49:21 UTC 2022
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile d_alignof.c d_alignof.exp
Added Files:
src/tests/usr.bin/xlint/lint1: msg_349.c msg_349.exp
Log Message:
tests/lint: add more tests for __alignof__
To generate a diff of this commit:
cvs rdiff -u -r1.1204 -r1.1205 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.122 -r1.123 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_alignof.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_alignof.exp
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_349.c \
src/tests/usr.bin/xlint/lint1/msg_349.exp
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.1204 src/distrib/sets/lists/tests/mi:1.1205
--- src/distrib/sets/lists/tests/mi:1.1204 Thu May 12 00:09:44 2022
+++ src/distrib/sets/lists/tests/mi Thu May 12 20:49:21 2022
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1204 2022/05/12 00:09:44 rillig Exp $
+# $NetBSD: mi,v 1.1205 2022/05/12 20:49:21 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -7275,6 +7275,8 @@
./usr/tests/usr.bin/xlint/lint1/msg_347.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_348.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_348.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_349.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_349.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/op_colon.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/op_colon.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.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.122 src/tests/usr.bin/xlint/lint1/Makefile:1.123
--- src/tests/usr.bin/xlint/lint1/Makefile:1.122 Thu May 12 00:09:44 2022
+++ src/tests/usr.bin/xlint/lint1/Makefile Thu May 12 20:49:21 2022
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.122 2022/05/12 00:09:44 rillig Exp $
+# $NetBSD: Makefile,v 1.123 2022/05/12 20:49:21 rillig Exp $
NOMAN= # defined
-MAX_MESSAGE= 348 # see lint1/err.c
+MAX_MESSAGE= 349 # see lint1/err.c
.include <bsd.own.mk>
Index: src/tests/usr.bin/xlint/lint1/d_alignof.c
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.5 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.6
--- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.5 Thu May 12 00:28:01 2022
+++ src/tests/usr.bin/xlint/lint1/d_alignof.c Thu May 12 20:49:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: d_alignof.c,v 1.5 2022/05/12 00:28:01 rillig Exp $ */
+/* $NetBSD: d_alignof.c,v 1.6 2022/05/12 20:49:21 rillig Exp $ */
# 3 "d_alignof.c"
/* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -46,3 +46,27 @@ plain_alignof_expr(void)
return alignof 3;
}
/* expect-1: warning: function plain_alignof_expr falls off bottom without returning value [217] */
+
+
+/*
+ * As with 'sizeof', the keyword '__alignof__' doesn't require parentheses
+ * when followed by an expression. This allows for the seemingly strange
+ * '->' after the parentheses, which in fact is perfectly fine.
+ *
+ * The NetBSD style guide says "We parenthesize sizeof expressions", even
+ * though it is misleading in edge cases like this. The GCC manual says that
+ * '__alignof__' and 'sizeof' are syntactically the same, therefore the same
+ * reasoning applies to '__alignof__'.
+ */
+unsigned long
+alignof_pointer_to_member(void)
+{
+ struct s {
+ unsigned long member;
+ } var = { 0 }, *ptr = &var;
+
+ /* FIXME: the syntax error is wrong, this is perfectly valid */
+ /* expect+1: error: syntax error '->' [249] */
+ return __alignof__(ptr)->member + ptr->member;
+}
+/* expect-1: warning: function alignof_pointer_to_member falls off bottom without returning value [217] */
Index: src/tests/usr.bin/xlint/lint1/d_alignof.exp
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.3 src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.4
--- src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.3 Thu May 12 00:28:01 2022
+++ src/tests/usr.bin/xlint/lint1/d_alignof.exp Thu May 12 20:49:21 2022
@@ -4,3 +4,5 @@ d_alignof.c(25): warning: function plain
d_alignof.c(46): error: 'alignof' undefined [99]
d_alignof.c(46): error: syntax error '3' [249]
d_alignof.c(47): warning: function plain_alignof_expr falls off bottom without returning value [217]
+d_alignof.c(70): error: syntax error '->' [249]
+d_alignof.c(71): warning: function alignof_pointer_to_member falls off bottom without returning value [217]
Added files:
Index: src/tests/usr.bin/xlint/lint1/msg_349.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_349.c:1.1
--- /dev/null Thu May 12 20:49:21 2022
+++ src/tests/usr.bin/xlint/lint1/msg_349.c Thu May 12 20:49:21 2022
@@ -0,0 +1,16 @@
+/* $NetBSD: msg_349.c,v 1.1 2022/05/12 20:49:21 rillig Exp $ */
+# 3 "msg_349.c"
+
+// Test for message 349: non type argument to alignof is a GCC extension [348]
+
+/* lint1-flags: -S -w */
+
+unsigned long c11_type = _Alignof(int);
+
+/* expect+1: warning: non type argument to alignof is a GCC extension [349] */
+unsigned long c11_expr = _Alignof(3);
+
+unsigned long gcc_type = __alignof__(int);
+
+/* expect+1: warning: non type argument to alignof is a GCC extension [349] */
+unsigned long gcc_expr = __alignof__(3);
Index: src/tests/usr.bin/xlint/lint1/msg_349.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_349.exp:1.1
--- /dev/null Thu May 12 20:49:21 2022
+++ src/tests/usr.bin/xlint/lint1/msg_349.exp Thu May 12 20:49:21 2022
@@ -0,0 +1,2 @@
+msg_349.c(11): warning: non type argument to alignof is a GCC extension [349]
+msg_349.c(16): warning: non type argument to alignof is a GCC extension [349]