1 /* gcc-function-attribtues.h -- GCC-specific function attributes
2
3 Copyright (C) 2016-2022 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 /*
20 Be aware that some function attributes do not work with function
21 pointers. See
22 https://lists.gnu.org/r/bug-gnulib/2011-04/msg00007.html
23 for details.
24 */
25 #ifndef _GCC_FUNCTION_ATTRIBUTES_H
26 # define _GCC_FUNCTION_ATTRIBUTES_H
27
28 # ifndef __GNUC_PREREQ
29 # if defined __GNUC__ && defined __GNUC_MINOR__
30 # define __GNUC_PREREQ(maj, min) \
31 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
32 # else
33 # define __GNUC_PREREQ(maj, min) 0
34 # endif
35 # endif
36
37 /*
38 The following attributes are currently (GCC-4.4.5) defined for
39 functions on all targets. Where this file provides a macro
40 for using it, the macro name is given in the second column.
41
42 Attribute Macro (if implemented in this file)
43 -------------------------------------------------------------------------------
44 alias
45 aligned
46 alloc_size _GL_ATTRIBUTE_ALLOC_SIZE(arg_num)
47 always_inline
48 artificial
49 cold
50 const
51 constructor
52 deprecated _GL_ATTRIBUTE_DEPRECATED
53 destructor
54 error
55 externally_visible
56 flatten
57 format _GL_ATTRIBUTE_FORMAT(spec)
58 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(fmt,firstarg)
59 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(fmt,firstarg)
60 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(fmt,firstarg)
61 _GL_ATTRIBUTE_FORMAT_SCANF(fmt,firstarg)
62 format_arg
63 gnu_inline
64 hot
65 malloc _GL_ATTRIBUTE_MALLOC
66 no_instrument_function
67 noinline
68 nonnull _GL_ATTRIBUTE_NONNULL(args)
69 _GL_ARG_NONNULL(args)
70 noreturn _GL_ATTRIBUTE_NORETURN
71 nothrow
72 pure _GL_ATTRIBUTE_PURE
73 returns_twice
74 section
75 sentinel _GL_ATTRIBUTE_SENTINEL
76 unused
77 used
78 warn_unused_result _GL_ATTRIBUTE_WUR
79 warning
80 weak
81 */
82
83 /*
84 Attributes used in gnulib, but which appear to be platform-specific
85 regparm
86 stdcall
87 */
88
89 /*
90 Attributes used in gnulib with special arguments
91 Macro Args
92 visibility "default"
93 */
94
95 /*
96 The __attribute__ feature is available in gcc versions 2.5 and later.
97 The underscored __format__ spelling of the attribute names requires 2.6.4 (we check for 2.7).
98 */
99
100
101 # ifndef _GL_ATTRIBUTE_ALLOC_SIZE
102 # if __GNUC_PREREQ(4,3)
103 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
104 # else
105 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) /* unsupported */
106 # endif
107 # endif
108
109 # ifndef _GL_ATTRIBUTE_DEPRECATED
110 # if __GNUC_PREREQ(3,1)
111 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
112 # else
113 # define _GL_ATTRIBUTE_DEPRECATED /* empty */
114 # endif
115 # endif
116
117 # ifndef _GL_ATTRIBUTE_FORMAT
118 # if __GNUC_PREREQ(2,7)
119 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
120 # else
121 # define _GL_ATTRIBUTE_FORMAT(spec) /* unsupported */
122 # endif
123 # endif
124
125 # ifndef _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM
126 # if __GNUC_PREREQ(2,7)
127 # define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \
128 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
129 # else
130 # define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(spec) /* unsupported */
131 # endif
132 # endif
133
134 # ifndef _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD
135 # if __GNUC_PREREQ(2,7)
136 # if __GNUC_PREREQ(4,4)
137 # define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \
138 _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument))
139 # else
140 # define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \
141 _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument))
142 # endif
143 # else
144 # define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(spec) /* unsupported */
145 # endif
146 # endif
147
148 # ifndef _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM
149 # if __GNUC_PREREQ(2,7)
150 # define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \
151 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
152 # else
153 # define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(spec) /* unsupported */
154 # endif
155 # endif
156
157 # ifndef _GL_ATTRIBUTE_FORMAT_SCANF
158 # if __GNUC_PREREQ(2,7)
159 # if __GNUC_PREREQ(4,4)
160 # define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
161 _GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, first_argument))
162 # else
163 # define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
164 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
165 # endif
166 # else
167 # define _GL_ATTRIBUTE_FORMAT_SCANF(spec) /* unsupported */
168 # endif
169 # endif
170
171 # ifndef _GL_ATTRIBUTE_MALLOC
172 # if __GNUC_PREREQ(3,0)
173 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
174 # else
175 # define _GL_ATTRIBUTE_MALLOC /* unsupported */
176 # endif
177 # endif
178
179
180 # ifndef _GL_ATTRIBUTE_NONNULL
181 # if __GNUC_PREREQ(3,3)
182 # define _GL_ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
183 # else
184 # define _GL_ATTRIBUTE_NONNULL(m) /* unsupported */
185 # endif
186 # endif
187 # ifndef _GL_ARG_NONNULL
188 /* alternative spelling used in gnulib's stdio.h */
189 # define _GL_ARG_NONNULL(m) _GL_ATTRIBUTE_NONNULL(m)
190 # endif
191
192
193 # ifndef _GL_ATTRIBUTE_NORETURN
194 # if __GNUC_PREREQ(2,8)
195 # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
196 # else
197 # define _GL_ATTRIBUTE_NORETURN /* unsupported */
198 # endif
199 # endif
200
201 # ifndef _GL_ATTRIBUTE_PURE
202 # if __GNUC_PREREQ(2,96)
203 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
204 # else
205 # define _GL_ATTRIBUTE_PURE /* unsupported */
206 # endif
207 # endif
208
209 # ifndef _GL_ATTRIBUTE_SENTINEL
210 # if __GNUC_PREREQ(4,0)
211 /* gnulib uses the __attribute__((__sentinel__)) variant, for which the
212 argument number 0 is assumed. Arguments are counted backwards, the last
213 being 0.
214 */
215 # define _GL_ATTRIBUTE_SENTINEL(backward_arg_num) __attribute__ ((__sentinel__(backward_arg_num)))
216 # else
217 # define _GL_ATTRIBUTE_SENTINEL(backward_arg_num) /* unsupported */
218 # endif
219 # endif
220
221 # ifndef _GL_ATTRIBUTE_WUR
222 # if __GNUC_PREREQ(3,4)
223 # define _GL_ATTRIBUTE_WUR __attribute__ ((__warn__unused_result__))
224 # else
225 # define _GL_ATTRIBUTE_WUR /* unsupported */
226 # endif
227 # endif
228 # ifndef _GL_ATTRIBUTE_RETURN_CHECK
229 /* gnulib is inconsistent in which macro it uses; support both for now. */
230 # define _GL_ATTRIBUTE_RETURN_CHECK _GL_ATTRIBUTE_WUR
231 # endif
232
233 #endif /* _GCC_FUNCTION_ATTRIBUTES_H */