Blame confdb/ax_gcc_func_attribute.m4

Packit Service c5cf8c
# ===========================================================================
Packit Service c5cf8c
#  https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
Packit Service c5cf8c
# ===========================================================================
Packit Service c5cf8c
#
Packit Service c5cf8c
# SYNOPSIS
Packit Service c5cf8c
#
Packit Service c5cf8c
#   AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
Packit Service c5cf8c
#
Packit Service c5cf8c
# DESCRIPTION
Packit Service c5cf8c
#
Packit Service c5cf8c
#   This macro checks if the compiler supports one of GCC's function
Packit Service c5cf8c
#   attributes; many other compilers also provide function attributes with
Packit Service c5cf8c
#   the same syntax. Compiler warnings are used to detect supported
Packit Service c5cf8c
#   attributes as unsupported ones are ignored by default so quieting
Packit Service c5cf8c
#   warnings when using this macro will yield false positives.
Packit Service c5cf8c
#
Packit Service c5cf8c
#   The ATTRIBUTE parameter holds the name of the attribute to be checked.
Packit Service c5cf8c
#
Packit Service c5cf8c
#   If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.
Packit Service c5cf8c
#
Packit Service c5cf8c
#   The macro caches its result in the ax_cv_have_func_attribute_<attribute>
Packit Service c5cf8c
#   variable.
Packit Service c5cf8c
#
Packit Service c5cf8c
#   The macro currently supports the following function attributes:
Packit Service c5cf8c
#
Packit Service c5cf8c
#    alias
Packit Service c5cf8c
#    aligned
Packit Service c5cf8c
#    alloc_size
Packit Service c5cf8c
#    always_inline
Packit Service c5cf8c
#    artificial
Packit Service c5cf8c
#    cold
Packit Service c5cf8c
#    const
Packit Service c5cf8c
#    constructor
Packit Service c5cf8c
#    constructor_priority for constructor attribute with priority
Packit Service c5cf8c
#    deprecated
Packit Service c5cf8c
#    destructor
Packit Service c5cf8c
#    dllexport
Packit Service c5cf8c
#    dllimport
Packit Service c5cf8c
#    error
Packit Service c5cf8c
#    externally_visible
Packit Service c5cf8c
#    fallthrough
Packit Service c5cf8c
#    flatten
Packit Service c5cf8c
#    format
Packit Service c5cf8c
#    format_arg
Packit Service c5cf8c
#    gnu_inline
Packit Service c5cf8c
#    hot
Packit Service c5cf8c
#    ifunc
Packit Service c5cf8c
#    leaf
Packit Service c5cf8c
#    malloc
Packit Service c5cf8c
#    noclone
Packit Service c5cf8c
#    noinline
Packit Service c5cf8c
#    nonnull
Packit Service c5cf8c
#    noreturn
Packit Service c5cf8c
#    nothrow
Packit Service c5cf8c
#    optimize
Packit Service c5cf8c
#    pure
Packit Service c5cf8c
#    sentinel
Packit Service c5cf8c
#    sentinel_position
Packit Service c5cf8c
#    unused
Packit Service c5cf8c
#    used
Packit Service c5cf8c
#    visibility
Packit Service c5cf8c
#    warning
Packit Service c5cf8c
#    warn_unused_result
Packit Service c5cf8c
#    weak
Packit Service c5cf8c
#    weakref
Packit Service c5cf8c
#
Packit Service c5cf8c
#   Unsupported function attributes will be tested with a prototype
Packit Service c5cf8c
#   returning an int and not accepting any arguments and the result of the
Packit Service c5cf8c
#   check might be wrong or meaningless so use with care.
Packit Service c5cf8c
#
Packit Service c5cf8c
# LICENSE
Packit Service c5cf8c
#
Packit Service c5cf8c
#   Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
Packit Service c5cf8c
#
Packit Service c5cf8c
#   Copying and distribution of this file, with or without modification, are
Packit Service c5cf8c
#   permitted in any medium without royalty provided the copyright notice
Packit Service c5cf8c
#   and this notice are preserved.  This file is offered as-is, without any
Packit Service c5cf8c
#   warranty.
Packit Service c5cf8c
Packit Service c5cf8c
#serial 9
Packit Service c5cf8c
Packit Service c5cf8c
AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
Packit Service c5cf8c
    AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
Packit Service c5cf8c
Packit Service c5cf8c
    AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
Packit Service c5cf8c
        AC_LINK_IFELSE([AC_LANG_PROGRAM([
Packit Service c5cf8c
            m4_case([$1],
Packit Service c5cf8c
                [alias], [
Packit Service c5cf8c
                    int foo( void ) { return 0; }
Packit Service c5cf8c
                    int bar( void ) __attribute__(($1("foo")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [aligned], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1(32)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [alloc_size], [
Packit Service c5cf8c
                    void *foo(int a) __attribute__(($1(1)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [always_inline], [
Packit Service c5cf8c
                    inline __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [artificial], [
Packit Service c5cf8c
                    inline __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [cold], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [const], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [constructor_priority], [
Packit Service c5cf8c
                    int foo( void ) __attribute__((__constructor__(65535/2)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [constructor], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [deprecated], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1("")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [destructor], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [dllexport], [
Packit Service c5cf8c
                    __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [dllimport], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [error], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1("")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [externally_visible], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [fallthrough], [
Packit Service c5cf8c
                    int foo( void ) {switch (0) { case 1: __attribute__(($1)); case 2: break ; }};
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [flatten], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [format], [
Packit Service c5cf8c
                    int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [format_arg], [
Packit Service c5cf8c
                    char *foo(const char *p) __attribute__(($1(1)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [gnu_inline], [
Packit Service c5cf8c
                    inline __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [hot], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [ifunc], [
Packit Service c5cf8c
                    int my_foo( void ) { return 0; }
Packit Service c5cf8c
                    static int (*resolve_foo(void))(void) { return my_foo; }
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1("resolve_foo")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [leaf], [
Packit Service c5cf8c
                    __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [malloc], [
Packit Service c5cf8c
                    void *foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [noclone], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [noinline], [
Packit Service c5cf8c
                    __attribute__(($1)) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [nonnull], [
Packit Service c5cf8c
                    int foo(char *p) __attribute__(($1(1)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [noreturn], [
Packit Service c5cf8c
                    void foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [nothrow], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [optimize], [
Packit Service c5cf8c
                    __attribute__(($1(3))) int foo( void ) { return 0; }
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [pure], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [sentinel], [
Packit Service c5cf8c
                    int foo(void *p, ...) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [sentinel_position], [
Packit Service c5cf8c
                    int foo(void *p, ...) __attribute__(($1(1)));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [returns_nonnull], [
Packit Service c5cf8c
                    void *foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [unused], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [used], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [visibility], [
Packit Service c5cf8c
                    int foo_def( void ) __attribute__(($1("default")));
Packit Service c5cf8c
                    int foo_hid( void ) __attribute__(($1("hidden")));
Packit Service c5cf8c
                    int foo_int( void ) __attribute__(($1("internal")));
Packit Service c5cf8c
                    int foo_pro( void ) __attribute__(($1("protected")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [warning], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1("")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [warn_unused_result], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [weak], [
Packit Service c5cf8c
                    int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [weakref], [
Packit Service c5cf8c
                    static int foo( void ) { return 0; }
Packit Service c5cf8c
                    static int bar( void ) __attribute__(($1("foo")));
Packit Service c5cf8c
                ],
Packit Service c5cf8c
                [
Packit Service c5cf8c
                 m4_warn([syntax], [Unsupported attribute $1, the test may fail])
Packit Service c5cf8c
                 int foo( void ) __attribute__(($1));
Packit Service c5cf8c
                ]
Packit Service c5cf8c
            )], [])
Packit Service c5cf8c
            ],
Packit Service c5cf8c
            dnl GCC doesn't exit with an error if an unknown attribute is
Packit Service c5cf8c
            dnl provided but only outputs a warning, so accept the attribute
Packit Service c5cf8c
            dnl only if no warning were issued.
Packit Service c5cf8c
            [AS_IF([test -s conftest.err],
Packit Service c5cf8c
                [AS_VAR_SET([ac_var], [no])],
Packit Service c5cf8c
                [AS_VAR_SET([ac_var], [yes])])],
Packit Service c5cf8c
            [AS_VAR_SET([ac_var], [no])])
Packit Service c5cf8c
    ])
Packit Service c5cf8c
Packit Service c5cf8c
    AS_IF([test yes = AS_VAR_GET([ac_var])],
Packit Service c5cf8c
        [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
Packit Service c5cf8c
            [Define to 1 if the system has the `$1' function attribute])], [])
Packit Service c5cf8c
Packit Service c5cf8c
    AS_VAR_POPDEF([ac_var])
Packit Service c5cf8c
])