Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tests/lint: add platform-specific tests for troublesome poin...
details: https://anonhg.NetBSD.org/src/rev/df394842a5cd
branches: trunk
changeset: 377281:df394842a5cd
user: rillig <rillig%NetBSD.org@localhost>
date: Wed Jul 05 11:36:56 2023 +0000
description:
tests/lint: add platform-specific tests for troublesome pointer casts
diffstat:
distrib/sets/lists/tests/mi | 5 +-
tests/usr.bin/xlint/lint1/msg_247.c | 17 +-
tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c | 1205 +++++++++++++++++++++
tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c | 1211 +++++++++++++++++++++
tests/usr.bin/xlint/lint1/msg_247_portable.c | 1238 ++++++++++++++++++++++
5 files changed, 3671 insertions(+), 5 deletions(-)
diffs (truncated from 3728 to 300 lines):
diff -r fa5d7dfd13de -r df394842a5cd distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Wed Jul 05 10:59:08 2023 +0000
+++ b/distrib/sets/lists/tests/mi Wed Jul 05 11:36:56 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1273 2023/07/03 15:29:42 rillig Exp $
+# $NetBSD: mi,v 1.1274 2023/07/05 11:36:56 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -7220,6 +7220,9 @@
./usr/tests/usr.bin/xlint/lint1/msg_246.exp tests-obsolete obsolete,atf
./usr/tests/usr.bin/xlint/lint1/msg_247.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_247.exp tests-obsolete obsolete,atf
+./usr/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_247_portable.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_248.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/msg_248.exp tests-obsolete obsolete,atf
./usr/tests/usr.bin/xlint/lint1/msg_249.c tests-usr.bin-tests compattestfile,atf
diff -r fa5d7dfd13de -r df394842a5cd tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c Wed Jul 05 10:59:08 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c Wed Jul 05 11:36:56 2023 +0000
@@ -1,8 +1,17 @@
-/* $NetBSD: msg_247.c,v 1.29 2023/04/22 17:42:29 rillig Exp $ */
+/* $NetBSD: msg_247.c,v 1.30 2023/07/05 11:36:56 rillig Exp $ */
# 3 "msg_247.c"
// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
+/*
+ * The word 'may' in the message text means that the trouble is not necessarily
+ * on this platform with its specific type sizes, but on other platforms.
+ *
+ * See also:
+ * msg_247_portable.c
+ * msg_247_lp64.c
+ */
+
/* lint1-extra-flags: -c -X 351 */
/* example taken from Xlib.h */
@@ -166,7 +175,7 @@ lh_OPENSSL_STRING_new(void)
*/
return (struct lhash_st_OPENSSL_STRING *)OPENSSL_LH_new();
}
-# 170 "msg_247.c" 2
+# 179 "msg_247.c" 2
void sink(const void *);
@@ -355,9 +364,9 @@ static anything *p_anything;
void
conversions_from_and_to_union(void)
{
- /* Self-assignment, disguided by a cast to its own type. */
+ /* Self-assignment, disguised by a cast to its own type. */
p_int = (int *)p_int;
- /* Self-assignment, disguided by a cast to a pointer. */
+ /* Self-assignment, disguised by a cast to a pointer. */
p_int = (void *)p_int;
/* expect+1: warning: illegal combination of 'pointer to int' and 'pointer to double', op '=' [124] */
diff -r fa5d7dfd13de -r df394842a5cd tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c Wed Jul 05 11:36:56 2023 +0000
@@ -0,0 +1,1205 @@
+/* $NetBSD: msg_247_ilp32_ldbl64.c,v 1.1 2023/07/05 11:36:56 rillig Exp $ */
+# 3 "msg_247_ilp32.c"
+
+// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
+
+// In non-portable mode, lint warns based on the actual type sizes.
+//
+// See also:
+// msg_247_lp64.c
+// msg_247_portable.c
+
+/* lint1-only-if: ilp32 ldbl-64 */
+/* lint1-extra-flags: -c -X 351 */
+
+typedef double double_array[5];
+typedef struct {
+ char member;
+} char_struct;
+typedef struct {
+ double member;
+} double_struct;
+typedef union {
+ char member;
+} char_union;
+typedef union {
+ double member;
+} double_union;
+typedef enum {
+ CONSTANT
+} int_enum;
+typedef void (*function_pointer)(void);
+
+static _Bool *bool_ptr;
+static char *char_ptr;
+static signed char *schar_ptr;
+static unsigned char *uchar_ptr;
+static short *short_ptr;
+static unsigned short *ushort_ptr;
+static int *int_ptr;
+static unsigned int *uint_ptr;
+static long *long_ptr;
+static unsigned long *ulong_ptr;
+static long long *llong_ptr;
+static unsigned long long *ullong_ptr;
+// No int128_t, as that is only supported on LP64 platforms.
+static float *float_ptr;
+static double *double_ptr;
+static long double *ldouble_ptr;
+static float _Complex *fcomplex_ptr;
+static double _Complex *dcomplex_ptr;
+static long double _Complex *lcomplex_ptr;
+static void *void_ptr;
+static char_struct *char_struct_ptr;
+static double_struct *double_struct_ptr;
+static char_union *char_union_ptr;
+static double_union *double_union_ptr;
+static int_enum *enum_ptr;
+static double_array *double_array_ptr;
+static function_pointer func_ptr;
+
+void
+all_casts(void)
+{
+ bool_ptr = (typeof(bool_ptr))bool_ptr;
+ bool_ptr = (typeof(bool_ptr))char_ptr;
+ bool_ptr = (typeof(bool_ptr))schar_ptr;
+ bool_ptr = (typeof(bool_ptr))uchar_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to short' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))short_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned short' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))ushort_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to int' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))int_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned int' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))uint_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))long_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))ulong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long long' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))llong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long long' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))ullong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to float' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))float_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to double' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))double_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long double' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))ldouble_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to float _Complex' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))fcomplex_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to double _Complex' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))dcomplex_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long double _Complex' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))lcomplex_ptr;
+ bool_ptr = (typeof(bool_ptr))void_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to struct typedef char_struct' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))char_struct_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to struct typedef double_struct' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))double_struct_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to union typedef char_union' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))char_union_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to union typedef double_union' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))double_union_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to enum typedef int_enum' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))enum_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to array[5] of double' to 'pointer to _Bool' may be troublesome [247] */
+ bool_ptr = (typeof(bool_ptr))double_array_ptr;
+ /* expect+1: warning: converting 'pointer to function(void) returning void' to 'pointer to _Bool' is questionable [229] */
+ bool_ptr = (typeof(bool_ptr))func_ptr;
+
+ char_ptr = (typeof(char_ptr))bool_ptr;
+ char_ptr = (typeof(char_ptr))char_ptr;
+ char_ptr = (typeof(char_ptr))schar_ptr;
+ char_ptr = (typeof(char_ptr))uchar_ptr;
+ char_ptr = (typeof(char_ptr))short_ptr;
+ char_ptr = (typeof(char_ptr))ushort_ptr;
+ char_ptr = (typeof(char_ptr))int_ptr;
+ char_ptr = (typeof(char_ptr))uint_ptr;
+ char_ptr = (typeof(char_ptr))long_ptr;
+ char_ptr = (typeof(char_ptr))ulong_ptr;
+ char_ptr = (typeof(char_ptr))llong_ptr;
+ char_ptr = (typeof(char_ptr))ullong_ptr;
+ char_ptr = (typeof(char_ptr))float_ptr;
+ char_ptr = (typeof(char_ptr))double_ptr;
+ char_ptr = (typeof(char_ptr))ldouble_ptr;
+ char_ptr = (typeof(char_ptr))fcomplex_ptr;
+ char_ptr = (typeof(char_ptr))dcomplex_ptr;
+ char_ptr = (typeof(char_ptr))lcomplex_ptr;
+ char_ptr = (typeof(char_ptr))void_ptr;
+ char_ptr = (typeof(char_ptr))char_struct_ptr;
+ char_ptr = (typeof(char_ptr))double_struct_ptr;
+ char_ptr = (typeof(char_ptr))char_union_ptr;
+ char_ptr = (typeof(char_ptr))double_union_ptr;
+ char_ptr = (typeof(char_ptr))enum_ptr;
+ char_ptr = (typeof(char_ptr))double_array_ptr;
+ /* expect+1: warning: converting 'pointer to function(void) returning void' to 'pointer to char' is questionable [229] */
+ char_ptr = (typeof(char_ptr))func_ptr;
+
+ schar_ptr = (typeof(schar_ptr))bool_ptr;
+ schar_ptr = (typeof(schar_ptr))char_ptr;
+ schar_ptr = (typeof(schar_ptr))schar_ptr;
+ schar_ptr = (typeof(schar_ptr))uchar_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to short' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))short_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned short' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))ushort_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to int' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))int_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned int' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))uint_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))long_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))ulong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long long' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))llong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long long' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))ullong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to float' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))float_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to double' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))double_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long double' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))ldouble_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to float _Complex' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))fcomplex_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to double _Complex' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))dcomplex_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long double _Complex' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))lcomplex_ptr;
+ schar_ptr = (typeof(schar_ptr))void_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to struct typedef char_struct' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))char_struct_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to struct typedef double_struct' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))double_struct_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to union typedef char_union' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))char_union_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to union typedef double_union' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))double_union_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to enum typedef int_enum' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))enum_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to array[5] of double' to 'pointer to signed char' may be troublesome [247] */
+ schar_ptr = (typeof(schar_ptr))double_array_ptr;
+ /* expect+1: warning: converting 'pointer to function(void) returning void' to 'pointer to signed char' is questionable [229] */
+ schar_ptr = (typeof(schar_ptr))func_ptr;
+
+ uchar_ptr = (typeof(uchar_ptr))bool_ptr;
+ uchar_ptr = (typeof(uchar_ptr))char_ptr;
+ uchar_ptr = (typeof(uchar_ptr))schar_ptr;
+ uchar_ptr = (typeof(uchar_ptr))uchar_ptr;
+ uchar_ptr = (typeof(uchar_ptr))short_ptr;
+ uchar_ptr = (typeof(uchar_ptr))ushort_ptr;
+ uchar_ptr = (typeof(uchar_ptr))int_ptr;
+ uchar_ptr = (typeof(uchar_ptr))uint_ptr;
+ uchar_ptr = (typeof(uchar_ptr))long_ptr;
+ uchar_ptr = (typeof(uchar_ptr))ulong_ptr;
+ uchar_ptr = (typeof(uchar_ptr))llong_ptr;
+ uchar_ptr = (typeof(uchar_ptr))ullong_ptr;
+ uchar_ptr = (typeof(uchar_ptr))float_ptr;
+ uchar_ptr = (typeof(uchar_ptr))double_ptr;
+ uchar_ptr = (typeof(uchar_ptr))ldouble_ptr;
+ uchar_ptr = (typeof(uchar_ptr))fcomplex_ptr;
+ uchar_ptr = (typeof(uchar_ptr))dcomplex_ptr;
+ uchar_ptr = (typeof(uchar_ptr))lcomplex_ptr;
+ uchar_ptr = (typeof(uchar_ptr))void_ptr;
+ uchar_ptr = (typeof(uchar_ptr))char_struct_ptr;
+ uchar_ptr = (typeof(uchar_ptr))double_struct_ptr;
+ uchar_ptr = (typeof(uchar_ptr))char_union_ptr;
+ uchar_ptr = (typeof(uchar_ptr))double_union_ptr;
+ uchar_ptr = (typeof(uchar_ptr))enum_ptr;
+ uchar_ptr = (typeof(uchar_ptr))double_array_ptr;
+ /* expect+1: warning: converting 'pointer to function(void) returning void' to 'pointer to unsigned char' is questionable [229] */
+ uchar_ptr = (typeof(uchar_ptr))func_ptr;
+
+ /* expect+1: warning: pointer cast from 'pointer to _Bool' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))bool_ptr;
+ short_ptr = (typeof(short_ptr))char_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to signed char' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))schar_ptr;
+ short_ptr = (typeof(short_ptr))uchar_ptr;
+ short_ptr = (typeof(short_ptr))short_ptr;
+ short_ptr = (typeof(short_ptr))ushort_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to int' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))int_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned int' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))uint_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))long_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))ulong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to long long' to 'pointer to short' may be troublesome [247] */
+ short_ptr = (typeof(short_ptr))llong_ptr;
+ /* expect+1: warning: pointer cast from 'pointer to unsigned long long' to 'pointer to short' may be troublesome [247] */
Home |
Main Index |
Thread Index |
Old Index