Implement #pragma GCC warning/error
[official-gcc.git] / gcc / builtin-attrs.def
blob0c331fb4caaf2d381d0ec11f8450026d1b01375c
1 /* Copyright (C) 2001, 2002, 2004, 2005, 2007, 2010
2 Free Software Foundation, Inc.
3 Contributed by Joseph Myers <jsm28@cam.ac.uk>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This header provides a declarative way of describing the attributes
22 that are applied to some functions by default.
24 Before including this header, you must define the following macros.
25 In each case where there is an ENUM, it is an identifier used to
26 reference the tree in subsequent definitions.
28 DEF_ATTR_NULL_TREE (ENUM)
30 Constructs a NULL_TREE.
32 DEF_ATTR_INT (ENUM, VALUE)
34 Constructs an INTEGER_CST with value VALUE (an integer representable
35 in HOST_WIDE_INT).
37 DEF_ATTR_IDENT (ENUM, STRING)
39 Constructs an IDENTIFIER_NODE for STRING.
41 DEF_ATTR_TREE_LIST (ENUM, PURPOSE, VALUE, CHAIN)
43 Constructs a TREE_LIST with given PURPOSE, VALUE and CHAIN (given
44 as previous ENUM names). */
46 DEF_ATTR_NULL_TREE (ATTR_NULL)
48 /* Construct a tree for a given integer and a list containing it. */
49 #define DEF_ATTR_FOR_INT(VALUE) \
50 DEF_ATTR_INT (ATTR_##VALUE, VALUE) \
51 DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE, ATTR_NULL, \
52 ATTR_##VALUE, ATTR_NULL)
53 DEF_ATTR_FOR_INT (0)
54 DEF_ATTR_FOR_INT (1)
55 DEF_ATTR_FOR_INT (2)
56 DEF_ATTR_FOR_INT (3)
57 DEF_ATTR_FOR_INT (4)
58 DEF_ATTR_FOR_INT (5)
59 DEF_ATTR_FOR_INT (6)
60 #undef DEF_ATTR_FOR_INT
62 /* Construct a tree for a given string and a list containing it. */
63 #define DEF_ATTR_FOR_STRING(ENUM, VALUE) \
64 DEF_ATTR_STRING (ATTR_##ENUM, VALUE) \
65 DEF_ATTR_TREE_LIST (ATTR_LIST_##ENUM, ATTR_NULL, \
66 ATTR_##ENUM, ATTR_NULL)
67 DEF_ATTR_FOR_STRING (STR1, "1")
68 #undef DEF_ATTR_FOR_STRING
70 /* Construct a tree for a list of two integers. */
71 #define DEF_LIST_INT_INT(VALUE1, VALUE2) \
72 DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE1##_##VALUE2, ATTR_NULL, \
73 ATTR_##VALUE1, ATTR_LIST_##VALUE2)
74 DEF_LIST_INT_INT (1,0)
75 DEF_LIST_INT_INT (1,2)
76 DEF_LIST_INT_INT (2,0)
77 DEF_LIST_INT_INT (2,3)
78 DEF_LIST_INT_INT (3,0)
79 DEF_LIST_INT_INT (3,4)
80 DEF_LIST_INT_INT (4,0)
81 DEF_LIST_INT_INT (4,5)
82 DEF_LIST_INT_INT (5,0)
83 DEF_LIST_INT_INT (5,6)
84 #undef DEF_LIST_INT_INT
86 /* Construct trees for identifiers. */
87 DEF_ATTR_IDENT (ATTR_CONST, "const")
88 DEF_ATTR_IDENT (ATTR_FORMAT, "format")
89 DEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg")
90 DEF_ATTR_IDENT (ATTR_MALLOC, "malloc")
91 DEF_ATTR_IDENT (ATTR_NONNULL, "nonnull")
92 DEF_ATTR_IDENT (ATTR_NORETURN, "noreturn")
93 DEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow")
94 DEF_ATTR_IDENT (ATTR_LEAF, "leaf")
95 DEF_ATTR_IDENT (ATTR_FNSPEC, "fn spec")
96 DEF_ATTR_IDENT (ATTR_PRINTF, "printf")
97 DEF_ATTR_IDENT (ATTR_ASM_FPRINTF, "asm_fprintf")
98 DEF_ATTR_IDENT (ATTR_GCC_DIAG, "gcc_diag")
99 DEF_ATTR_IDENT (ATTR_GCC_CDIAG, "gcc_cdiag")
100 DEF_ATTR_IDENT (ATTR_GCC_CXXDIAG, "gcc_cxxdiag")
101 DEF_ATTR_IDENT (ATTR_PURE, "pure")
102 DEF_ATTR_IDENT (ATTR_NOVOPS, "no vops")
103 DEF_ATTR_IDENT (ATTR_SCANF, "scanf")
104 DEF_ATTR_IDENT (ATTR_SENTINEL, "sentinel")
105 DEF_ATTR_IDENT (ATTR_STRFMON, "strfmon")
106 DEF_ATTR_IDENT (ATTR_STRFTIME, "strftime")
107 DEF_ATTR_IDENT (ATTR_TYPEGENERIC, "type generic")
108 DEF_ATTR_IDENT (ATTR_TM_REGPARM, "*tm regparm")
109 DEF_ATTR_IDENT (ATTR_TM_TMPURE, "transaction_pure")
110 DEF_ATTR_IDENT (ATTR_RETURNS_TWICE, "returns_twice")
112 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL)
114 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NOVOPS_LIST)
116 DEF_ATTR_TREE_LIST (ATTR_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NULL)
118 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL)
120 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NOTHROW_LIST)
122 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST, \
123 ATTR_NULL, ATTR_NOTHROW_LIST)
124 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LEAF_LIST, ATTR_CONST, \
125 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
126 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE, \
127 ATTR_NULL, ATTR_NOTHROW_LIST)
128 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LEAF_LIST, ATTR_PURE, \
129 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
130 DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \
131 ATTR_NULL, ATTR_NOTHROW_LIST)
132 DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\
133 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
134 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \
135 ATTR_NULL, ATTR_NOTHROW_LIST)
136 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LEAF_LIST, ATTR_MALLOC, \
137 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
138 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LIST, ATTR_SENTINEL, \
139 ATTR_NULL, ATTR_NOTHROW_LIST)
140 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LEAF_LIST, ATTR_SENTINEL, \
141 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
143 /* Functions whose pointer parameter(s) are all nonnull. */
144 DEF_ATTR_TREE_LIST (ATTR_NONNULL_LIST, ATTR_NONNULL, ATTR_NULL, ATTR_NULL)
145 /* Functions whose first parameter is a nonnull pointer. */
146 DEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, ATTR_NULL)
147 /* Functions whose second parameter is a nonnull pointer. */
148 DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, ATTR_NULL)
149 /* Functions whose third parameter is a nonnull pointer. */
150 DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, ATTR_NULL)
151 /* Nothrow functions with the sentinel(1) attribute. */
152 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_SENTINEL_1, ATTR_SENTINEL, ATTR_LIST_1, \
153 ATTR_NOTHROW_LIST)
154 /* Nothrow functions whose pointer parameter(s) are all nonnull. */
155 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL, ATTR_NONNULL, ATTR_NULL, \
156 ATTR_NOTHROW_LIST)
157 /* Nothrow leaf functions whose pointer parameter(s) are all nonnull. */
158 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_LEAF, ATTR_NONNULL, ATTR_NULL, \
159 ATTR_NOTHROW_LEAF_LIST)
160 /* Nothrow functions whose first parameter is a nonnull pointer. */
161 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \
162 ATTR_NOTHROW_LIST)
163 /* Nothrow functions whose second parameter is a nonnull pointer. */
164 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \
165 ATTR_NOTHROW_LIST)
166 /* Nothrow functions whose third parameter is a nonnull pointer. */
167 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \
168 ATTR_NOTHROW_LIST)
169 /* Nothrow functions whose fourth parameter is a nonnull pointer. */
170 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_4, ATTR_NONNULL, ATTR_LIST_4, \
171 ATTR_NOTHROW_LIST)
172 /* Nothrow functions whose fifth parameter is a nonnull pointer. */
173 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_5, ATTR_NONNULL, ATTR_LIST_5, \
174 ATTR_NOTHROW_LIST)
175 /* Nothrow const functions whose pointer parameter(s) are all nonnull. */
176 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL, ATTR_CONST, ATTR_NULL, \
177 ATTR_NOTHROW_NONNULL)
178 /* Nothrow leaf functions whose pointer parameter(s) are all nonnull,
179 and which return their first argument. */
180 DEF_ATTR_TREE_LIST (ATTR_RET1_NOTHROW_NONNULL_LEAF, ATTR_FNSPEC, ATTR_LIST_STR1, \
181 ATTR_NOTHROW_NONNULL_LEAF)
182 /* Nothrow const leaf functions whose pointer parameter(s) are all nonnull. */
183 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL_LEAF, ATTR_CONST, ATTR_NULL, \
184 ATTR_NOTHROW_NONNULL_LEAF)
185 /* Nothrow const functions which are type-generic. */
186 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_TYPEGENERIC, ATTR_TYPEGENERIC, ATTR_NULL, \
187 ATTR_CONST_NOTHROW_LIST)
188 /* Nothrow const leaf functions which are type-generic. */
189 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_TYPEGENERIC_LEAF, ATTR_TYPEGENERIC, ATTR_NULL, \
190 ATTR_CONST_NOTHROW_LEAF_LIST)
191 /* Nothrow pure functions whose pointer parameter(s) are all nonnull. */
192 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL, ATTR_PURE, ATTR_NULL, \
193 ATTR_NOTHROW_NONNULL)
194 /* Nothrow pure leaf functions whose pointer parameter(s) are all nonnull. */
195 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_LEAF, ATTR_PURE, ATTR_NULL, \
196 ATTR_NOTHROW_NONNULL_LEAF)
197 /* Nothrow malloc functions whose pointer parameter(s) are all nonnull. */
198 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL, ATTR_MALLOC, ATTR_NULL, \
199 ATTR_NOTHROW_NONNULL)
200 /* Nothrow malloc leaf functions whose pointer parameter(s) are all nonnull. */
201 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL_LEAF, ATTR_MALLOC, ATTR_NULL, \
202 ATTR_NOTHROW_NONNULL_LEAF)
204 /* Construct a tree for a format attribute. */
205 #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \
206 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
207 ATTR_##TYPE, ATTR_LIST_##VALUES) \
208 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT, \
209 ATTR_##TYPE##_##VALUES, ATTR_NONNULL_##FA)
210 #define DEF_FORMAT_ATTRIBUTE_NOTHROW(TYPE, FA, VALUES) \
211 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
212 ATTR_##TYPE, ATTR_LIST_##VALUES) \
213 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_NOTHROW_##VALUES, ATTR_FORMAT,\
214 ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA)
215 #define DEF_FORMAT_ATTRIBUTE_BOTH(TYPE, FA, VALUES) \
216 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
217 ATTR_##TYPE, ATTR_LIST_##VALUES) \
218 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT, \
219 ATTR_##TYPE##_##VALUES, ATTR_NONNULL_##FA) \
220 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_NOTHROW_##VALUES, ATTR_FORMAT,\
221 ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA)
222 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0)
223 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2)
224 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,2,2_0)
225 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,2,2_3)
226 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,3,3_0)
227 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,3,3_4)
228 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,4,4_0)
229 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,4,4_5)
230 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,5,5_0)
231 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,5,5_6)
232 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_0)
233 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_2)
234 DEF_FORMAT_ATTRIBUTE_BOTH(SCANF,2,2_0)
235 DEF_FORMAT_ATTRIBUTE_BOTH(SCANF,2,2_3)
236 DEF_FORMAT_ATTRIBUTE_NOTHROW(STRFTIME,3,3_0)
237 DEF_FORMAT_ATTRIBUTE_NOTHROW(STRFMON,3,3_4)
238 #undef DEF_FORMAT_ATTRIBUTE
239 #undef DEF_FORMAT_ATTRIBUTE_NOTHROW
240 #undef DEF_FORMAT_ATTRIBUTE_BOTH
242 /* Transactional memory variants of the above. */
244 DEF_ATTR_TREE_LIST (ATTR_TM_NOTHROW_LIST,
245 ATTR_TM_REGPARM, ATTR_NULL, ATTR_NOTHROW_LIST)
246 DEF_ATTR_TREE_LIST (ATTR_TM_TMPURE_NOTHROW_LIST,
247 ATTR_TM_TMPURE, ATTR_NULL, ATTR_TM_NOTHROW_LIST)
248 DEF_ATTR_TREE_LIST (ATTR_TM_PURE_TMPURE_NOTHROW_LIST,
249 ATTR_PURE, ATTR_NULL, ATTR_TM_TMPURE_NOTHROW_LIST)
250 DEF_ATTR_TREE_LIST (ATTR_TM_NORETURN_NOTHROW_LIST,
251 ATTR_TM_REGPARM, ATTR_NULL, ATTR_NORETURN_NOTHROW_LIST)
252 DEF_ATTR_TREE_LIST (ATTR_TM_CONST_NOTHROW_LIST,
253 ATTR_TM_REGPARM, ATTR_NULL, ATTR_CONST_NOTHROW_LIST)
254 DEF_ATTR_TREE_LIST (ATTR_TM_NOTHROW_RT_LIST,
255 ATTR_RETURNS_TWICE, ATTR_NULL, ATTR_TM_NOTHROW_LIST)
257 /* Same attributes used for BUILT_IN_MALLOC except with TM_PURE thrown in. */
258 DEF_ATTR_TREE_LIST (ATTR_TMPURE_MALLOC_NOTHROW_LIST,
259 ATTR_TM_TMPURE, ATTR_NULL, ATTR_MALLOC_NOTHROW_LIST)
260 /* Same attributes used for BUILT_IN_FREE except with TM_PURE thrown in. */
261 DEF_ATTR_TREE_LIST (ATTR_TMPURE_NOTHROW_LIST,
262 ATTR_TM_TMPURE, ATTR_NULL, ATTR_NOTHROW_LIST)
264 /* Construct a tree for a format_arg attribute. */
265 #define DEF_FORMAT_ARG_ATTRIBUTE(FA) \
266 DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_##FA, ATTR_FORMAT_ARG, \
267 ATTR_LIST_##FA, ATTR_NOTHROW_NONNULL_##FA)
268 DEF_FORMAT_ARG_ATTRIBUTE(1)
269 DEF_FORMAT_ARG_ATTRIBUTE(2)
270 #undef DEF_FORMAT_ARG_ATTRIBUTE