From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 19AC53857C40 for ; Mon, 7 Aug 2023 09:28:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19AC53857C40 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy05.your-server.de ([78.46.172.2]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qSwXM-000HdO-NH for newlib@sourceware.org; Mon, 07 Aug 2023 11:28:28 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qSwXM-000Ie9-JZ for newlib@sourceware.org; Mon, 07 Aug 2023 11:28:28 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 4413D480136 for ; Mon, 7 Aug 2023 11:28:28 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10032) with ESMTP id cMWOCcSrOvy0 for ; Mon, 7 Aug 2023 11:28:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id EEE9A48017C for ; Mon, 7 Aug 2023 11:28:27 +0200 (CEST) X-Virus-Scanned: amavis at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10026) with ESMTP id 6wfWx4QiaO8p for ; Mon, 7 Aug 2023 11:28:27 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id C51F948017E for ; Mon, 7 Aug 2023 11:28:27 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Date: Mon, 7 Aug 2023 11:28:25 +0200 Message-Id: <20230807092825.24459-3-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230807092825.24459-1-sebastian.huber@embedded-brains.de> References: <20230807092825.24459-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldi-networks.de X-Virus-Scanned: Clear (ClamAV 0.103.8/26993/Mon Aug 7 09:28:50 2023) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_SHORT,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 server2.sourceware.org List-Id: Newlib shares large parts of with FreeBSD and received this bug report: https://sourceware.org/pipermail/newlib/2023/020400.html As an extension, GCC and clang offer C99-style restricted pointers in C++ mode: https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html We notice that this extension is broken when including newlib headers: restricted pointers are treated as ordinary pointers. We traced this to the following section of newlib/libc/include/sys/cdefs.h: /* * GCC 2.95 provides `__restrict' as an extension to C90 to support the * C99-specific `restrict' type qualifier. We happen to use `__restric= t' as * a way to define the `restrict' type qualifier without disturbing old= er * software that is unaware of C99 keywords. */ #if !(__GNUC__ =3D=3D 2 && __GNUC_MINOR__ =3D=3D 95) #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif #endif While the GCC __restrict extension was indeed introduced in GCC 2.95, it is not limited to this version; the extension is also not limited to C90: https://gcc.gnu.org/gcc-2.95/c++features.html Rewrite the logic in the header so that __restrict is kept alone when available. PR: 272723 MFC after: 1 week --- newlib/libc/include/sys/cdefs.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cd= efs.h index 808498c50b..cc1a8a1ccb 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -412,17 +412,15 @@ #endif =20 /* - * GCC 2.95 provides `__restrict' as an extension to C90 to support the - * C99-specific `restrict' type qualifier. We happen to use `__restrict= ' as - * a way to define the `restrict' type qualifier without disturbing olde= r - * software that is unaware of C99 keywords. + * We use `__restrict' as a way to define the `restrict' type qualifier + * without disturbing older software that is unaware of C99 keywords. + * GCC also provides `__restrict' as an extension to support C99-style + * restricted pointers in other language modes. */ -#if !(__GNUC__ =3D=3D 2 && __GNUC_MINOR__ =3D=3D 95) -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 -#define __restrict -#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >=3D 199901 #define __restrict restrict -#endif +#elif !__GNUC_PREREQ__(2, 95) +#define __restrict #endif =20 /* --=20 2.35.3