From c1ebf8f4b6b0cab7163db1d41a86dcbb5a33333a Mon Sep 17 00:00:00 2001 From: rillig Date: Thu, 12 May 2022 20:49:21 +0000 Subject: [PATCH] tests/lint: add more tests for __alignof__ --- 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(-) create mode 100644 tests/usr.bin/xlint/lint1/msg_349.c create mode 100644 tests/usr.bin/xlint/lint1/msg_349.exp diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 66eeafd5c267..5ef6f6faa6c0 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -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 --git a/tests/usr.bin/xlint/lint1/Makefile b/tests/usr.bin/xlint/lint1/Makefile index 70ccce7ef004..68975e9003b8 100644 --- a/tests/usr.bin/xlint/lint1/Makefile +++ b/tests/usr.bin/xlint/lint1/Makefile @@ -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 diff --git a/tests/usr.bin/xlint/lint1/d_alignof.c b/tests/usr.bin/xlint/lint1/d_alignof.c index 7dc5fe6b601c..74ca1a0df2a3 100644 --- a/tests/usr.bin/xlint/lint1/d_alignof.c +++ b/tests/usr.bin/xlint/lint1/d_alignof.c @@ -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] */ diff --git a/tests/usr.bin/xlint/lint1/d_alignof.exp b/tests/usr.bin/xlint/lint1/d_alignof.exp index 315532eb7c35..8df4b59b9547 100644 --- a/tests/usr.bin/xlint/lint1/d_alignof.exp +++ b/tests/usr.bin/xlint/lint1/d_alignof.exp @@ -4,3 +4,5 @@ d_alignof.c(25): warning: function plain_alignof_type falls off bottom without r 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 --git a/tests/usr.bin/xlint/lint1/msg_349.c b/tests/usr.bin/xlint/lint1/msg_349.c new file mode 100644 index 000000000000..9d432afc1068 --- /dev/null +++ b/tests/usr.bin/xlint/lint1/msg_349.c @@ -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 --git a/tests/usr.bin/xlint/lint1/msg_349.exp b/tests/usr.bin/xlint/lint1/msg_349.exp new file mode 100644 index 000000000000..5e230ee2ba5a --- /dev/null +++ b/tests/usr.bin/xlint/lint1/msg_349.exp @@ -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]