From 4329029317e4cba70f0582b5f8a1a69a6f6afae8 Mon Sep 17 00:00:00 2001 From: rillig Date: Tue, 6 Apr 2021 21:17:27 +0000 Subject: [PATCH] lint: fix wrong warning about losing accuracy when converting to _Bool --- tests/usr.bin/xlint/lint1/msg_132.c | 9 +++++++-- tests/usr.bin/xlint/lint1/msg_132.exp | 1 - usr.bin/xlint/lint1/tree.c | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/usr.bin/xlint/lint1/msg_132.c b/tests/usr.bin/xlint/lint1/msg_132.c index 39b172ef518d..40db193e9d52 100644 --- a/tests/usr.bin/xlint/lint1/msg_132.c +++ b/tests/usr.bin/xlint/lint1/msg_132.c @@ -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, i64 v64) 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; } diff --git a/tests/usr.bin/xlint/lint1/msg_132.exp b/tests/usr.bin/xlint/lint1/msg_132.exp index 3c208a518cdd..c96ff05221e6 100644 --- a/tests/usr.bin/xlint/lint1/msg_132.exp +++ b/tests/usr.bin/xlint/lint1/msg_132.exp @@ -10,4 +10,3 @@ msg_132.c(51): warning: conversion from 'long long' to 'signed char' may lose ac 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] diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 3ca1557de5cc..e10e36922f2b 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -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 #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 @@ -1948,6 +1948,9 @@ check_integer_conversion(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, 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) {