[PATCH v2] Address regressions from e8ff555b95baab66cc7d060c1e7f9fdd49d3802f

Matt Turner mattst88 at gmail.com
Thu Sep 22 19:44:12 PDT 2011


On Thu, Sep 22, 2011 at 10:11 PM, Jeremy Huddleston <jeremyhu at apple.com> wrote:
> 1) The error attribute appeared in gcc-4.3
> 2) The return type of __builtin_constant_p is int
> 3) Sun Studio 12.0 and later builtin support for __builtin_constant_p
>
> Found by Tinderbox.
>
> Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
> ---
>  include/misc.h |   14 +++++++++-----
>  1 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/include/misc.h b/include/misc.h
> index 1fea73e..b583e31 100644
> --- a/include/misc.h
> +++ b/include/misc.h
> @@ -261,18 +261,22 @@ version_compare(uint16_t a_major, uint16_t a_minor,
>  #define SwapRestL(stuff) \
>     SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
>
> -#ifdef __GNUC__
> +#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
>  void __attribute__((error("wrong sized variable passed to swap"))) wrong_size(void);
>  #else
>  static inline void wrong_size(void)
>  {
>  }
> +#endif
>
> -static inline void __builtin_constant_p(int x)
> +static inline int constant_p(int x)
>  {
> +#if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
> +       return __builtin_constant_p(x);
> +#else
>        return 0;
> -}
>  #endif
> +}
>
>  /* byte swap a 32-bit value */
>  static inline void swap_uint32(uint32_t *x)
> @@ -288,7 +292,7 @@ static inline void swap_uint32(uint32_t *x)
>  #define swapl(x) do { \
>                if (sizeof(*(x)) != 4) \
>                        wrong_size(); \
> -               if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
> +               if (constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
>                        *(x) = lswapl(*(x)); \
>                else \
>                        swap_uint32((uint32_t *)(x)); \
> @@ -305,7 +309,7 @@ static inline void swap_uint16(uint16_t *x)
>  #define swaps(x) do { \
>                if (sizeof(*(x)) != 2) \
>                        wrong_size(); \
> -               if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
> +               if (constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
>                        *(x) = lswaps(*(x)); \
>                else \
>                        swap_uint16((uint16_t *)(x)); \
> --
> 1.7.6.1

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the xorg-devel mailing list