Module Name:    src
Committed By:   rillig
Date:           Thu Apr 21 19:48:18 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_132.c msg_132.exp

Log Message:
tests/lint: extend test for lossy integer conversion


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_132.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.8 src/tests/usr.bin/xlint/lint1/msg_132.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.8	Wed Apr 20 22:50:56 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Thu Apr 21 19:48:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.8 2022/04/20 22:50:56 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.9 2022/04/21 19:48:18 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -6,67 +6,107 @@
 /*
  * NetBSD's default lint flags only include a single -a, which only flags
  * narrowing conversions from long.  To get warnings for all narrowing
- * conversions, -aa needs to be given more than once.
+ * conversions, -a needs to be given more than once.
  *
  * https://gnats.netbsd.org/14531
  */
 
 /* lint1-extra-flags: -aa */
 
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long long u64;
-
-typedef signed char i8;
-typedef signed short i16;
-typedef signed int i32;
-typedef signed long long i64;
+unsigned char u8;
+unsigned short u16;
+unsigned int u32;
+unsigned long long u64;
+
+signed char s8;
+signed short s16;
+signed int s32;
+signed long long s64;
 
 void
-convert_unsigned(u8 v8, u16 v16, u32 v32, u64 v64)
+unsigned_to_unsigned(void)
 {
-	v8 = v16;		/* expect: 132 */
-	v8 = v32;		/* expect: 132 */
-	v8 = v64;		/* expect: 132 */
-
-	v16 = v8;
-	v16 = v32;		/* expect: 132 */
-	v16 = v64;		/* expect: 132 */
-
-	v32 = v8;
-	v32 = v16;
-	v32 = v64;		/* expect: 132 */
-
-	v64 = v8;
-	v64 = v16;
-	v64 = v32;
+	u8 = u16;		/* expect: 132 */
+	u8 = u32;		/* expect: 132 */
+	u8 = u64;		/* expect: 132 */
+
+	u16 = u8;
+	u16 = u32;		/* expect: 132 */
+	u16 = u64;		/* expect: 132 */
+
+	u32 = u8;
+	u32 = u16;
+	u32 = u64;		/* expect: 132 */
+
+	u64 = u8;
+	u64 = u16;
+	u64 = u32;
 }
 
 void
-convert_signed(i8 v8, i16 v16, i32 v32, i64 v64)
+unsigned_to_signed(void)
 {
-	v8 = v16;		/* expect: 132 */
-	v8 = v32;		/* expect: 132 */
-	v8 = v64;		/* expect: 132 */
-
-	v16 = v8;
-	v16 = v32;		/* expect: 132 */
-	v16 = v64;		/* expect: 132 */
-
-	v32 = v8;
-	v32 = v16;
-	v32 = v64;		/* expect: 132 */
-
-	v64 = v8;
-	v64 = v16;
-	v64 = v32;
+	s8 = u16;		/* expect: 132 */
+	s8 = u32;		/* expect: 132 */
+	s8 = u64;		/* expect: 132 */
+
+	s16 = u8;
+	s16 = u32;		/* expect: 132 */
+	s16 = u64;		/* expect: 132 */
+
+	s32 = u8;
+	s32 = u16;
+	s32 = u64;		/* expect: 132 */
+
+	s64 = u8;
+	s64 = u16;
+	s64 = u32;
+}
+
+void
+signed_to_unsigned(void)
+{
+	u8 = s16;		/* expect: 132 */
+	u8 = s32;		/* expect: 132 */
+	u8 = s64;		/* expect: 132 */
+
+	u16 = s8;
+	u16 = s32;		/* expect: 132 */
+	u16 = s64;		/* expect: 132 */
+
+	u32 = s8;
+	u32 = s16;
+	u32 = s64;		/* expect: 132 */
+
+	u64 = s8;
+	u64 = s16;
+	u64 = s32;
+}
+
+void
+signed_to_signed(void)
+{
+	s8 = s16;		/* expect: 132 */
+	s8 = s32;		/* expect: 132 */
+	s8 = s64;		/* expect: 132 */
+
+	s16 = s8;
+	s16 = s32;		/* expect: 132 */
+	s16 = s64;		/* expect: 132 */
+
+	s32 = s8;
+	s32 = s16;
+	s32 = s64;		/* expect: 132 */
+
+	s64 = s8;
+	s64 = s16;
+	s64 = s32;
 }
 
 /*
- * Before tree.c 1.268 from 2021-04-06, lint wrongly warned that conversion to
- * _Bool might lose accuracy.  C99 6.3.1.2 defines a special conversion rule
- * from scalar to _Bool though.
+ * Before tree.c 1.268 from 2021-04-06, lint wrongly warned that conversion
+ * to _Bool might lose accuracy.  C99 6.3.1.2 defines a special conversion
+ * rule from scalar to _Bool though by comparing the value to 0.
  */
 _Bool
 to_bool(long a, long b)

Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.7 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.8
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.7	Wed Apr 20 22:50:56 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp	Thu Apr 21 19:48:18 2022
@@ -4,12 +4,24 @@ msg_132.c(31): warning: conversion from 
 msg_132.c(34): warning: conversion from 'unsigned int' to 'unsigned short' may lose accuracy [132]
 msg_132.c(35): warning: conversion from 'unsigned long long' to 'unsigned short' may lose accuracy [132]
 msg_132.c(39): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
-msg_132.c(49): warning: conversion from 'short' to 'signed char' may lose accuracy [132]
-msg_132.c(50): warning: conversion from 'int' to 'signed char' may lose accuracy [132]
-msg_132.c(51): warning: conversion from 'long long' to 'signed char' may lose accuracy [132]
-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]
-msg_132.c(101): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
+msg_132.c(49): warning: conversion from 'unsigned short' to 'signed char' may lose accuracy [132]
+msg_132.c(50): warning: conversion from 'unsigned int' to 'signed char' may lose accuracy [132]
+msg_132.c(51): warning: conversion from 'unsigned long long' to 'signed char' may lose accuracy [132]
+msg_132.c(54): warning: conversion from 'unsigned int' to 'short' may lose accuracy [132]
+msg_132.c(55): warning: conversion from 'unsigned long long' to 'short' may lose accuracy [132]
+msg_132.c(59): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
+msg_132.c(69): warning: conversion from 'short' to 'unsigned char' may lose accuracy [132]
+msg_132.c(70): warning: conversion from 'int' to 'unsigned char' may lose accuracy [132]
+msg_132.c(71): warning: conversion from 'long long' to 'unsigned char' may lose accuracy [132]
+msg_132.c(74): warning: conversion from 'int' to 'unsigned short' may lose accuracy [132]
+msg_132.c(75): warning: conversion from 'long long' to 'unsigned short' may lose accuracy [132]
+msg_132.c(79): warning: conversion from 'long long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(89): warning: conversion from 'short' to 'signed char' may lose accuracy [132]
+msg_132.c(90): warning: conversion from 'int' to 'signed char' may lose accuracy [132]
+msg_132.c(91): warning: conversion from 'long long' to 'signed char' may lose accuracy [132]
+msg_132.c(94): warning: conversion from 'int' to 'short' may lose accuracy [132]
+msg_132.c(95): warning: conversion from 'long long' to 'short' may lose accuracy [132]
+msg_132.c(99): warning: conversion from 'long long' to 'int' may lose accuracy [132]
+msg_132.c(125): error: operands of '+' have incompatible types (pointer != double) [107]
+msg_132.c(125): warning: function 'cover_build_plus_minus' expects to return value [214]
+msg_132.c(141): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]

Reply via email to