]> Savannah Git Hosting - gnulib.git/commitdiff
Use __restrict also on clang.
authorBruno Haible <bruno@clisp.org>
Wed, 12 Aug 2020 00:24:04 +0000 (02:24 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 12 Aug 2020 00:24:04 +0000 (02:24 +0200)
* lib/cdefs.h (__restrict): Don't define as a macro on clang.
(__restrict_arr): On clang, define like on GCC.
* lib/regex.h (_Restrict_): Use '__restrict' also on clang.
(_Restrict_arr_): Use _Restrict_ also on clang.
* lib/spawn.in.h (_Restrict_): Use '__restrict' also on clang.
(_Restrict_arr_): Use _Restrict_ also on clang.

ChangeLog
lib/cdefs.h
lib/regex.h
lib/spawn.in.h

index aced45e791d908106a808284d19b00686bf90249..5c17b05cb27d0530dc9ae0b377c475dc37c75aac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-11  Bruno Haible  <bruno@clisp.org>
+
+       Use __restrict also on clang.
+       * lib/cdefs.h (__restrict): Don't define as a macro on clang.
+       (__restrict_arr): On clang, define like on GCC.
+       * lib/regex.h (_Restrict_): Use '__restrict' also on clang.
+       (_Restrict_arr_): Use _Restrict_ also on clang.
+       * lib/spawn.in.h (_Restrict_): Use '__restrict' also on clang.
+       (_Restrict_arr_): Use _Restrict_ also on clang.
+
 2020-08-11  Bruno Haible  <bruno@clisp.org>
 
        Use flexible array syntax also on clang.
index 4086d51b28a3158d105e7f82c5be98ad8a90929d..dfa935fc8d4671547c18eea940393024aabe99f2 100644 (file)
 # define __extension__         /* Ignore */
 #endif
 
-/* __restrict is known in EGCS 1.2 and above. */
-#if !__GNUC_PREREQ (2,92)
+/* __restrict is known in EGCS 1.2 and above, and in clang.
+   It works also in C++ mode (outside of arrays), but only when spelled
+   as '__restrict', not 'restrict'.  */
+#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
 #  define __restrict   restrict
 # else
 
 /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
      array_name[restrict]
-   GCC 3.1 supports this.  */
-#if __GNUC_PREREQ (3,1) && !defined __GNUG__
+   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__
index 5fe41c86853fc2866d9dbd05670bac8b4895fa98..7418e6c76f06b63be0fda545a1c0311fb42f79ef 100644 (file)
@@ -612,7 +612,9 @@ extern int re_exec (const char *);
    'configure' might #define 'restrict' to those words, so pick a
    different name.  */
 #ifndef _Restrict_
-# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# if defined __restrict \
+     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
+     || __clang_major__ >= 3
 #  define _Restrict_ __restrict
 # elif 199901L <= __STDC_VERSION__ || defined restrict
 #  define _Restrict_ restrict
@@ -620,13 +622,18 @@ extern int re_exec (const char *);
 #  define _Restrict_
 # endif
 #endif
-/* For [restrict], use glibc's __restrict_arr if available.
-   Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict].  */
+/* For the ISO C99 syntax
+     array_name[restrict]
+   use glibc's __restrict_arr if available.
+   Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode).
+   Other ISO C99 compilers support it as well.  */
 #ifndef _Restrict_arr_
 # ifdef __restrict_arr
 #  define _Restrict_arr_ __restrict_arr
-# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \
-        && !defined __GNUG__)
+# elif ((199901L <= __STDC_VERSION__ \
+         || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+         || __clang_major__ >= 3) \
+        && !defined __cplusplus)
 #  define _Restrict_arr_ _Restrict_
 # else
 #  define _Restrict_arr_
index c4dd01aa35f4d53640472d7ead107530ce280d16..537fac7dbc55fa6111f7cd6db95bd91d52649a4c 100644 (file)
@@ -50,7 +50,9 @@
    'configure' might #define 'restrict' to those words, so pick a
    different name.  */
 #ifndef _Restrict_
-# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# if defined __restrict \
+     || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
+     || __clang_major__ >= 3
 #  define _Restrict_ __restrict
 # elif 199901L <= __STDC_VERSION__ || defined restrict
 #  define _Restrict_ restrict
 #  define _Restrict_
 # endif
 #endif
-/* For [restrict], use glibc's __restrict_arr if available.
-   Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict].  */
+/* For the ISO C99 syntax
+     array_name[restrict]
+   use glibc's __restrict_arr if available.
+   Otherwise, GCC 3.1 and clang support this syntax (but not in C++ mode).
+   Other ISO C99 compilers support it as well.  */
 #ifndef _Restrict_arr_
 # ifdef __restrict_arr
 #  define _Restrict_arr_ __restrict_arr
-# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \
-        && !defined __GNUG__)
+# elif ((199901L <= __STDC_VERSION__ \
+         || 3 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+         || __clang_major__ >= 3) \
+        && !defined __cplusplus)
 #  define _Restrict_arr_ _Restrict_
 # else
 #  define _Restrict_arr_