Module Name: src
Committed By: rillig
Date: Tue May 9 15:45:06 UTC 2023
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: preserve integer constraints on cast
To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.519 -r1.520 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.28 src/tests/usr.bin/xlint/lint1/msg_132.c:1.29
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.28 Tue May 9 15:37:29 2023
+++ src/tests/usr.bin/xlint/lint1/msg_132.c Tue May 9 15:45:06 2023
@@ -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);
}
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.519 src/usr.bin/xlint/lint1/tree.c:1.520
--- src/usr.bin/xlint/lint1/tree.c:1.519 Sat Apr 22 20:54:28 2023
+++ src/usr.bin/xlint/lint1/tree.c Tue May 9 15:45:06 2023
@@ -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)
{
+ 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 (width_in_bits(ntp) > width_in_bits(otp) &&
- is_uinteger(otp->t_tspec))
+ if (nw >= ow && nu == ou)
+ return a;
+ if (nw > ow && ou)
return a;
return ic_any(ntp);
}