NetBSD Problem Report #58617

From www@netbsd.org  Sun Aug 18 13:32:59 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4915B1A9242
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 18 Aug 2024 13:32:59 +0000 (UTC)
Message-Id: <20240818133258.02F2C1A9243@mollari.NetBSD.org>
Date: Sun, 18 Aug 2024 13:32:57 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: lint spuriously warns about impossible __SHIFTOUT/__BITS truncation
X-Send-Pr-Version: www-1.0

>Number:         58617
>Category:       toolchain
>Synopsis:       lint spuriously warns about impossible __SHIFTOUT/__BITS truncation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    rillig
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 18 13:35:00 +0000 2024
>Closed-Date:    Sun Aug 18 16:55:46 +0000 2024
>Last-Modified:  Sun Aug 18 16:55:46 +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!

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: toolchain-manager->rillig
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Sun, 18 Aug 2024 13:41:24 +0000
Responsible-Changed-Why:
Can you take a look at this when you have a moment?


From: "Roland Illig" <rillig@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58617 CVS commit: src/tests/usr.bin/xlint/lint1
Date: Sun, 18 Aug 2024 15:11:43 +0000

 Module Name:	src
 Committed By:	rillig
 Date:		Sun Aug 18 15:11:43 UTC 2024

 Modified Files:
 	src/tests/usr.bin/xlint/lint1: msg_132.c

 Log Message:
 tests/lint: demonstrate wrong warning about accuracy loss

 Demonstrates PR toolchain/58617.


 To generate a diff of this commit:
 cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/xlint/lint1/msg_132.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Roland Illig" <rillig@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58617 CVS commit: src
Date: Sun, 18 Aug 2024 15:21:09 +0000

 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.

State-Changed-From-To: open->closed
State-Changed-By: rillig@NetBSD.org
State-Changed-When: Sun, 18 Aug 2024 16:55:46 +0000
State-Changed-Why:
Fixed, thanks for the PR.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.