* [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD @ 2023-08-07 9:28 Sebastian Huber 2023-08-07 9:28 ` [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Sebastian Huber @ 2023-08-07 9:28 UTC (permalink / raw) To: newlib John Baldwin (1): <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber (1): sys/cdefs.h: fix for use __restrict in C++ newlib/libc/include/sys/cdefs.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) -- 2.35.3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() 2023-08-07 9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber @ 2023-08-07 9:28 ` Sebastian Huber 2023-08-07 9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber 2023-08-07 10:00 ` [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen 2 siblings, 0 replies; 7+ messages in thread From: Sebastian Huber @ 2023-08-07 9:28 UTC (permalink / raw) To: newlib From: John Baldwin <jhb@FreeBSD.org> This ensures that __generic() more closely matches _Generic() when using the fallback version when _Generic() is not available (such as GCC). Co-authored by: jrtc27 Reviewed by: jrtc27 Differential Revision: https://reviews.freebsd.org/D38215 --- newlib/libc/include/sys/cdefs.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h index 720e700920..808498c50b 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -328,6 +328,9 @@ * __generic(). Unlike _Generic(), this macro can only distinguish * between a single type, so it requires nested invocations to * distinguish multiple cases. + * + * Note that the comma operator is used to force expr to decay in + * order to match _Generic(). */ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ @@ -337,7 +340,7 @@ #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) #define __generic(expr, t, yes, no) \ __builtin_choose_expr( \ - __builtin_types_compatible_p(__typeof(expr), t), yes, no) + __builtin_types_compatible_p(__typeof((0, (expr))), t), yes, no) #endif /* -- 2.35.3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ 2023-08-07 9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber 2023-08-07 9:28 ` [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber @ 2023-08-07 9:28 ` Sebastian Huber 2023-08-07 13:15 ` Corinna Vinschen 2023-08-07 10:00 ` [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen 2 siblings, 1 reply; 7+ messages in thread From: Sebastian Huber @ 2023-08-07 9:28 UTC (permalink / raw) To: newlib Newlib shares large parts of <sys/cdefs.h> 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 `__restrict' as * a way to define the `restrict' type qualifier without disturbing older * software that is unaware of C99 keywords. */ #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 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/cdefs.h index 808498c50b..cc1a8a1ccb 100644 --- a/newlib/libc/include/sys/cdefs.h +++ b/newlib/libc/include/sys/cdefs.h @@ -412,17 +412,15 @@ #endif /* - * 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__ == 2 && __GNUC_MINOR__ == 95) -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 -#define __restrict -#else +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 #define __restrict restrict -#endif +#elif !__GNUC_PREREQ__(2, 95) +#define __restrict #endif /* -- 2.35.3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ 2023-08-07 9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber @ 2023-08-07 13:15 ` Corinna Vinschen 2023-08-07 13:35 ` Sebastian Huber 0 siblings, 1 reply; 7+ messages in thread From: Corinna Vinschen @ 2023-08-07 13:15 UTC (permalink / raw) To: Sebastian Huber; +Cc: newlib Hi Sebastian, On Aug 7 11:28, Sebastian Huber wrote: > diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h > index 808498c50b..cc1a8a1ccb 100644 > --- a/newlib/libc/include/sys/cdefs.h > +++ b/newlib/libc/include/sys/cdefs.h > @@ -412,17 +412,15 @@ > #endif > > /* > - * 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__ == 2 && __GNUC_MINOR__ == 95) > -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 > -#define __restrict > -#else > +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 > #define __restrict restrict > -#endif > +#elif !__GNUC_PREREQ__(2, 95) > +#define __restrict > #endif > > /* Turns out, this leads to a build failuer in Cygwin. We have a definition in aio.h: int lio_listio (int, struct aiocb *__restrict const [__restrict], int, struct sigevent *__restrict); and a matching one in aio.cc: int lio_listio (int mode, struct aiocb *__restrict const aiolist[__restrict], int nent, struct sigevent *__restrict sig) The problem is the bracket expression. The restrict keyword is allowed in C90, but not in C++. GLibc has a special definition __restrict_arr in cdefs.h, which is used in the brackets of the above definition: /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is array_name[restrict] GCC 3.1 and clang support this. This syntax is not usable in C++ mode. */ #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus # define __restrict_arr __restrict #else # ifdef __GNUC__ # define __restrict_arr /* Not supported in old GCC. */ # else # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L # define __restrict_arr restrict # else /* Some other non-C99 compiler. */ # define __restrict_arr /* Not supported. */ # endif # endif #endif This doesn't exist in FreeBSD, though. Do you think it's ok to add it to our cdefs.h, nevertheless? Thanks, Corinna ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ 2023-08-07 13:15 ` Corinna Vinschen @ 2023-08-07 13:35 ` Sebastian Huber 2023-08-07 14:10 ` Corinna Vinschen 0 siblings, 1 reply; 7+ messages in thread From: Sebastian Huber @ 2023-08-07 13:35 UTC (permalink / raw) To: newlib On 07.08.23 15:15, Corinna Vinschen wrote: > This doesn't exist in FreeBSD, though. Do you think it's ok to add it to > our cdefs.h, nevertheless? It is good to have glibc and FreeBSD compatibility from my point of view, so we should also add this __restrict_arr. -- embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ 2023-08-07 13:35 ` Sebastian Huber @ 2023-08-07 14:10 ` Corinna Vinschen 0 siblings, 0 replies; 7+ messages in thread From: Corinna Vinschen @ 2023-08-07 14:10 UTC (permalink / raw) To: Sebastian Huber; +Cc: newlib On Aug 7 15:35, Sebastian Huber wrote: > On 07.08.23 15:15, Corinna Vinschen wrote: > > This doesn't exist in FreeBSD, though. Do you think it's ok to add it to > > our cdefs.h, nevertheless? > > It is good to have glibc and FreeBSD compatibility from my point of view, so > we should also add this __restrict_arr. Thanks, I hope my just pused version is ok. Corinna ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD 2023-08-07 9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber 2023-08-07 9:28 ` [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber 2023-08-07 9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber @ 2023-08-07 10:00 ` Corinna Vinschen 2 siblings, 0 replies; 7+ messages in thread From: Corinna Vinschen @ 2023-08-07 10:00 UTC (permalink / raw) To: Sebastian Huber; +Cc: newlib On Aug 7 11:28, Sebastian Huber wrote: > John Baldwin (1): > <sys/cdefs.h>: Decay expression passed to fallback version of > __generic() > > Sebastian Huber (1): > sys/cdefs.h: fix for use __restrict in C++ > > newlib/libc/include/sys/cdefs.h | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) > > -- > 2.35.3 Okidoki! Thanks, Corinna ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-08-07 14:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-08-07 9:28 [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Sebastian Huber 2023-08-07 9:28 ` [PATCH 1/2] <sys/cdefs.h>: Decay expression passed to fallback version of __generic() Sebastian Huber 2023-08-07 9:28 ` [PATCH 2/2] sys/cdefs.h: fix for use __restrict in C++ Sebastian Huber 2023-08-07 13:15 ` Corinna Vinschen 2023-08-07 13:35 ` Sebastian Huber 2023-08-07 14:10 ` Corinna Vinschen 2023-08-07 10:00 ` [PATCH 0/2] Synchronize <sys/cdefs.h> with FreeBSD Corinna Vinschen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).