Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: test bit shift with la...



details:   https://anonhg.NetBSD.org/src/rev/a02313cdc709
branches:  trunk
changeset: 368276:a02313cdc709
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 02 09:48:18 2022 +0000

description:
tests/lint: test bit shift with large integer types

build_bit_shift converts the right-hand operand to INT or UINT, even
though C11 6.5.7 doesn't say anything about narrowing conversions.

Traditional C says that the operators '<<' and '>>' perform the usual
arithmetic conversions.  This has been dropped in C90.

What lint actually does is something completely different.  In the
operators table in ops.def, the operators '<<' and '>>' are not marked
as performing the usual arithmetic conversions (column 'balance').  This
leaves all conversions to 'build_bit_shift', which converts the
right-hand side to INT or UINT.  There is no obvious reason for this
conversion, as the bounds checks need to be performed no matter whether
the type is INT or UINT128.

diffstat:

 tests/usr.bin/xlint/lint1/msg_132.c |  56 +++++++++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 14 deletions(-)

diffs (82 lines):

diff -r e210ed15d5c6 -r a02313cdc709 tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c       Sat Jul 02 08:43:28 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c       Sat Jul 02 09:48:18 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_132.c,v 1.19 2022/06/19 12:14:34 rillig Exp $      */
+/*     $NetBSD: msg_132.c,v 1.20 2022/07/02 09:48:18 rillig Exp $      */
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -13,15 +13,24 @@
 
 /* lint1-extra-flags: -aa */
 
-unsigned char u8;
-unsigned short u16;
-unsigned int u32;
-unsigned long long u64;
+typedef unsigned char u8_t;
+typedef unsigned short u16_t;
+typedef unsigned int u32_t;
+typedef unsigned long long u64_t;
+typedef signed char s8_t;
+typedef signed short s16_t;
+typedef signed int s32_t;
+typedef signed long long s64_t;
 
-signed char s8;
-signed short s16;
-signed int s32;
-signed long long s64;
+u8_t u8;
+u16_t u16;
+u32_t u32;
+u64_t u64;
+
+s8_t s8;
+s16_t s16;
+s32_t s32;
+s64_t s64;
 
 void
 unsigned_to_unsigned(void)
@@ -165,11 +174,6 @@
        return not_a_constant * 8ULL;
 }
 
-typedef unsigned char u8_t;
-typedef unsigned short u16_t;
-typedef unsigned int u32_t;
-typedef unsigned long long u64_t;
-
 /*
  * PR 36668 notices that lint wrongly complains about the possible loss.
  *
@@ -238,3 +242,27 @@
        /* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */
        return s.bits_32 & m;
 }
+
+u64_t
+u64_shl(u64_t lhs, u64_t rhs)
+{
+       return lhs << rhs;
+}
+
+u64_t
+u64_shr(u64_t lhs, u64_t rhs)
+{
+       return lhs >> rhs;
+}
+
+s64_t
+s64_shl(s64_t lhs, s64_t rhs)
+{
+       return lhs << rhs;
+}
+
+s64_t
+s64_shr(s64_t lhs, s64_t rhs)
+{
+       return lhs >> rhs;
+}



Home | Main Index | Thread Index | Old Index