From patchwork Thu Apr 16 21:00:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Sherrill X-Patchwork-Id: 133218 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 86A294C91769 for ; Thu, 16 Apr 2026 21:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86A294C91769 X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by sourceware.org (Postfix) with ESMTPS id 9A6584C9175B for ; Thu, 16 Apr 2026 21:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A6584C9175B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rtems.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A6584C9175B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776373291; cv=none; b=FAHRSw0nkMA8nh3NLoz5f4xR07XnHcu6LGqOArOaOpA/8DU3YxMytmmuosltFHWqm1Ur2KoI650FmWtfma2YfVYeYLchzLjdVCmQmpiV/aRluCNTADYj9hrs+ZhC0IIxZ2GxEa+l+o7uqFfv31YWaTTQ9R6O82PQbHRp/rMfilQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776373291; c=relaxed/simple; bh=o7SRjL4dUaJ8vbF9M0lyY0btP/BmTKtKNHvkk+BMtZA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DPUfwL8T9uHJx7dk1VA0JpCUOfvckw9MTy1L6Xe8mDjS7rMPLeyKsJP2csmGeyL7w4ctctG5jg6FAvHvVunlnmGYykSBYFqubNy9cBRI6GgXdsVYOi4BojC4PsawPdwfeiRJj5XvJoxqo2P2xzsHFObvIY5HydfdXgWFqZTKRWk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A6584C9175B Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-794719afcd4so93717197b3.1 for ; Thu, 16 Apr 2026 14:01:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776373289; x=1776978089; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5Zs8PNchTaWydpDmDfciCjAUJxRaLNqJVJ0wupMHwss=; b=HN5TnT2RSuVrMMD2YdOYmbxYr0mAo9oMfCnwURgQcgWITxft7wnmJx0MlB/TnK1MLn p9+21aVVbTwpo7X0AN7BGLFe+hBmWrxnNh6t39W0DAzYLRpShTXVLy8bqQwzA9tgUcH0 tztU/IFq+KshiACPh/EQBPvmA6U4cY3DLGbawBDWan4eIx27n0EzEwQkDVH49y5NJb/D QUX98+1BDDWL+pTX6i/t024566wCynHms4Pq3jDEPdEL69KdW3X4iw8mxyBEt8HfsTSu xAd5Q1Wq/nUq+EwkeQNcfHYm52zU3ya84//I7QslC0SMNqhVVSAPTpNl9niboSqlroX/ 0ItQ== X-Gm-Message-State: AOJu0YymRUmrQ29HXwxHL1sH3f4MBr9XysvEH6PBJNs6Fb9BGgJDQlfP 0EKeJrxok2IdlA2XuZI06hGrySdB6+bsC0bxcHK1dt4aQBouJ1RckKQ1aovf9lCP X-Gm-Gg: AeBDies2nRpS+GKTUp85lM6I8Ha+7hcjrFhnBsSPcXKRGTRpM8AvwyOB/PeAyU9CXFM tYYpih8gM6zMs0gy1Ok0r+vGWrt8szO0lmcAqRIPqLZ+cgk9B0OIq6CHdOTixMJQVdVIChA4G6B Fl+4ouXmxv6nu43RX7EJfpTxUiLXbyTHI9PxJuu4aUv/FHCRAAs5O1ukdGzeseyQCdUOvqsiRfm RNNJFGg1QmUTgxq+0A+WDTMYdkZwtHnHmoJJhId12zGPsNIWuhqfZCWTcxFGpBF8svKWpI+8hQE JgSXa6vgesSyW3Woj0vw3qJ8rfJFaaRlh1a2AuNLskj3H6a/TzsvOKNi7eH6hYwsNxSQysPLiqO wBZsbhgRH2pLkmtl/c1gqtbIZKG0R86yh5k11QSfb68y5id7wck6f7C3UeFUQEKjsnIEOAn2MVu v6PgnCK8kQ3ah25tz0Fpu5kmnkXxnjnzGdrL2F+oodioWbKiDDlFtMZLGELyiBJwU0f3sIBhyW X-Received: by 2002:a05:690c:1d:b0:7b4:f43f:1a23 with SMTP id 00721157ae682-7b9ecfa1baamr1480537b3.34.1776373289136; Thu, 16 Apr 2026 14:01:29 -0700 (PDT) Received: from gitlab.oarcorp.com (d27-96-189-151.evv.wideopenwest.com. [96.27.151.189]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7b76931854esm28916287b3.37.2026.04.16.14.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2026 14:01:27 -0700 (PDT) From: Joel Sherrill To: newlib@sourceware.org Cc: Joel Sherrill Subject: [PATCH v3 4/6] newlib/libc/stdbit: Make compile for C99 and newer Date: Thu, 16 Apr 2026 16:00:45 -0500 Message-ID: <20260416210047.2198615-5-joel@rtems.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260416210047.2198615-1-joel@rtems.org> References: <20260416210047.2198615-1-joel@rtems.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3036.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org This involved two issues. First, is that C23 adds multiple _WIDTH constants which are used by the implementation. This is addressed by stdbit_internal.h defining them if needed. Second, C99 does not have static_assert(). Changed to use newlib's _Static_assert() adapter which has implementations for C99 and newer. --- newlib/libc/stdbit/stdbit_internal.h | 47 +++++++++++++++++++ newlib/libc/stdbit/stdc_bit_ceil.c | 6 ++- newlib/libc/stdbit/stdc_bit_floor.c | 2 + newlib/libc/stdbit/stdc_bit_width.c | 2 + newlib/libc/stdbit/stdc_count_ones.c | 2 + newlib/libc/stdbit/stdc_count_zeros.c | 2 + newlib/libc/stdbit/stdc_first_leading_one.c | 2 + newlib/libc/stdbit/stdc_first_leading_zero.c | 2 + newlib/libc/stdbit/stdc_first_trailing_one.c | 2 + newlib/libc/stdbit/stdc_first_trailing_zero.c | 2 + newlib/libc/stdbit/stdc_has_single_bit.c | 2 + newlib/libc/stdbit/stdc_leading_ones.c | 6 ++- newlib/libc/stdbit/stdc_leading_zeros.c | 6 ++- newlib/libc/stdbit/stdc_trailing_ones.c | 6 ++- newlib/libc/stdbit/stdc_trailing_zeros.c | 6 ++- 15 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 newlib/libc/stdbit/stdbit_internal.h diff --git a/newlib/libc/stdbit/stdbit_internal.h b/newlib/libc/stdbit/stdbit_internal.h new file mode 100644 index 000000000..0d99c691b --- /dev/null +++ b/newlib/libc/stdbit/stdbit_internal.h @@ -0,0 +1,47 @@ +/* + * Newlib specific addition to ensure the C23 *_WIDTH constants + * used in the stdbits implementation are available even when + * compiling using another version of the C Programming Language. + */ + +/* + * Written by Joel Sherrill . + * + * COPYRIGHT (c) 2026. + * On-Line Applications Research Corporation (OAR). + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION + * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS + * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + */ + +#ifndef STDBIT_INTERNAL_h +#define STDBIT_INTERNAL_h + +#ifndef UCHAR_WIDTH +#define UCHAR_WIDTH __SCHAR_WIDTH__ +#endif + +#ifndef USHRT_WIDTH +#define USHRT_WIDTH __SHRT_WIDTH__ +#endif + +#ifndef UINT_WIDTH +#define UINT_WIDTH __INT_WIDTH__ +#endif + +#ifndef ULONG_WIDTH +#define ULONG_WIDTH __LONG_LONG_WIDTH__ +#endif + +#ifndef ULLONG_WIDTH +#define ULLONG_WIDTH __LONG_LONG_WIDTH__ +#endif + +#endif diff --git a/newlib/libc/stdbit/stdc_bit_ceil.c b/newlib/libc/stdbit/stdc_bit_ceil.c index 2dfd7bbcb..f25d184af 100644 --- a/newlib/libc/stdbit/stdc_bit_ceil.c +++ b/newlib/libc/stdbit/stdc_bit_ceil.c @@ -8,8 +8,10 @@ #include #include +#include "stdbit_internal.h" + /* Ensure we don't shift 1U out of range. */ -static_assert(UCHAR_WIDTH < UINT_WIDTH, +_Static_assert(UCHAR_WIDTH < UINT_WIDTH, "stdc_bit_ceil_uc needs UCHAR_WIDTH < UINT_WIDTH"); unsigned char @@ -22,7 +24,7 @@ stdc_bit_ceil_uc(unsigned char x) } /* Ensure we don't shift 1U out of range. */ -static_assert(USHRT_WIDTH < UINT_WIDTH, +_Static_assert(USHRT_WIDTH < UINT_WIDTH, "stdc_bit_ceil_us needs USHRT_WIDTH < UINT_WIDTH"); unsigned short diff --git a/newlib/libc/stdbit/stdc_bit_floor.c b/newlib/libc/stdbit/stdc_bit_floor.c index 0a491d6ec..ab9156056 100644 --- a/newlib/libc/stdbit/stdc_bit_floor.c +++ b/newlib/libc/stdbit/stdc_bit_floor.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned char stdc_bit_floor_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_bit_width.c b/newlib/libc/stdbit/stdc_bit_width.c index e248fae48..602916d21 100644 --- a/newlib/libc/stdbit/stdc_bit_width.c +++ b/newlib/libc/stdbit/stdc_bit_width.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_bit_width_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_count_ones.c b/newlib/libc/stdbit/stdc_count_ones.c index c5198dca8..6dfcbfd45 100644 --- a/newlib/libc/stdbit/stdc_count_ones.c +++ b/newlib/libc/stdbit/stdc_count_ones.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_count_ones_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_count_zeros.c b/newlib/libc/stdbit/stdc_count_zeros.c index 35db965af..49f1ff851 100644 --- a/newlib/libc/stdbit/stdc_count_zeros.c +++ b/newlib/libc/stdbit/stdc_count_zeros.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_count_zeros_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_first_leading_one.c b/newlib/libc/stdbit/stdc_first_leading_one.c index de4368565..ad95b3cfd 100644 --- a/newlib/libc/stdbit/stdc_first_leading_one.c +++ b/newlib/libc/stdbit/stdc_first_leading_one.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_first_leading_one_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_first_leading_zero.c b/newlib/libc/stdbit/stdc_first_leading_zero.c index e6609b51b..4e3d29002 100644 --- a/newlib/libc/stdbit/stdc_first_leading_zero.c +++ b/newlib/libc/stdbit/stdc_first_leading_zero.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_first_leading_zero_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_first_trailing_one.c b/newlib/libc/stdbit/stdc_first_trailing_one.c index 22972758d..23d2329ea 100644 --- a/newlib/libc/stdbit/stdc_first_trailing_one.c +++ b/newlib/libc/stdbit/stdc_first_trailing_one.c @@ -6,6 +6,8 @@ #include +#include "stdbit_internal.h" + unsigned int stdc_first_trailing_one_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_first_trailing_zero.c b/newlib/libc/stdbit/stdc_first_trailing_zero.c index 27395c697..248f8d99b 100644 --- a/newlib/libc/stdbit/stdc_first_trailing_zero.c +++ b/newlib/libc/stdbit/stdc_first_trailing_zero.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + unsigned int stdc_first_trailing_zero_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_has_single_bit.c b/newlib/libc/stdbit/stdc_has_single_bit.c index a448464b0..9a235c023 100644 --- a/newlib/libc/stdbit/stdc_has_single_bit.c +++ b/newlib/libc/stdbit/stdc_has_single_bit.c @@ -7,6 +7,8 @@ #include #include +#include "stdbit_internal.h" + bool stdc_has_single_bit_uc(unsigned char x) { diff --git a/newlib/libc/stdbit/stdc_leading_ones.c b/newlib/libc/stdbit/stdc_leading_ones.c index 79d3ec7f2..c7ab75b98 100644 --- a/newlib/libc/stdbit/stdc_leading_ones.c +++ b/newlib/libc/stdbit/stdc_leading_ones.c @@ -8,8 +8,10 @@ #include #include +#include "stdbit_internal.h" + /* Avoid triggering undefined behavior if x == 0. */ -static_assert(UCHAR_WIDTH < UINT_WIDTH, +_Static_assert(UCHAR_WIDTH < UINT_WIDTH, "stdc_leading_ones_uc needs UCHAR_WIDTH < UINT_WIDTH"); unsigned int @@ -21,7 +23,7 @@ stdc_leading_ones_uc(unsigned char x) } /* Avoid triggering undefined behavior if x == 0. */ -static_assert(USHRT_WIDTH < UINT_WIDTH, +_Static_assert(USHRT_WIDTH < UINT_WIDTH, "stdc_leading_ones_us needs USHRT_WIDTH < UINT_WIDTH"); unsigned int diff --git a/newlib/libc/stdbit/stdc_leading_zeros.c b/newlib/libc/stdbit/stdc_leading_zeros.c index 2fdf64ec9..dba6a14e2 100644 --- a/newlib/libc/stdbit/stdc_leading_zeros.c +++ b/newlib/libc/stdbit/stdc_leading_zeros.c @@ -8,8 +8,10 @@ #include #include +#include "stdbit_internal.h" + /* Offset must be greater than zero. */ -static_assert(UCHAR_WIDTH < UINT_WIDTH, +_Static_assert(UCHAR_WIDTH < UINT_WIDTH, "stdc_leading_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH"); unsigned int @@ -21,7 +23,7 @@ stdc_leading_zeros_uc(unsigned char x) } /* Offset must be greater than zero. */ -static_assert(USHRT_WIDTH < UINT_WIDTH, +_Static_assert(USHRT_WIDTH < UINT_WIDTH, "stdc_leading_zeros_us needs USHRT_WIDTH < UINT_WIDTH"); unsigned int diff --git a/newlib/libc/stdbit/stdc_trailing_ones.c b/newlib/libc/stdbit/stdc_trailing_ones.c index c1a0e6b99..0f7ccb553 100644 --- a/newlib/libc/stdbit/stdc_trailing_ones.c +++ b/newlib/libc/stdbit/stdc_trailing_ones.c @@ -8,8 +8,10 @@ #include #include +#include "stdbit_internal.h" + /* Avoid triggering undefined behavior if x == ~0. */ -static_assert(UCHAR_WIDTH < UINT_WIDTH, +_Static_assert(UCHAR_WIDTH < UINT_WIDTH, "stdc_trailing_ones_uc needs UCHAR_WIDTH < UINT_WIDTH"); unsigned int @@ -19,7 +21,7 @@ stdc_trailing_ones_uc(unsigned char x) } /* Avoid triggering undefined behavior if x == ~0. */ -static_assert(USHRT_WIDTH < UINT_WIDTH, +_Static_assert(USHRT_WIDTH < UINT_WIDTH, "stdc_trailing_ones_uc needs USHRT_WIDTH < UINT_WIDTH"); unsigned int diff --git a/newlib/libc/stdbit/stdc_trailing_zeros.c b/newlib/libc/stdbit/stdc_trailing_zeros.c index 6213f62cf..396333e17 100644 --- a/newlib/libc/stdbit/stdc_trailing_zeros.c +++ b/newlib/libc/stdbit/stdc_trailing_zeros.c @@ -8,8 +8,10 @@ #include #include +#include "stdbit_internal.h" + /* Ensure we do not shift 1U out of range. */ -static_assert(UCHAR_WIDTH < UINT_WIDTH, +_Static_assert(UCHAR_WIDTH < UINT_WIDTH, "stdc_trailing_zeros_uc needs UCHAR_WIDTH < UINT_WIDTH"); unsigned int @@ -19,7 +21,7 @@ stdc_trailing_zeros_uc(unsigned char x) } /* Ensure we do not shift 1U out of range. */ -static_assert(USHRT_WIDTH < UINT_WIDTH, +_Static_assert(USHRT_WIDTH < UINT_WIDTH, "stdc_trailing_zeros_uc needs USHRT_WIDTH < UINT_WIDTH"); unsigned int