[Mesa-dev] [PATCH] util: fix NORETURN for msvc, add HAVE_FUNC_ATTRIBUTE_NORETURN to c99_compat.h

Brian Paul brianp at vmware.com
Wed Jan 10 02:38:48 UTC 2018


On 01/09/2018 07:15 PM, sroland at vmware.com wrote:
> From: Roland Scheidegger <sroland at vmware.com>
> 
> We've seen some problems internally due to macro redefinition.
> Fix this by adding HAVE_FUNC_ATTRIBUTE_NORETURN to c99_compat.h,
> and defining it for msvc.
> And avoid redefinition just in case.
> ---
>   include/c99_compat.h |  1 +
>   src/util/macros.h    | 12 ++++++++----
>   2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/include/c99_compat.h b/include/c99_compat.h
> index cb690c6..81621a7 100644
> --- a/include/c99_compat.h
> +++ b/include/c99_compat.h
> @@ -164,6 +164,7 @@ test_c99_compat_h(const void * restrict a,
>   #    define HAVE_FUNC_ATTRIBUTE_FORMAT 1
>   #    define HAVE_FUNC_ATTRIBUTE_PACKED 1
>   #    define HAVE_FUNC_ATTRIBUTE_ALIAS 1
> +#    define HAVE_FUNC_ATTRIBUTE_NORETURN 1
>   
>   #    if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
>          /* https://urldefense.proofpoint.com/v2/url?u=https-3A__gcc.gnu.org_onlinedocs_gcc-2D4.3.6_gcc_Other-2DBuiltins.html&d=DwIGaQ&c=uilaK90D4TOVoH58JNXRgQ&r=Ie7_encNUsqxbSRbqbNgofw0ITcfE8JKfaUjIQhncGA&m=oylXtmBLOzvwWe7ZHMkXZwIoBmh1Aq4Crp-zXabZjzE&s=CESxymd22FyLvhnwZwopuzUabQR-tlSIAmzo81-NE8k&e= */
> diff --git a/src/util/macros.h b/src/util/macros.h
> index 2a08407..5ce0e57 100644
> --- a/src/util/macros.h
> +++ b/src/util/macros.h
> @@ -171,10 +171,14 @@ do {                       \
>   #define ATTRIBUTE_RETURNS_NONNULL
>   #endif
>   
> -#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
> -#define NORETURN __attribute__((__noreturn__))
> -#else
> -#define NORETURN
> +#ifndef NORETURN
> +#  ifdef _MSC_VER
> +#    define NORETURN __declspec(noreturn)
> +#  elif defined HAVE_FUNC_ATTRIBUTE_NORETURN
> +#    define NORETURN __attribute__((__noreturn__))
> +#  else
> +#    define NORETURN
> +#  endif
>   #endif
>   
>   #ifdef __cplusplus
> 

I didn't test this, but looks OK to me.

Reviewed-by: Brian Paul <brianp at vmware.com>



More information about the mesa-dev mailing list