Module Name:    src
Committed By:   rillig
Date:           Sat Mar 30 17:23:13 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: queries.c t_usage.sh
        src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: add query for implicit integer-to-floating conversion


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/xlint/lint1/queries.c
cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.238 -r1.239 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.631 -r1.632 src/usr.bin/xlint/lint1/tree.c

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/queries.c
diff -u src/tests/usr.bin/xlint/lint1/queries.c:1.25 src/tests/usr.bin/xlint/lint1/queries.c:1.26
--- src/tests/usr.bin/xlint/lint1/queries.c:1.25	Sat Mar 30 17:12:26 2024
+++ src/tests/usr.bin/xlint/lint1/queries.c	Sat Mar 30 17:23:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: queries.c,v 1.25 2024/03/30 17:12:26 rillig Exp $	*/
+/*	$NetBSD: queries.c,v 1.26 2024/03/30 17:23:13 rillig Exp $	*/
 # 3 "queries.c"
 
 /*
@@ -15,7 +15,9 @@
  *	such as casts between arithmetic types.
  */
 
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10 */
+/* lint1-extra-flags: -q 11,12,13,14,15,16,17,18,19 */
+/* lint1-extra-flags: -X 351 */
 
 typedef unsigned char u8_t;
 typedef unsigned short u16_t;
@@ -354,9 +356,9 @@ Q9(int x)
 		return (0.0);
 	case 9:
 		return
-# 358 "queries.c" 3 4
+# 360 "queries.c" 3 4
 		((void *)0)
-# 360 "queries.c"
+# 362 "queries.c"
 		/* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
 		;
 	case 10:
@@ -473,6 +475,31 @@ int Q17_wide_string[] = L" \0	";
 
 /* For Q18, see queries_schar.c and queries_uchar.c. */
 
+void
+convert_from_integer_to_floating(void)
+{
+	/* expect+1: implicit conversion from integer 'unsigned int' to floating point 'float' [Q19] */
+	f32 = 0xffff0000;
+	/* expect+1: implicit conversion from integer 'unsigned int' to floating point 'float' [Q19] */
+	f32 = 0xffffffff;
+	/* expect+1: implicit conversion from integer 'int' to floating point 'float' [Q19] */
+	f32 = s32;
+	/* expect+1: implicit conversion from integer 'unsigned int' to floating point 'float' [Q19] */
+	f32 = u32;
+	/* expect+1: implicit conversion from integer 'int' to floating point 'double' [Q19] */
+	f64 = s32;
+	/* expect+1: implicit conversion from integer 'unsigned int' to floating point 'double' [Q19] */
+	f64 = u32;
+	/* expect+1: implicit conversion from integer 'long long' to floating point 'double' [Q19] */
+	f64 = s64;
+	/* expect+1: implicit conversion from integer 'unsigned long long' to floating point 'double' [Q19] */
+	f64 = u64;
+
+	f32 = 0.0F;
+	f32 = 0.0;
+	f64 = 0.0;
+}
+
 /*
  * Since queries do not affect the exit status, force a warning to make this
  * test conform to the general expectation that a test that produces output

Index: src/tests/usr.bin/xlint/lint1/t_usage.sh
diff -u src/tests/usr.bin/xlint/lint1/t_usage.sh:1.18 src/tests/usr.bin/xlint/lint1/t_usage.sh:1.19
--- src/tests/usr.bin/xlint/lint1/t_usage.sh:1.18	Sun Mar  3 00:50:41 2024
+++ src/tests/usr.bin/xlint/lint1/t_usage.sh	Sat Mar 30 17:23:13 2024
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.18 2024/03/03 00:50:41 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.19 2024/03/30 17:23:13 rillig Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -89,13 +89,13 @@ enable_queries_body()
 
 	# The largest known query.
 	atf_check \
-	    "$lint1" -q 18 code.c /dev/null
+	    "$lint1" -q 19 code.c /dev/null
 
 	# Larger than the largest known query.
 	atf_check \
 	    -s 'exit:1' \
-	    -e "inline:lint1: invalid query ID '19'\n" \
-	    "$lint1" -q 19 code.c /dev/null
+	    -e "inline:lint1: invalid query ID '20'\n" \
+	    "$lint1" -q 20 code.c /dev/null
 
 	# Whitespace is not allowed before a query ID.
 	atf_check \

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.238 src/usr.bin/xlint/lint1/err.c:1.239
--- src/usr.bin/xlint/lint1/err.c:1.238	Sat Mar 30 17:12:26 2024
+++ src/usr.bin/xlint/lint1/err.c	Sat Mar 30 17:23:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.238 2024/03/30 17:12:26 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.239 2024/03/30 17:23:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.238 2024/03/30 17:12:26 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.239 2024/03/30 17:23:13 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -740,6 +740,7 @@ static const char *queries[] = {
 	"'%s' was declared 'static', now non-'static'",			// Q16
 	"invisible character U+%04X in %s",				// Q17
 	"const automatic variable '%s'",				// Q18
+	"implicit conversion from integer '%s' to floating point '%s'",	// Q19
 };
 
 bool any_query_enabled;		/* for optimizing non-query scenarios */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.631 src/usr.bin/xlint/lint1/tree.c:1.632
--- src/usr.bin/xlint/lint1/tree.c:1.631	Sat Mar 30 17:12:26 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar 30 17:23:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.631 2024/03/30 17:12:26 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.632 2024/03/30 17:23:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.631 2024/03/30 17:12:26 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.632 2024/03/30 17:23:13 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3642,7 +3642,11 @@ convert(op_t op, int arg, type_t *tp, tn
 			convert_integer_from_pointer(op, nt, tp, tn);
 
 	} else if (is_floating(nt)) {
-		/* No further checks. */
+		if (is_integer(ot)) {
+			/* implicit conversion from integer '%s' to ... */
+			query_message(19,
+			    type_name(tn->tn_type), type_name(tp));
+		}
 
 	} else if (nt == PTR) {
 		if (is_null_pointer(tn)) {

Reply via email to