Source-Changes-HG archive

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

[src/trunk]: src tests/lint: fix test for loss of accuracy on ILP32 platforms



details:   https://anonhg.NetBSD.org/src/rev/52b8712f74ba
branches:  trunk
changeset: 366713:52b8712f74ba
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 10 18:29:01 2022 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi                |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile         |   4 +++-
 tests/usr.bin/xlint/lint1/msg_132.c        |  16 ++++------------
 tests/usr.bin/xlint/lint1/msg_132.exp      |   5 ++---
 tests/usr.bin/xlint/lint1/msg_132_ilp32.c  |  12 +++++++++++-
 tests/usr.bin/xlint/lint1/msg_132_lp64.c   |  14 ++++++++++++++
 tests/usr.bin/xlint/lint1/msg_132_lp64.exp |   1 +
 7 files changed, 38 insertions(+), 18 deletions(-)

diffs (129 lines):

diff -r b39aad2f5b0d -r 52b8712f74ba distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jun 10 17:47:20 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jun 10 18:29:01 2022 +0000
@@ -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
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Fri Jun 10 17:47:20 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Fri Jun 10 18:29:01 2022 +0000
@@ -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.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
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Fri Jun 10 17:47:20 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Fri Jun 10 18:29:01 2022 +0000
@@ -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 @@
 };
 
 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;
-}
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/msg_132.exp
--- a/tests/usr.bin/xlint/lint1/msg_132.exp     Fri Jun 10 17:47:20 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.exp     Fri Jun 10 18:29:01 2022 +0000
@@ -27,6 +27,5 @@
 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]
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/msg_132_ilp32.c
--- a/tests/usr.bin/xlint/lint1/msg_132_ilp32.c Fri Jun 10 17:47:20 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132_ilp32.c Fri Jun 10 18:29:01 2022 +0000
@@ -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 @@
        /* 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;
+}
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/msg_132_lp64.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132_lp64.c  Fri Jun 10 18:29:01 2022 +0000
@@ -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;
+}
diff -r b39aad2f5b0d -r 52b8712f74ba tests/usr.bin/xlint/lint1/msg_132_lp64.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132_lp64.exp        Fri Jun 10 18:29:01 2022 +0000
@@ -0,0 +1,1 @@
+msg_132_lp64.c(13): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]



Home | Main Index | Thread Index | Old Index