Source-Changes-HG archive

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

[src/trunk]: src tests/lint: add more tests for __alignof__



details:   https://anonhg.NetBSD.org/src/rev/496a2fd0e652
branches:  trunk
changeset: 366059:496a2fd0e652
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 12 20:49:21 2022 +0000

description:
tests/lint: add more tests for __alignof__

diffstat:

 distrib/sets/lists/tests/mi             |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile      |   4 ++--
 tests/usr.bin/xlint/lint1/d_alignof.c   |  26 +++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_alignof.exp |   2 ++
 tests/usr.bin/xlint/lint1/msg_349.c     |  16 ++++++++++++++++
 tests/usr.bin/xlint/lint1/msg_349.exp   |   2 ++
 6 files changed, 50 insertions(+), 4 deletions(-)

diffs (103 lines):

diff -r f813dbae260f -r 496a2fd0e652 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu May 12 20:22:58 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Thu May 12 20:49:21 2022 +0000
@@ -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
diff -r f813dbae260f -r 496a2fd0e652 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Thu May 12 20:22:58 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Thu May 12 20:49:21 2022 +0000
@@ -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>
 
diff -r f813dbae260f -r 496a2fd0e652 tests/usr.bin/xlint/lint1/d_alignof.c
--- a/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 20:22:58 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 20:49:21 2022 +0000
@@ -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 @@
        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] */
diff -r f813dbae260f -r 496a2fd0e652 tests/usr.bin/xlint/lint1/d_alignof.exp
--- a/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 20:22:58 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 20:49:21 2022 +0000
@@ -4,3 +4,5 @@
 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]
diff -r f813dbae260f -r 496a2fd0e652 tests/usr.bin/xlint/lint1/msg_349.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_349.c       Thu May 12 20:49:21 2022 +0000
@@ -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);
diff -r f813dbae260f -r 496a2fd0e652 tests/usr.bin/xlint/lint1/msg_349.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_349.exp     Thu May 12 20:49:21 2022 +0000
@@ -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]



Home | Main Index | Thread Index | Old Index