NetBSD-Bugs archive

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

toolchain/58617: lint spuriously warns about impossible __SHIFTOUT/__BITS truncation



>Number:         58617
>Category:       toolchain
>Synopsis:       lint spuriously warns about impossible __SHIFTOUT/__BITS truncation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 18 13:35:00 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The NetBSD Foundlonglint
>Environment:
>Description:
			*pc8 = 0xc0 | __SHIFTOUT(c32, __BITS(10,6));

/home/riastradh/netbsd/current/src/lib/libc/locale/mbrtoc8.c(199): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]

Losing accuracy is impossible, because the only possible values of __SHIFTOUT(..., __BITS(10,6)) are at most five bits long (10 - 6 + 1), and the only possible values of 0xc0 | <fivebits> are eight bits long, and the type of the result (char8_t) is always at least eight bits.

lint needs to be able to handle this kind of __SHIFTOUT, which is designed to make this kind of bit hacking clear to the reader.  Requiring the addition of casts clutters the code and puts an unnecessary burden on the reader to wonder whether there is additional truncation going on.
>How-To-Repeat:
as above
>Fix:
Yes, please!



Home | Main Index | Thread Index | Old Index