From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id 777413871A94; Mon, 7 Aug 2023 11:51:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 777413871A94 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691409112; bh=vgWmi5ysMvEJxTb5ixOViR0KWPIewuZR/Vng9B4Sab8=; h=From:To:Subject:Date:From; b=P74o+T0uF4Xke5YzDr99maIXAx1AtyJKee9ub4KN+xWdiy1gqRtsAnT6e2NllUK+J 5sI46mWMBxVpAeMF1WTwGQOfVEC7gsLp8BQQC9MN+cgZiIwFXc/e6VyYhWWAz80gJU v1VSL90/AdPp0TNPoFQgLD3GC95JzCpsDL2Vr2wk= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] sys/cdefs.h: fix for use __restrict in C++ X-Act-Checkin: newlib-cygwin X-Git-Author: Sebastian Huber X-Git-Refname: refs/heads/master X-Git-Oldrev: b12934540f17ba7c22923940e48bfbf02d0ae082 X-Git-Newrev: 3c75fac130b5720068707f67b12f4372abf4ad38 Message-Id: <20230807115152.777413871A94@sourceware.org> Date: Mon, 7 Aug 2023 11:51:52 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3c75fac130b= 5720068707f67b12f4372abf4ad38 commit 3c75fac130b5720068707f67b12f4372abf4ad38 Author: Sebastian Huber Date: Sun Aug 6 16:27:27 2023 +0300 sys/cdefs.h: fix for use __restrict in C++ =20 Newlib shares large parts of with FreeBSD and received this bug report: =20 https://sourceware.org/pipermail/newlib/2023/020400.html =20 As an extension, GCC and clang offer C99-style restricted pointers in C++ mode: https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html =20 We notice that this extension is broken when including newlib headers: restricted pointers are treated as ordinary pointers. =20 We traced this to the following section of newlib/libc/include/sys/cdefs.h: =20 /* * GCC 2.95 provides `__restrict' as an extension to C90 to support t= he * C99-specific `restrict' type qualifier. We happen to use `__restr= ict' as * a way to define the `restrict' type qualifier without disturbing o= lder * 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 =20 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 =20 Rewrite the logic in the header so that __restrict is kept alone when available. =20 PR: 272723 MFC after: 1 week Diff: --- 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/cdef= s.h index 808498c50..cc1a8a1cc 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 older - * 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 /*