Module Name: src Committed By: riastradh Date: Tue Oct 8 13:42:17 UTC 2024
Modified Files: src/lib/libc/locale: c16rtomb.c c8rtomb.c Log Message: c16rtomb, c8rtomb: Omit needless casts. Mark remaining lint issues. These casts were introduced to pacify lint. lint has now been fixed to handle __SHIFTOUT/__BITS more robustly so some of them are no longer needed to pacify lint. But lint still objects without some semantically unnecessary casts -- mark those. - In c8rtomb, c32 is guaranteed to be at most 24-bit -- actually, at most 21-bit -- but I'm not sure how to prove this to lint without a transitive analysis of the state machine transitions and knowledge of the only allowed initial state. - In c16rtomb, the shiftouts are always 9-bit and so the shiftin should never overflow, but lint hasn't figured this out yet. PR standards/58601: uchar.h C23 compliance: char8_t, mbrtoc8, c8rtomb PR toolchain/58728: __SHIFTIN/__BITS of values in known-limited range without cast To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/libc/locale/c16rtomb.c cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c8rtomb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/locale/c16rtomb.c diff -u src/lib/libc/locale/c16rtomb.c:1.7 src/lib/libc/locale/c16rtomb.c:1.8 --- src/lib/libc/locale/c16rtomb.c:1.7 Wed Aug 21 18:36:11 2024 +++ src/lib/libc/locale/c16rtomb.c Tue Oct 8 13:42:17 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: c16rtomb.c,v 1.7 2024/08/21 18:36:11 rillig Exp $ */ +/* $NetBSD: c16rtomb.c,v 1.8 2024/10/08 13:42:17 riastradh Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: c16rtomb.c,v 1.7 2024/08/21 18:36:11 rillig Exp $"); +__RCSID("$NetBSD: c16rtomb.c,v 1.8 2024/10/08 13:42:17 riastradh Exp $"); #include "namespace.h" @@ -177,6 +177,11 @@ c16rtomb_l(char *restrict s, char16_t c1 } const char16_t w1 = S->surrogate; const char16_t w2 = c16; + /* + * XXX lint is unconvinced that this cast is needless: + * PR toolchain/58728: __SHIFTIN/__BITS of values in + * known-limited range without cast + */ c32 = (char32_t)( __SHIFTIN(__SHIFTOUT(w1, __BITS(9,0)), __BITS(19,10)) | __SHIFTIN(__SHIFTOUT(w2, __BITS(9,0)), __BITS(9,0))); Index: src/lib/libc/locale/c8rtomb.c diff -u src/lib/libc/locale/c8rtomb.c:1.6 src/lib/libc/locale/c8rtomb.c:1.7 --- src/lib/libc/locale/c8rtomb.c:1.6 Sun Aug 18 12:41:38 2024 +++ src/lib/libc/locale/c8rtomb.c Tue Oct 8 13:42:17 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: c8rtomb.c,v 1.6 2024/08/18 12:41:38 riastradh Exp $ */ +/* $NetBSD: c8rtomb.c,v 1.7 2024/10/08 13:42:17 riastradh Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: c8rtomb.c,v 1.6 2024/08/18 12:41:38 riastradh Exp $"); +__RCSID("$NetBSD: c8rtomb.c,v 1.7 2024/10/08 13:42:17 riastradh Exp $"); #include "namespace.h" @@ -193,8 +193,8 @@ c8rtomb_l(char *restrict s, char8_t c8, * Get the current state and buffer. */ __CTASSERT(UTF8_ACCEPT == 0); /* initial conversion state */ - state = (utf8_state_t)__SHIFTOUT(S->state_c32, __BITS(31,24)); - c32 = (char32_t)__SHIFTOUT(S->state_c32, __BITS(23,0)); + state = __SHIFTOUT(S->state_c32, __BITS(31,24)); + c32 = __SHIFTOUT(S->state_c32, __BITS(23,0)); /* * Feed the byte into the state machine to update the state. @@ -211,6 +211,11 @@ c8rtomb_l(char *restrict s, char8_t c8, /* * Valid UTF-8 so far but incomplete. Update state and * output nothing. + * + * XXX lint is unconvinced that this cast is needless. + * Related to (but perhaps not addressed by solving): + * PR toolchain/58728: __SHIFTIN/__BITS of values in + * known-limited range without cast */ S->state_c32 = (char32_t)( __SHIFTIN(state, __BITS(31,24)) |