tests/lint: add more tests for __alignof__
This commit is contained in:
parent
6ddc1e42c5
commit
c1ebf8f4b6
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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] */
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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);
|
|
@ -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]
|
Loading…
Reference in New Issue