Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: preserve integer constraints on cast



details:   https://anonhg.NetBSD.org/src/rev/889ab8844521
branches:  trunk
changeset: 374659:889ab8844521
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue May 09 15:45:06 2023 +0000

description:
lint: preserve integer constraints on cast

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c |   4 +---
 usr.bin/xlint/lint1/tree.c          |  15 ++++++++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)

diffs (54 lines):

diff -r 9ebc0a0f4a4c -r 889ab8844521 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Tue May 09 15:43:39 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Tue May 09 15:45:06 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.28 2023/05/09 15:37:29 rillig Exp $      */
+/*     $NetBSD: msg_132.c,v 1.29 2023/05/09 15:45:06 rillig Exp $      */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -372,8 +372,6 @@ void
 test_ic_cvt(void)
 {
        u16 = (u32 & 0x0000ff00);
-       /* FIXME: Don't throw away the constraint. */
-       /* expect+1: warning: conversion from 'unsigned int' to 'unsigned short' may lose accuracy [132] */
        u16 = (u32_t)(u32 & 0x0000ff00);
 }
 
diff -r 9ebc0a0f4a4c -r 889ab8844521 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue May 09 15:43:39 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue May 09 15:45:06 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.519 2023/04/22 20:54:28 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.520 2023/05/09 15:45:06 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.519 2023/04/22 20:54:28 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.520 2023/05/09 15:45:06 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -147,9 +147,14 @@ ic_con(const type_t *tp, const val_t *v)
 static integer_constraints
 ic_cvt(const type_t *ntp, const type_t *otp, integer_constraints a)
 {
-
-       if (width_in_bits(ntp) > width_in_bits(otp) &&
-           is_uinteger(otp->t_tspec))
+       unsigned nw = width_in_bits(ntp);
+       unsigned ow = width_in_bits(otp);
+       bool nu = is_uinteger(ntp->t_tspec);
+       bool ou = is_uinteger(otp->t_tspec);
+
+       if (nw >= ow && nu == ou)
+               return a;
+       if (nw > ow && ou)
                return a;
        return ic_any(ntp);
 }



Home | Main Index | Thread Index | Old Index