Debian Codegraph @

build-aux/m4/ax_gcc_func_attribute.m4

raw
1 # ===========================================================================
2 # https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
8 #
9 # DESCRIPTION
10 #
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.
16 #
17 # The ATTRIBUTE parameter holds the name of the attribute to be checked.
18 #
19 # If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.
20 #
21 # The macro caches its result in the ax_cv_have_func_attribute_<attribute>
22 # variable.
23 #
24 # The macro currently supports the following function attributes:
25 #
26 # alias
27 # aligned
28 # alloc_size
29 # always_inline
30 # artificial
31 # cold
32 # const
33 # constructor
34 # constructor_priority for constructor attribute with priority
35 # deprecated
36 # destructor
37 # dllexport
38 # dllimport
39 # error
40 # externally_visible
41 # fallthrough
42 # flatten
43 # format
44 # format_arg
45 # gnu_format
46 # gnu_inline
47 # hot
48 # ifunc
49 # leaf
50 # malloc
51 # noclone
52 # noinline
53 # nonnull
54 # noreturn
55 # nothrow
56 # optimize
57 # pure
58 # sentinel
59 # sentinel_position
60 # unused
61 # used
62 # visibility
63 # warning
64 # warn_unused_result
65 # weak
66 # weakref
67 # symver
68 #
69 # Unsupported function attributes will be tested with a prototype
70 # returning an int and not accepting any arguments and the result of the
71 # check might be wrong or meaningless so use with care.
72 #
73 # LICENSE
74 #
75 # Copyright (c) 2013 Gabriele Svelto <[email protected]>
76 #
77 # Copying and distribution of this file, with or without modification, are
78 # permitted in any medium without royalty provided the copyright notice
79 # and this notice are preserved. This file is offered as-is, without any
80 # warranty.
81
82 #serial 13
83
84 AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
85 AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
86
87 AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
88 AC_LINK_IFELSE([AC_LANG_PROGRAM([
89 m4_case([$1],
90 [alias], [
91 int foo( void ) { return 0; }
92 int bar( void ) __attribute__(($1("foo")));
93 ],
94 [aligned], [
95 int foo( void ) __attribute__(($1(32)));
96 ],
97 [alloc_size], [
98 void *foo(int a) __attribute__(($1(1)));
99 ],
100 [always_inline], [
101 inline __attribute__(($1)) int foo( void ) { return 0; }
102 ],
103 [artificial], [
104 inline __attribute__(($1)) int foo( void ) { return 0; }
105 ],
106 [cold], [
107 int foo( void ) __attribute__(($1));
108 ],
109 [const], [
110 int foo( void ) __attribute__(($1));
111 ],
112 [constructor_priority], [
113 int foo( void ) __attribute__((__constructor__(65535/2)));
114 ],
115 [constructor], [
116 int foo( void ) __attribute__(($1));
117 ],
118 [deprecated], [
119 int foo( void ) __attribute__(($1("")));
120 ],
121 [destructor], [
122 int foo( void ) __attribute__(($1));
123 ],
124 [dllexport], [
125 __attribute__(($1)) int foo( void ) { return 0; }
126 ],
127 [dllimport], [
128 int foo( void ) __attribute__(($1));
129 ],
130 [error], [
131 int foo( void ) __attribute__(($1("")));
132 ],
133 [externally_visible], [
134 int foo( void ) __attribute__(($1));
135 ],
136 [fallthrough], [
137 void foo( int x ) {switch (x) { case 1: __attribute__(($1)); case 2: break ; }};
138 ],
139 [flatten], [
140 int foo( void ) __attribute__(($1));
141 ],
142 [format], [
143 int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
144 ],
145 [gnu_format], [
146 int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2)));
147 ],
148 [format_arg], [
149 char *foo(const char *p) __attribute__(($1(1)));
150 ],
151 [gnu_inline], [
152 inline __attribute__(($1)) int foo( void ) { return 0; }
153 ],
154 [hot], [
155 int foo( void ) __attribute__(($1));
156 ],
157 [ifunc], [
158 int my_foo( void ) { return 0; }
159 static int (*resolve_foo(void))(void) { return my_foo; }
160 int foo( void ) __attribute__(($1("resolve_foo")));
161 ],
162 [leaf], [
163 __attribute__(($1)) int foo( void ) { return 0; }
164 ],
165 [malloc], [
166 void *foo( void ) __attribute__(($1));
167 ],
168 [noclone], [
169 int foo( void ) __attribute__(($1));
170 ],
171 [noinline], [
172 __attribute__(($1)) int foo( void ) { return 0; }
173 ],
174 [nonnull], [
175 int foo(char *p) __attribute__(($1(1)));
176 ],
177 [noreturn], [
178 void foo( void ) __attribute__(($1));
179 ],
180 [nothrow], [
181 int foo( void ) __attribute__(($1));
182 ],
183 [optimize], [
184 __attribute__(($1(3))) int foo( void ) { return 0; }
185 ],
186 [pure], [
187 int foo( void ) __attribute__(($1));
188 ],
189 [sentinel], [
190 int foo(void *p, ...) __attribute__(($1));
191 ],
192 [sentinel_position], [
193 int foo(void *p, ...) __attribute__(($1(1)));
194 ],
195 [returns_nonnull], [
196 void *foo( void ) __attribute__(($1));
197 ],
198 [unused], [
199 int foo( void ) __attribute__(($1));
200 ],
201 [used], [
202 int foo( void ) __attribute__(($1));
203 ],
204 [visibility], [
205 int foo_def( void ) __attribute__(($1("default")));
206 int foo_hid( void ) __attribute__(($1("hidden")));
207 int foo_int( void ) __attribute__(($1("internal")));
208 int foo_pro( void ) __attribute__(($1("protected")));
209 ],
210 [warning], [
211 int foo( void ) __attribute__(($1("")));
212 ],
213 [warn_unused_result], [
214 int foo( void ) __attribute__(($1));
215 ],
216 [weak], [
217 int foo( void ) __attribute__(($1));
218 ],
219 [weakref], [
220 static int foo( void ) { return 0; }
221 static int bar( void ) __attribute__(($1("foo")));
222 ],
223 [symver], [
224 __attribute__(($1("[email protected]"))) void bar( void ) {}
225 ],
226 [
227 m4_warn([syntax], [Unsupported attribute $1, the test may fail])
228 int foo( void ) __attribute__(($1));
229 ]
230 )], [])
231 ],
232 dnl GCC doesn't exit with an error if an unknown attribute is
233 dnl provided but only outputs a warning, so accept the attribute
234 dnl only if no warning were issued.
235 [AS_IF([grep -q -e -Wattributes -e -Wunknown-attributes -e error -e warning conftest.err],
236 [AS_VAR_SET([ac_var], [no])],
237 [AS_VAR_SET([ac_var], [yes])])],
238 [AS_VAR_SET([ac_var], [no])])
239 ])
240
241 AS_IF([test yes = AS_VAR_GET([ac_var])],
242 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
243 [Define to 1 if the system has the `$1' function attribute])], [])
244
245 AS_VAR_POPDEF([ac_var])
246 ])