diff mbox

Fix non-__GNUC__ definitions of __inline and __restrict (bug 17721)

Message ID alpine.DEB.2.20.1802012035030.13065@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers Feb. 1, 2018, 8:35 p.m. UTC
Bug 17721 reports that the non-__GNUC__ definitions of __inline and
__restrict are suboptimal, in that they are defined to empty when they
could be defined to inline and restrict for appropriate language
versions.  This patch makes those fixes.

Tested for x86_64 (however, I have not done any testing with an actual
non-__GNUC__ compiler and it's likely such compilers may have other
problems with glibc headers).

2018-02-01  Joseph Myers  <joseph@codesourcery.com>

	[BZ #17721]
	* misc/sys/cdefs.h [!__GNUC__ && (__cplusplus || (__STDC_VERSION__
	&& __STDC_VERSION__ >= 199901L))] (__inline): Define to inline.
	[!__GNUC_PREREQ (2,92) && __STDC_VERSION__ && __STDC_VERSION__ >=
	199901L] (__restrict): Define to restrict.

Comments

Joseph Myers Feb. 6, 2018, 6 p.m. UTC | #1
Ping.  This patch 
<https://sourceware.org/ml/libc-alpha/2018-02/msg00030.html> is pending 
review.
Adhemerval Zanella Feb. 6, 2018, 7:37 p.m. UTC | #2
On 01/02/2018 18:35, Joseph Myers wrote:
> Bug 17721 reports that the non-__GNUC__ definitions of __inline and
> __restrict are suboptimal, in that they are defined to empty when they
> could be defined to inline and restrict for appropriate language
> versions.  This patch makes those fixes.
> 
> Tested for x86_64 (however, I have not done any testing with an actual
> non-__GNUC__ compiler and it's likely such compilers may have other
> problems with glibc headers).

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> 
> 2018-02-01  Joseph Myers  <joseph@codesourcery.com>
> 
> 	[BZ #17721]
> 	* misc/sys/cdefs.h [!__GNUC__ && (__cplusplus || (__STDC_VERSION__
> 	&& __STDC_VERSION__ >= 199901L))] (__inline): Define to inline.
> 	[!__GNUC_PREREQ (2,92) && __STDC_VERSION__ && __STDC_VERSION__ >=
> 	199901L] (__restrict): Define to restrict.
> 
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index af103fd..e80a45c 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -72,7 +72,12 @@
>  
>  #else	/* Not GCC.  */
>  
> -# define __inline		/* No inline functions.  */
> +# if (defined __cplusplus						\
> +      || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
> +#  define __inline	inline
> +# else
> +#  define __inline		/* No inline functions.  */
> +# endif
>  
>  # define __THROW
>  # define __THROWNL
> @@ -368,7 +373,11 @@
>  
>  /* __restrict is known in EGCS 1.2 and above. */
>  #if !__GNUC_PREREQ (2,92)
> -# define __restrict	/* Ignore */
> +# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
> +#  define __restrict	restrict
> +# else
> +#  define __restrict	/* Ignore */
> +# endif
>  #endif

Can't we dump the __GNUC_PREREQ and just check for __STDC_VERSION__? Or old
GCC version does not correct correctly?

>  
>  /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
>
Joseph Myers Feb. 6, 2018, 9:47 p.m. UTC | #3
On Tue, 6 Feb 2018, Adhemerval Zanella wrote:

> >  /* __restrict is known in EGCS 1.2 and above. */
> >  #if !__GNUC_PREREQ (2,92)
> > -# define __restrict	/* Ignore */
> > +# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
> > +#  define __restrict	restrict
> > +# else
> > +#  define __restrict	/* Ignore */
> > +# endif
> >  #endif
> 
> Can't we dump the __GNUC_PREREQ and just check for __STDC_VERSION__? Or old
> GCC version does not correct correctly?

The point of the __GNUC_PREREQ (2,92) check is that for GCC 2.92 and later 
we still want to use __restrict (not define it to empty) outside C99 mode 
- whereas for other compilers, __restrict may not be supported, so we have 
to define it either to restrict or to empty.
diff mbox

Patch

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index af103fd..e80a45c 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -72,7 +72,12 @@ 
 
 #else	/* Not GCC.  */
 
-# define __inline		/* No inline functions.  */
+# if (defined __cplusplus						\
+      || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
+#  define __inline	inline
+# else
+#  define __inline		/* No inline functions.  */
+# endif
 
 # define __THROW
 # define __THROWNL
@@ -368,7 +373,11 @@ 
 
 /* __restrict is known in EGCS 1.2 and above. */
 #if !__GNUC_PREREQ (2,92)
-# define __restrict	/* Ignore */
+# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#  define __restrict	restrict
+# else
+#  define __restrict	/* Ignore */
+# endif
 #endif
 
 /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is