Module Name: src
Committed By: rillig
Date: Sun Aug 18 15:21:09 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: add value propagation for '/' combined with bit operations
Fixes __SHIFTIN/__SHIFTOUT expressions, as in PR toolchain/58617.
To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.649 -r1.650 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.41 src/tests/usr.bin/xlint/lint1/msg_132.c:1.42
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.41 Sun Aug 18 15:11:43 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c Sun Aug 18 15:21:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_132.c,v 1.41 2024/08/18 15:11:43 rillig Exp $ */
+/* $NetBSD: msg_132.c,v 1.42 2024/08/18 15:21:09 rillig Exp $ */
# 3 "msg_132.c"
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -458,6 +458,5 @@ binary_operators_on_bit_fields(void)
unsigned char
combine_arithmetic_and_bit_operations(unsigned int c32)
{
- /* expect+1: warning: conversion from 'unsigned int' to 'unsigned char' may lose accuracy [132] */
return 0xc0 | (c32 & 0x07c0) / 64;
}
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.649 src/usr.bin/xlint/lint1/tree.c:1.650
--- src/usr.bin/xlint/lint1/tree.c:1.649 Wed Jul 10 20:33:37 2024
+++ src/usr.bin/xlint/lint1/tree.c Sun Aug 18 15:21:09 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.649 2024/07/10 20:33:37 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.650 2024/08/18 15:21:09 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.649 2024/07/10 20:33:37 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.650 2024/08/18 15:21:09 rillig Exp $");
#endif
#include <float.h>
@@ -172,7 +172,7 @@ ic_bitand(integer_constraints a, integer
c.smin = INT64_MIN;
c.smax = INT64_MAX;
c.umin = 0;
- c.umax = UINT64_MAX;
+ c.umax = ~(a.bclr | b.bclr);
c.bset = a.bset & b.bset;
c.bclr = a.bclr | b.bclr;
return c;
@@ -186,7 +186,7 @@ ic_bitor(integer_constraints a, integer_
c.smin = INT64_MIN;
c.smax = INT64_MAX;
c.umin = 0;
- c.umax = UINT64_MAX;
+ c.umax = ~(a.bclr & b.bclr);
c.bset = a.bset | b.bset;
c.bclr = a.bclr & b.bclr;
return c;
@@ -210,6 +210,23 @@ ic_mod(const type_t *tp, integer_constra
}
static integer_constraints
+ic_div(const type_t *tp, integer_constraints a, integer_constraints b)
+{
+ integer_constraints c;
+
+ if (ic_maybe_signed(tp, &a) || ic_maybe_signed(tp, &b) || b.umin == 0)
+ return ic_any(tp);
+
+ c.smin = INT64_MIN;
+ c.smax = INT64_MAX;
+ c.umin = a.umin / b.umax;
+ c.umax = a.umax / b.umin;
+ c.bset = 0;
+ c.bclr = ~u64_fill_right(c.umax);
+ return c;
+}
+
+static integer_constraints
ic_shl(const type_t *tp, integer_constraints a, integer_constraints b)
{
integer_constraints c;
@@ -288,6 +305,10 @@ ic_expr(const tnode_t *tn)
return ic_any(tn->tn_type);
lc = ic_expr(tn->u.ops.left);
return ic_cvt(tn->tn_type, tn->u.ops.left->tn_type, lc);
+ case DIV:
+ lc = ic_expr(before_conversion(tn->u.ops.left));
+ rc = ic_expr(before_conversion(tn->u.ops.right));
+ return ic_div(tn->tn_type, lc, rc);
case MOD:
lc = ic_expr(before_conversion(tn->u.ops.left));
rc = ic_expr(before_conversion(tn->u.ops.right));