public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Sebastian Huber <sh@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] sys/cdefs.h: fix for use __restrict in C++
Date: Mon,  7 Aug 2023 11:51:52 +0000 (GMT)	[thread overview]
Message-ID: <20230807115152.777413871A94@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3c75fac130b5720068707f67b12f4372abf4ad38

commit 3c75fac130b5720068707f67b12f4372abf4ad38
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Sun Aug 6 16:27:27 2023 +0300

    sys/cdefs.h: fix for use __restrict in C++
    
    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

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/cdefs.h
index 808498c50..cc1a8a1cc 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
 
 /*

                 reply	other threads:[~2023-08-07 11:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230807115152.777413871A94@sourceware.org \
    --to=sh@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).