1 # ===========================================================================
2 # http://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:
65 # Unsuppored function attributes will be tested with a prototype returning
66 # an int and not accepting any arguments and the result of the check might
67 # be wrong or meaningless so use with care.
71 # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
73 # Copying and distribution of this file, with or without modification, are
74 # permitted in any medium without royalty provided the copyright notice
75 # and this notice are preserved. This file is offered as-is, without any
81 # Added support for returns_nonnull attribute
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));
112 int foo( void ) __attribute__(($1));
115 int foo( void ) __attribute__(($1("")));
118 int foo( void ) __attribute__(($1));
121 __attribute__(($1)) int foo( void ) { return 0; }
124 int foo( void ) __attribute__(($1));
127 int foo( void ) __attribute__(($1("")));
129 [externally_visible], [
130 int foo( void ) __attribute__(($1));
133 int foo( void ) __attribute__(($1));
136 int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
139 char *foo(const char *p) __attribute__(($1(1)));
142 inline __attribute__(($1)) int foo( void ) { return 0; }
145 int foo( void ) __attribute__(($1));
148 int my_foo( void ) { return 0; }
149 static int (*resolve_foo(void))(void) { return my_foo; }
150 int foo( void ) __attribute__(($1("resolve_foo")));
153 __attribute__(($1)) int foo( void ) { return 0; }
156 void *foo( void ) __attribute__(($1));
159 int foo( void ) __attribute__(($1));
162 __attribute__(($1)) int foo( void ) { return 0; }
165 int foo(char *p) __attribute__(($1(1)));
168 void foo( void ) __attribute__(($1));
171 int foo( void ) __attribute__(($1));
174 __attribute__(($1(3))) int foo( void ) { return 0; }
177 struct __attribute__(($1)) foo { int bar; };
180 int foo( void ) __attribute__(($1));
183 int *foo( void ) __attribute__(($1));
186 int foo( void ) __attribute__(($1));
189 int foo( void ) __attribute__(($1));
192 int foo_def( void ) __attribute__(($1("default")));
193 int foo_hid( void ) __attribute__(($1("hidden")));
194 int foo_int( void ) __attribute__(($1("internal")));
195 int foo_pro( void ) __attribute__(($1("protected")));
198 int foo( void ) __attribute__(($1("")));
200 [warn_unused_result], [
201 int foo( void ) __attribute__(($1));
204 int foo( void ) __attribute__(($1));
207 static int foo( void ) { return 0; }
208 static int bar( void ) __attribute__(($1("foo")));
211 m4_warn([syntax], [Unsupported attribute $1, the test may fail])
212 int foo( void ) __attribute__(($1));
216 dnl GCC doesn't exit with an error if an unknown attribute is
217 dnl provided but only outputs a warning, so accept the attribute
218 dnl only if no warning were issued.
219 [AS_IF([test -s conftest.err],
220 [AS_VAR_SET([ac_var], [no])],
221 [AS_VAR_SET([ac_var], [yes])])],
222 [AS_VAR_SET([ac_var], [no])])
225 AS_IF([test yes = AS_VAR_GET([ac_var])],
226 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
227 [Define to 1 if the system has the `$1' function attribute])], [])
229 AS_VAR_POPDEF([ac_var])