Module Name:    src
Committed By:   rillig
Date:           Tue Apr  6 21:17:28 UTC 2021

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

Log Message:
lint: fix wrong warning about losing accuracy when converting to _Bool


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_132.exp
cvs rdiff -u -r1.267 -r1.268 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/msg_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.4 src/tests/usr.bin/xlint/lint1/msg_132.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.4	Tue Apr  6 21:10:37 2021
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Tue Apr  6 21:17:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.4 2021/04/06 21:10:37 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.5 2021/04/06 21:17:28 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -63,9 +63,14 @@ convert_signed(i8 v8, i16 v16, i32 v32, 
 	v64 = v32;
 }
 
+/*
+ * 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.
+ */
 _Bool
 to_bool(long a, long b)
 {
 	/* seen in fp_lib.h, function wideRightShiftWithSticky */
-	return a | b;		/* expect: 132 *//*FIXME*/
+	return a | b;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.3	Tue Apr  6 21:10:37 2021
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp	Tue Apr  6 21:17:28 2021
@@ -10,4 +10,3 @@ msg_132.c(51): warning: conversion from 
 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(70): warning: conversion from 'long' to '_Bool' may lose accuracy [132]

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.267 src/usr.bin/xlint/lint1/tree.c:1.268
--- src/usr.bin/xlint/lint1/tree.c:1.267	Tue Apr  6 13:17:04 2021
+++ src/usr.bin/xlint/lint1/tree.c	Tue Apr  6 21:17:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.267 2021/04/06 13:17:04 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.268 2021/04/06 21:17:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.267 2021/04/06 13:17:04 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.268 2021/04/06 21:17:27 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1948,6 +1948,9 @@ check_integer_conversion(op_t op, int ar
 	if (op == CVT)
 		return;
 
+	if (Sflag && nt == BOOL)
+		return;		/* See C99 6.3.1.2 */
+
 	if (Pflag && portable_size_in_bits(nt) > portable_size_in_bits(ot) &&
 	    is_uinteger(nt) != is_uinteger(ot)) {
 		if (aflag > 0 && pflag) {

Reply via email to