1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_gcc_var_attribute.html
3 # ===========================================================================
7 # AX_GCC_VAR_ATTRIBUTE(ATTRIBUTE)
11 # This macro checks if the compiler supports one of GCC's variable
12 # attributes; many other compilers also provide variable 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_VAR_ATTRIBUTE_<ATTRIBUTE>.
21 # The macro caches its result in the ax_cv_have_var_attribute_<attribute>
24 # The macro currently supports the following variable attributes:
42 # Unsuppored variable attributes will be tested against a global integer
43 # variable and without any arguments given to the attribute itself; the
44 # result of this check might be wrong or meaningless so use with care.
48 # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
50 # Copying and distribution of this file, with or without modification, are
51 # permitted in any medium without royalty provided the copyright notice
52 # and this notice are preserved. This file is offered as-is, without any
57 AC_DEFUN([AX_GCC_VAR_ATTRIBUTE], [
58 AS_VAR_PUSHDEF([ac_var], [ax_cv_have_var_attribute_$1])
60 AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
61 AC_LINK_IFELSE([AC_LANG_PROGRAM([
64 int foo __attribute__(($1(32)));
67 int bar(int *t) { return *t; };
70 int foo __attribute__(($1));
73 int foo __attribute__(($1));
76 int foo __attribute__(($1)) = 0;
79 long foo __attribute__(($1(word)));
83 int baz __attribute__(($1));
87 __thread int bar1 __attribute__(($1("global-dynamic")));
88 __thread int bar2 __attribute__(($1("local-dynamic")));
89 __thread int bar3 __attribute__(($1("initial-exec")));
90 __thread int bar4 __attribute__(($1("local-exec")));
93 int foo __attribute__(($1));
96 int foo __attribute__(($1));
99 int foo __attribute__(($1(16)));
102 int foo __attribute__(($1));
105 int foo __attribute__(($1));
108 int foo __attribute__(($1));
111 struct bar { bar() {} ~bar() {} };
112 bar b __attribute__(($1(65535/2)));
115 m4_warn([syntax], [Unsupported attribute $1, the test may fail])
116 int foo __attribute__(($1));
121 int foo __attribute__(($1(bar))) = 0;
127 dnl GCC doesn't exit with an error if an unknown attribute is
128 dnl provided but only outputs a warning, so accept the attribute
129 dnl only if no warning were issued.
130 [AS_IF([test -s conftest.err],
131 [AS_VAR_SET([ac_var], [no])],
132 [AS_VAR_SET([ac_var], [yes])])],
133 [AS_VAR_SET([ac_var], [no])])
136 AS_IF([test yes = AS_VAR_GET([ac_var])],
137 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_VAR_ATTRIBUTE_$1), 1,
138 [Define to 1 if the system has the `$1' variable attribute])], [])
140 AS_VAR_POPDEF([ac_var])