summaryrefslogtreecommitdiff
path: root/config/c-compiler.m4
diff options
context:
space:
mode:
Diffstat (limited to 'config/c-compiler.m4')
-rw-r--r--config/c-compiler.m4141
1 files changed, 137 insertions, 4 deletions
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 9398ca6c47..802f5539d3 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -19,8 +19,19 @@ fi])# PGAC_C_SIGNED
# PGAC_C_INLINE
# -------------
-# Check if the C compiler understands inline functions.
-# Defines: inline, USE_INLINE
+# Check if the C compiler understands inline functions without being
+# noisy about unused static inline functions. Some older compilers
+# understand inline functions (as tested by AC_C_INLINE) but warn about
+# them if they aren't used in a translation unit.
+#
+# This test used to just define an inline function, but some compilers
+# (notably clang) got too smart and now warn about unused static
+# inline functions when defined inside a .c file, but not when defined
+# in an included header. Since the latter is what we want to use, test
+# to see if the warning appears when the function is in a header file.
+# Not pretty, but it works.
+#
+# Defines: inline, PG_USE_INLINE
AC_DEFUN([PGAC_C_INLINE],
[AC_C_INLINE
AC_CACHE_CHECK([for quiet inline (no complaint if unreferenced)], pgac_cv_c_inline_quietly,
@@ -28,12 +39,12 @@ AC_CACHE_CHECK([for quiet inline (no complaint if unreferenced)], pgac_cv_c_inli
if test "$ac_cv_c_inline" != no; then
pgac_c_inline_save_werror=$ac_c_werror_flag
ac_c_werror_flag=yes
- AC_LINK_IFELSE([AC_LANG_PROGRAM([static inline int fun () {return 0;}],[])],
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "$srcdir/config/test_quiet_include.h"],[])],
[pgac_cv_c_inline_quietly=yes])
ac_c_werror_flag=$pgac_c_inline_save_werror
fi])
if test "$pgac_cv_c_inline_quietly" != no; then
- AC_DEFINE_UNQUOTED([USE_INLINE], 1,
+ AC_DEFINE_UNQUOTED([PG_USE_INLINE], 1,
[Define to 1 if "static inline" works without unwanted warnings from ]
[compilations where static inline functions are defined but not called.])
fi
@@ -121,6 +132,103 @@ fi])# PGAC_C_FUNCNAME_SUPPORT
+# PGAC_C_STATIC_ASSERT
+# --------------------
+# Check if the C compiler understands _Static_assert(),
+# and define HAVE__STATIC_ASSERT if so.
+#
+# We actually check the syntax ({ _Static_assert(...) }), because we need
+# gcc-style compound expressions to be able to wrap the thing into macros.
+AC_DEFUN([PGAC_C_STATIC_ASSERT],
+[AC_CACHE_CHECK(for _Static_assert, pgac_cv__static_assert,
+[AC_TRY_LINK([],
+[({ _Static_assert(1, "foo"); })],
+[pgac_cv__static_assert=yes],
+[pgac_cv__static_assert=no])])
+if test x"$pgac_cv__static_assert" = xyes ; then
+AC_DEFINE(HAVE__STATIC_ASSERT, 1,
+ [Define to 1 if your compiler understands _Static_assert.])
+fi])# PGAC_C_STATIC_ASSERT
+
+
+
+# PGAC_C_TYPES_COMPATIBLE
+# -----------------------
+# Check if the C compiler understands __builtin_types_compatible_p,
+# and define HAVE__BUILTIN_TYPES_COMPATIBLE_P if so.
+#
+# We check usage with __typeof__, though it's unlikely any compiler would
+# have the former and not the latter.
+AC_DEFUN([PGAC_C_TYPES_COMPATIBLE],
+[AC_CACHE_CHECK(for __builtin_types_compatible_p, pgac_cv__types_compatible,
+[AC_TRY_COMPILE([],
+[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ],
+[pgac_cv__types_compatible=yes],
+[pgac_cv__types_compatible=no])])
+if test x"$pgac_cv__types_compatible" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
+ [Define to 1 if your compiler understands __builtin_types_compatible_p.])
+fi])# PGAC_C_TYPES_COMPATIBLE
+
+
+
+# PGAC_C_BUILTIN_CONSTANT_P
+# -------------------------
+# Check if the C compiler understands __builtin_constant_p(),
+# and define HAVE__BUILTIN_CONSTANT_P if so.
+AC_DEFUN([PGAC_C_BUILTIN_CONSTANT_P],
+[AC_CACHE_CHECK(for __builtin_constant_p, pgac_cv__builtin_constant_p,
+[AC_TRY_COMPILE([static int x; static int y[__builtin_constant_p(x) ? x : 1];],
+[],
+[pgac_cv__builtin_constant_p=yes],
+[pgac_cv__builtin_constant_p=no])])
+if test x"$pgac_cv__builtin_constant_p" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_CONSTANT_P, 1,
+ [Define to 1 if your compiler understands __builtin_constant_p.])
+fi])# PGAC_C_BUILTIN_CONSTANT_P
+
+
+
+# PGAC_C_BUILTIN_UNREACHABLE
+# --------------------------
+# Check if the C compiler understands __builtin_unreachable(),
+# and define HAVE__BUILTIN_UNREACHABLE if so.
+#
+# NB: Don't get the idea of putting a for(;;); or such before the
+# __builtin_unreachable() call. Some compilers would remove it before linking
+# and only a warning instead of an error would be produced.
+AC_DEFUN([PGAC_C_BUILTIN_UNREACHABLE],
+[AC_CACHE_CHECK(for __builtin_unreachable, pgac_cv__builtin_unreachable,
+[AC_TRY_LINK([],
+[__builtin_unreachable();],
+[pgac_cv__builtin_unreachable=yes],
+[pgac_cv__builtin_unreachable=no])])
+if test x"$pgac_cv__builtin_unreachable" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_UNREACHABLE, 1,
+ [Define to 1 if your compiler understands __builtin_unreachable.])
+fi])# PGAC_C_BUILTIN_UNREACHABLE
+
+
+
+# PGAC_C_VA_ARGS
+# --------------
+# Check if the C compiler understands C99-style variadic macros,
+# and define HAVE__VA_ARGS if so.
+AC_DEFUN([PGAC_C_VA_ARGS],
+[AC_CACHE_CHECK(for __VA_ARGS__, pgac_cv__va_args,
+[AC_TRY_COMPILE([#include <stdio.h>],
+[#define debug(...) fprintf(stderr, __VA_ARGS__)
+debug("%s", "blarg");
+],
+[pgac_cv__va_args=yes],
+[pgac_cv__va_args=no])])
+if test x"$pgac_cv__va_args" = xyes ; then
+AC_DEFINE(HAVE__VA_ARGS, 1,
+ [Define to 1 if your compiler understands __VA_ARGS__ in macros.])
+fi])# PGAC_C_VA_ARGS
+
+
+
# PGAC_PROG_CC_CFLAGS_OPT
# -----------------------
# Given a string, check if the compiler supports the string as a
@@ -145,6 +253,31 @@ undefine([Ac_cachevar])dnl
+# PGAC_PROG_CC_VAR_OPT
+# -----------------------
+# Given a variable name and a string, check if the compiler supports
+# the string as a command-line option. If it does, add the string to
+# the given variable.
+AC_DEFUN([PGAC_PROG_CC_VAR_OPT],
+[define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$2])])dnl
+AC_CACHE_CHECK([whether $CC supports $2], [Ac_cachevar],
+[pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS $2"
+ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ [Ac_cachevar=yes],
+ [Ac_cachevar=no])
+ac_c_werror_flag=$ac_save_c_werror_flag
+CFLAGS="$pgac_save_CFLAGS"])
+if test x"$Ac_cachevar" = x"yes"; then
+ $1="${$1} $2"
+fi
+undefine([Ac_cachevar])dnl
+])# PGAC_PROG_CC_CFLAGS_OPT
+
+
+
# PGAC_PROG_CC_LDFLAGS_OPT
# ------------------------
# Given a string, check if the compiler supports the string as a