* improve clang support (25)
@ 2020-08-12 0:29 Bruno Haible
2020-08-16 16:45 ` Bruno Haible
0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2020-08-12 0:29 UTC (permalink / raw
To: bug-gnulib
Where does clang support the 'restrict' and '__restrict' keywords? It's
like with GCC >= 3.1:
C mode C++ mode
T*__restrict supported supported
[__restrict] supported error
T*restrict supported error
[restrict] supported error
According to this table, it's possible to enable restrict checking also
with clang, when it does not masquerade as GCC.
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.
diff --git a/lib/cdefs.h b/lib/cdefs.h
index 4086d51..dfa935f 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -399,8 +399,10 @@
# 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
@@ -410,8 +412,9 @@
/* 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__
diff --git a/lib/regex.h b/lib/regex.h
index 5fe41c8..7418e6c 100644
--- a/lib/regex.h
+++ b/lib/regex.h
@@ -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_
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
index c4dd01a..537fac7 100644
--- a/lib/spawn.in.h
+++ b/lib/spawn.in.h
@@ -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
@@ -58,13 +60,18 @@
# 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_
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: improve clang support (25)
2020-08-12 0:29 improve clang support (25) Bruno Haible
@ 2020-08-16 16:45 ` Bruno Haible
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2020-08-16 16:45 UTC (permalink / raw
To: bug-gnulib
> Where does clang support the 'restrict' and '__restrict' keywords? It's
> like with GCC >= 3.1:
>
> C mode C++ mode
>
> T*__restrict supported supported
> [__restrict] supported error
> T*restrict supported error
> [restrict] supported error
'__restrict' is also dealt with in a couple of other files. Here are the
corresponding updates.
2020-08-16 Bruno Haible <bruno@clisp.org>
Use __restrict also on clang.
* lib/argp.h (__restrict): Don't define as a macro on clang >= 3.
* lib/glob.in.h (_Restrict_): Use __restrict on clang >= 3.
* lib/unitypes.in.h (_UC_RESTRICT): Likewise.
diff --git a/lib/argp.h b/lib/argp.h
index 808c900..c71dd96 100644
--- a/lib/argp.h
+++ b/lib/argp.h
@@ -39,7 +39,8 @@
Other compilers use __restrict, __restrict__, and _Restrict, and
'configure' might #define 'restrict' to those words. */
#ifndef __restrict
-# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
+# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__) \
+ || __clang_major__ >= 3)
# if 199901L <= __STDC_VERSION__
# define __restrict restrict
# else
diff --git a/lib/glob.in.h b/lib/glob.in.h
index 7061a25..d1c0733 100644
--- a/lib/glob.in.h
+++ b/lib/glob.in.h
@@ -45,7 +45,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
diff --git a/lib/unitypes.in.h b/lib/unitypes.in.h
index b11326d..63d0fe3 100644
--- a/lib/unitypes.in.h
+++ b/lib/unitypes.in.h
@@ -47,7 +47,9 @@ typedef uint32_t ucs4_t;
pass a pointer to a different object in the specified pointer argument
than in the other pointer arguments. */
#ifndef _UC_RESTRICT
-# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
+# if defined __restrict \
+ || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) \
+ || __clang_major__ >= 3
# define _UC_RESTRICT __restrict
# elif 199901L <= __STDC_VERSION__ || defined restrict
# define _UC_RESTRICT restrict
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-16 16:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-12 0:29 improve clang support (25) Bruno Haible
2020-08-16 16:45 ` Bruno Haible
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).