From 99d45c850e3962e4c89839dd8531de1c080b3ee7 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 20 Feb 2018 12:34:17 -0800 Subject: Fix problem with C99 inlines and -Werror=missing-prototypes Some older versions of gcc (gcc 4.2.1 at least) produce a warning, promoted to error, on C99 inlines. Do some work to figure out if we need to fall back to GNU inline syntax. Fix some issues with GNU inline syntax. Signed-off-by: H. Peter Anvin --- aclocal.m4 | 27 +++++++++++++++++++++++++++ configure.ac | 7 +++++++ include/compiler.h | 24 +++++++++++++++--------- include/iflag.h | 1 - 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index bd93193a..36d36cf8 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -172,3 +172,30 @@ AC_DEFUN(_PA_ADD_HEADER, AC_DEFUN(PA_ADD_HEADERS, [m4_map_args_w([$1],[_PA_ADD_HEADER(],[)])]) + +dnl -------------------------------------------------------------------------- +dnl PA_CHECK_BAD_STDC_INLINE +dnl +dnl Some versions of gcc seem to apply -Wmissing-prototypes to C99 +dnl inline functions, which means we need to use GNU inline syntax +dnl -------------------------------------------------------------------------- +AC_DEFUN(PA_CHECK_BAD_STDC_INLINE, +[AC_MSG_CHECKING([if $CC supports C99 external inlines]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +AC_INCLUDES_DEFAULT + +/* Don't mistake GNU inlines for c99 */ +#ifdef __GNUC_GNU_INLINE__ +# error "Using gnu inline standard" +#endif + +inline int foo(int x) +{ + return x+1; +} + ])], + [AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_STDC_INLINE, 1, + [Define to 1 if your compiler supports C99 extern inline])], + [AC_MSG_RESULT([no]) + PA_ADD_CFLAGS([-fgnu89-inline])])]) diff --git a/configure.ac b/configure.ac index 1f492103..7f1e1ce6 100644 --- a/configure.ac +++ b/configure.ac @@ -286,6 +286,13 @@ PA_ARG_ENABLED([werror], PA_ADD_CFLAGS([-Werror=vla])] ) +dnl +dnl On some versions of gcc, -Werror=missing-prototypes causes problems +dnl with C99-style external inlines. Test this *after* adding the -Werror +dnl options. +dnl +PA_CHECK_BAD_STDC_INLINE + dnl dnl support ccache dnl diff --git a/include/compiler.h b/include/compiler.h index 6e919d3d..95fd5ec4 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -214,15 +214,20 @@ size_t strnlen(const char *s, size_t maxlen); /* * Hack to support external-linkage inline functions */ -#ifdef __GNUC__ -# ifdef __GNUC_STDC_INLINE__ -# define HAVE_STDC_INLINE -# else -# define HAVE_GNU_INLINE -# endif -#elif defined(__STDC_VERSION__) -# if __STDC_VERSION__ >= 199901L -# define HAVE_STDC_INLINE +#ifndef HAVE_STDC_INLINE +# ifdef __GNUC__ +# ifdef __GNUC_STDC_INLINE__ +# define HAVE_STDC_INLINE +# else +# define HAVE_GNU_INLINE +# endif +# elif defined(__GNUC_GNU_INLINE__) +/* Some other compiler implementing only GNU inline semantics? */ +# define HAVE_GNU_INLINE +# elif defined(__STDC_VERSION__) +# if __STDC_VERSION__ >= 199901L +# define HAVE_STDC_INLINE +# endif # endif #endif @@ -230,6 +235,7 @@ size_t strnlen(const char *s, size_t maxlen); # define extern_inline inline #elif defined(HAVE_GNU_INLINE) # define extern_inline extern inline +# define inline_prototypes #else # define inline_prototypes #endif diff --git a/include/iflag.h b/include/iflag.h index e8fa6036..5280703e 100644 --- a/include/iflag.h +++ b/include/iflag.h @@ -7,7 +7,6 @@ #include #include "iflaggen.h" -#include "nasmlib.h" /* For ilog2_32() */ #define IF_GENBIT(bit) (UINT32_C(1) << (bit)) -- cgit v1.2.1