Module Name: src
Committed By: rillig
Date: Fri Jun 10 18:29:01 UTC 2022
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile msg_132.c msg_132.exp
msg_132_ilp32.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_132_lp64.c msg_132_lp64.exp
Log Message:
tests/lint: fix test for loss of accuracy on ILP32 platforms
The test had been wrong since msg_132.c 1.14 from 2022-05-30.
Using 'unsigned long' in a test that was intended to behave the same on
ILP32 and LP64 was an accident. Use 'unsigned long long' instead, which
is 64-bits wide on all platforms supported by lint.
Move the test about conversion from 'long' to 'int' to the
platform-specific test files.
Noticed by martin@ on powerpc.
To generate a diff of this commit:
cvs rdiff -u -r1.1211 -r1.1212 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.123 -r1.124 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_132.exp
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_132_lp64.c \
src/tests/usr.bin/xlint/lint1/msg_132_lp64.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1211 src/distrib/sets/lists/tests/mi:1.1212
--- src/distrib/sets/lists/tests/mi:1.1211 Mon Jun 6 10:57:05 2022
+++ src/distrib/sets/lists/tests/mi Fri Jun 10 18:29:01 2022
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1211 2022/06/06 10:57:05 nia Exp $
+# $NetBSD: mi,v 1.1212 2022/06/10 18:29:01 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6841,6 +6841,8 @@
./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_132_lp64.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_132_lp64.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
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.123 src/tests/usr.bin/xlint/lint1/Makefile:1.124
--- src/tests/usr.bin/xlint/lint1/Makefile:1.123 Thu May 12 20:49:21 2022
+++ src/tests/usr.bin/xlint/lint1/Makefile Fri Jun 10 18:29:01 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.123 2022/05/12 20:49:21 rillig Exp $
+# $NetBSD: Makefile,v 1.124 2022/06/10 18:29:01 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 349 # see lint1/err.c
@@ -223,6 +223,8 @@ FILES+= msg_001_c90.c
FILES+= msg_001_c90.exp
FILES+= msg_132_ilp32.c
FILES+= msg_132_ilp32.exp
+FILES+= msg_132_lp64.c
+FILES+= msg_132_lp64.exp
FILES+= msg_230_uchar.c
FILES+= msg_230_uchar.exp
FILES+= msg_259_c90.c
Index: src/tests/usr.bin/xlint/lint1/msg_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.16 src/tests/usr.bin/xlint/lint1/msg_132.c:1.17
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.16 Mon May 30 07:19:28 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.c Fri Jun 10 18:29:01 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_132.c,v 1.16 2022/05/30 07:19:28 rillig Exp $ */
+/* $NetBSD: msg_132.c,v 1.17 2022/06/10 18:29:01 rillig Exp $ */
# 3 "msg_132.c"
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -203,22 +203,14 @@ struct bit_fields {
};
unsigned char
-test_bit_fields(struct bit_fields s, unsigned long m)
+test_bit_fields(struct bit_fields s, unsigned long long m)
{
- /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
+ /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132] */
s.bits_3 = s.bits_32 & m;
s.bits_5 = s.bits_3 & m;
s.bits_32 = s.bits_5 & m;
- /* expect+1: warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132] */
+ /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */
return s.bits_32 & m;
}
-
-
-unsigned int
-convert_pointer_to_smaller_integer(void *ptr)
-{
- /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
- return (unsigned long)(ptr) >> 12;
-}
Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.15 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.16
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.15 Mon May 30 07:19:28 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp Fri Jun 10 18:29:01 2022
@@ -27,6 +27,5 @@ msg_132.c(125): warning: function 'cover
msg_132.c(141): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
msg_132.c(193): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
msg_132.c(195): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(209): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(215): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]
-msg_132.c(223): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(209): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(215): warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132]
Index: src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.1 src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.1 Wed Aug 25 22:04:52 2021
+++ src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c Fri Jun 10 18:29:01 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_132_ilp32.c,v 1.1 2021/08/25 22:04:52 rillig Exp $ */
+/* $NetBSD: msg_132_ilp32.c,v 1.2 2022/06/10 18:29:01 rillig Exp $ */
# 3 "msg_132_ilp32.c"
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -30,3 +30,13 @@ array_subscript(const char *p, long long
/* expect+1: warning: conversion from 'long long' to 'int' may lose accuracy [132] */
return p + idx;
}
+
+/*
+ * On ILP32 platforms, pointer, long and int have the same size, so there is
+ * no loss of accuracy.
+ */
+unsigned int
+convert_pointer_to_smaller_integer(void *ptr)
+{
+ return (unsigned long)(ptr) >> 12;
+}
Added files:
Index: src/tests/usr.bin/xlint/lint1/msg_132_lp64.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_132_lp64.c:1.1
--- /dev/null Fri Jun 10 18:29:01 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132_lp64.c Fri Jun 10 18:29:01 2022
@@ -0,0 +1,14 @@
+/* $NetBSD: msg_132_lp64.c,v 1.1 2022/06/10 18:29:01 rillig Exp $ */
+# 3 "msg_132_lp64.c"
+
+// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
+
+/* lint1-extra-flags: -a */
+/* lint1-only-if: lp64 */
+
+unsigned int
+convert_pointer_to_smaller_integer(void *ptr)
+{
+ /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
+ return (unsigned long)(ptr) >> 12;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_132_lp64.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_132_lp64.exp:1.1
--- /dev/null Fri Jun 10 18:29:01 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132_lp64.exp Fri Jun 10 18:29:01 2022
@@ -0,0 +1 @@
+msg_132_lp64.c(13): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]