Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test conversion from long long to intptr_t on ilp32



details:   https://anonhg.NetBSD.org/src/rev/646352a69803
branches:  trunk
changeset: 1023116:646352a69803
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Aug 25 22:04:51 2021 +0000

description:
tests/lint: test conversion from long long to intptr_t on ilp32

Seen in usr.bin/make/var.c:1608.

diffstat:

 distrib/sets/lists/tests/mi                      |   4 ++-
 tests/usr.bin/xlint/lint1/Makefile               |   4 ++-
 tests/usr.bin/xlint/lint1/decl_struct_member.c   |  18 ++++++++++++-
 tests/usr.bin/xlint/lint1/decl_struct_member.exp |   5 ++-
 tests/usr.bin/xlint/lint1/msg_132.c              |  13 +++++++++-
 tests/usr.bin/xlint/lint1/msg_132.exp            |   2 +
 tests/usr.bin/xlint/lint1/msg_132_ilp32.c        |  32 ++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/msg_132_ilp32.exp      |   1 +
 8 files changed, 73 insertions(+), 6 deletions(-)

diffs (154 lines):

diff -r 879f02cef5f1 -r 646352a69803 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Wed Aug 25 22:00:26 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Wed Aug 25 22:04:51 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1116 2021/08/24 21:30:52 rillig Exp $
+# $NetBSD: mi,v 1.1117 2021/08/25 22:04:51 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6583,6 +6583,8 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_131.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_132.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_132.exp                    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_132_ilp32.c                        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_132_ilp32.exp              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_133.c                      tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_133.exp                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_134.c                      tests-usr.bin-tests     compattestfile,atf
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Wed Aug 25 22:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Wed Aug 25 22:04:51 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.106 2021/08/22 20:56:51 rillig Exp $
+# $NetBSD: Makefile,v 1.107 2021/08/25 22:04:52 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   346             # see lint1/err.c
@@ -208,6 +208,8 @@
 FILES+=                msg_001_c90.exp
 FILES+=                msg_000_c90.c
 FILES+=                msg_000_c90.exp
+FILES+=                msg_132_ilp32.c
+FILES+=                msg_132_ilp32.exp
 FILES+=                msg_230_uchar.c
 FILES+=                msg_230_uchar.exp
 FILES+=                msg_259_ilp32.c
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/decl_struct_member.c
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.c    Wed Aug 25 22:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.c    Wed Aug 25 22:04:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl_struct_member.c,v 1.10 2021/07/21 21:17:57 rillig Exp $   */
+/*     $NetBSD: decl_struct_member.c,v 1.11 2021/08/25 22:04:52 rillig Exp $   */
 # 3 "decl_struct_member.c"
 
 struct multi_attributes {
@@ -57,6 +57,22 @@
 };
 
 /*
+ * An array of bit-fields sounds like a strange idea since a bit-field member
+ * is not addressable, while an array needs to be addressable.  Due to this
+ * contradiction, this combination may have gone without mention in the C
+ * standards.
+ *
+ * GCC 10.3.0 complains that the bit-field has invalid type.
+ *
+ * Clang 12.0.1 complains that the bit-field has non-integral type 'unsigned
+ * int [8]'.
+ */
+struct array_of_bit_fields {
+       /* expect+1: warning: illegal bit-field type 'array[8] of unsigned int' [35] */
+       unsigned int bits[8]: 1;
+};
+
+/*
  * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault.
  */
 struct {
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/decl_struct_member.exp
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.exp  Wed Aug 25 22:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.exp  Wed Aug 25 22:04:51 2021 +0000
@@ -3,5 +3,6 @@
 decl_struct_member.c(38): error: syntax error '}' [249]
 decl_struct_member.c(38): warning: empty declaration [0]
 decl_struct_member.c(47): error: syntax error 'unnamed member' [249]
-decl_struct_member.c(63): error: syntax error '0' [249]
-decl_struct_member.c(71): error: cannot recover from previous errors [224]
+decl_struct_member.c(72): warning: illegal bit-field type 'array[8] of unsigned int' [35]
+decl_struct_member.c(79): error: syntax error '0' [249]
+decl_struct_member.c(87): error: cannot recover from previous errors [224]
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Wed Aug 25 22:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Wed Aug 25 22:04:51 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.5 2021/04/06 21:17:28 rillig Exp $       */
+/*     $NetBSD: msg_132.c,v 1.6 2021/08/25 22:04:52 rillig Exp $       */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -74,3 +74,14 @@
        /* seen in fp_lib.h, function wideRightShiftWithSticky */
        return a | b;
 }
+
+/* ARGSUSED */
+const char *
+cover_build_plus_minus(const char *arr, double idx)
+{
+       /* expect+3: error: operands of '+' have incompatible types (pointer != double) [107] */
+       /* expect+2: warning: function 'cover_build_plus_minus' expects to return value [214] */
+       if (idx > 0.0)
+               return arr + idx;
+       return arr + (unsigned int)idx;
+}
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/msg_132.exp
--- a/tests/usr.bin/xlint/lint1/msg_132.exp     Wed Aug 25 22:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.exp     Wed Aug 25 22:04:51 2021 +0000
@@ -10,3 +10,5 @@
 msg_132.c(54): warning: conversion from 'int' to 'short' may lose accuracy [132]
 msg_132.c(55): warning: conversion from 'long long' to 'short' may lose accuracy [132]
 msg_132.c(59): warning: conversion from 'long long' to 'int' may lose accuracy [132]
+msg_132.c(85): error: operands of '+' have incompatible types (pointer != double) [107]
+msg_132.c(85): warning: function 'cover_build_plus_minus' expects to return value [214]
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/msg_132_ilp32.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132_ilp32.c Wed Aug 25 22:04:51 2021 +0000
@@ -0,0 +1,32 @@
+/*     $NetBSD: msg_132_ilp32.c,v 1.1 2021/08/25 22:04:52 rillig Exp $ */
+# 3 "msg_132_ilp32.c"
+
+// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
+
+/*
+ * On 32-bit platforms, it is possible to add a 64-bit integer to a 32-bit
+ * pointer.  The 64-bit integer is then converted to the ptrdiff_t of the
+ * target platform, which results in the non-obvious conversion from
+ * 'long long' to either 'long' or 'int', depending on the platform's
+ * ptrdiff_t.
+ */
+
+/* lint1-extra-flags: -a */
+/* lint1-only-if: ilp32 int */
+
+/*
+ * Seen in usr.bin/make/var.c, function RegexReplace, in the function call
+ * SepBuf_AddBytesBetween(buf, wp + m[0].rm_so, wp + m[0].rm_eo).  The
+ * offsets of regular expression matches have type off_t, which is a 64-bit
+ * integer.
+ *
+ * C11 6.5.6p8 does not explicitly define the meaning of a pointer + an
+ * overly long integer, it just says "undefined behavior" if the resulting
+ * pointer would be outside the object.
+ */
+const char *
+array_subscript(const char *p, long long idx)
+{
+       /* expect+1: warning: conversion from 'long long' to 'int' may lose accuracy [132] */
+       return p + idx;
+}
diff -r 879f02cef5f1 -r 646352a69803 tests/usr.bin/xlint/lint1/msg_132_ilp32.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132_ilp32.exp       Wed Aug 25 22:04:51 2021 +0000
@@ -0,0 +1,1 @@
+msg_132_ilp32.c(31): warning: conversion from 'long long' to 'int' may lose accuracy [132]



Home | Main Index | Thread Index | Old Index