Blame m4/ax_gcc_func_attribute.m4

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