1 # ===========================================================================
2 # https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
3 # ===========================================================================
7 # AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
11 # This macro checks if the compiler supports one of GCC's function
12 # attributes; many other compilers also provide function attributes with
13 # the same syntax. Compiler warnings are used to detect supported
14 # attributes as unsupported ones are ignored by default so quieting
15 # warnings when using this macro will yield false positives.
17 # The ATTRIBUTE parameter holds the name of the attribute to be checked.
19 # If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.
21 # The macro caches its result in the ax_cv_have_func_attribute_<attribute>
24 # The macro currently supports the following function attributes:
34 # constructor_priority for constructor attribute with priority
68 # Unsupported function attributes will be tested with a prototype
69 # returning an int and not accepting any arguments and the result of the
70 # check might be wrong or meaningless so use with care.
74 # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
76 # Copying and distribution of this file, with or without modification, are
77 # permitted in any medium without royalty provided the copyright notice
78 # and this notice are preserved. This file is offered as-is, without any
83 AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
84 AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
86 AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
87 AC_LINK_IFELSE([AC_LANG_PROGRAM([
90 int foo( void ) { return 0; }
91 int bar( void ) __attribute__(($1("foo")));
94 int foo( void ) __attribute__(($1(32)));
97 void *foo(int a) __attribute__(($1(1)));
100 inline __attribute__(($1)) int foo( void ) { return 0; }
103 inline __attribute__(($1)) int foo( void ) { return 0; }
106 int foo( void ) __attribute__(($1));
109 int foo( void ) __attribute__(($1));
111 [constructor_priority], [
112 int foo( void ) __attribute__((__constructor__(65535/2)));
115 int foo( void ) __attribute__(($1));
118 int foo( void ) __attribute__(($1("")));
121 int foo( void ) __attribute__(($1));
124 __attribute__(($1)) int foo( void ) { return 0; }
127 int foo( void ) __attribute__(($1));
130 int foo( void ) __attribute__(($1("")));
132 [externally_visible], [
133 int foo( void ) __attribute__(($1));
136 void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }};
139 int foo( void ) __attribute__(($1));
142 int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
145 int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2)));
148 char *foo(const char *p) __attribute__(($1(1)));
151 inline __attribute__(($1)) int foo( void ) { return 0; }
154 int foo( void ) __attribute__(($1));
157 int my_foo( void ) { return 0; }
158 static int (*resolve_foo(void))(void) { return my_foo; }
159 int foo( void ) __attribute__(($1("resolve_foo")));
162 __attribute__(($1)) int foo( void ) { return 0; }
165 void *foo( void ) __attribute__(($1));
168 int foo( void ) __attribute__(($1));
171 __attribute__(($1)) int foo( void ) { return 0; }
174 int foo(char *p) __attribute__(($1(1)));
177 void foo( void ) __attribute__(($1));
180 int foo( void ) __attribute__(($1));
183 __attribute__(($1(3))) int foo( void ) { return 0; }
186 int foo( void ) __attribute__(($1));
189 int foo(void *p, ...) __attribute__(($1));
191 [sentinel_position], [
192 int foo(void *p, ...) __attribute__(($1(1)));
195 void *foo( void ) __attribute__(($1));
198 int foo( void ) __attribute__(($1));
201 int foo( void ) __attribute__(($1));
204 int foo_def( void ) __attribute__(($1("default")));
205 int foo_hid( void ) __attribute__(($1("hidden")));
206 int foo_int( void ) __attribute__(($1("internal")));
207 int foo_pro( void ) __attribute__(($1("protected")));
210 int foo( void ) __attribute__(($1("")));
212 [warn_unused_result], [
213 int foo( void ) __attribute__(($1));
216 int foo( void ) __attribute__(($1));
219 static int foo( void ) { return 0; }
220 static int bar( void ) __attribute__(($1("foo")));
223 m4_warn([syntax], [Unsupported attribute $1, the test may fail])
224 int foo( void ) __attribute__(($1));
228 dnl GCC doesn't exit with an error if an unknown attribute is
229 dnl provided but only outputs a warning, so accept the attribute
230 dnl only if no warning were issued.
231 [AS_IF([grep -- -Wattributes conftest.err],
232 [AS_VAR_SET([ac_var], [no])],
233 [AS_VAR_SET([ac_var], [yes])])],
234 [AS_VAR_SET([ac_var], [no])])
237 AS_IF([test yes = AS_VAR_GET([ac_var])],
238 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
239 [Define to 1 if the system has the `$1' function attribute])], [])
241 AS_VAR_POPDEF([ac_var])