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 <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2018-02-20 12:34:17 -08:00
parent 53371ddd17
commit 99d45c850e
4 changed files with 49 additions and 10 deletions

27
aclocal.m4 vendored
View file

@ -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])])])

View file

@ -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

View file

@ -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

View file

@ -7,7 +7,6 @@
#include <string.h>
#include "iflaggen.h"
#include "nasmlib.h" /* For ilog2_32() */
#define IF_GENBIT(bit) (UINT32_C(1) << (bit))