2010-11-11 Jakub Jelinek <jakub@redhat.com>
[official-gcc.git] / gcc / builtin-attrs.def
blob587671b574ebff41c79c59466a428d680a65ea51
1 /* Copyright (C) 2001, 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
2 Contributed by Joseph Myers <jsm28@cam.ac.uk>.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This header provides a declarative way of describing the attributes
21 that are applied to some functions by default.
23 Before including this header, you must define the following macros.
24 In each case where there is an ENUM, it is an identifier used to
25 reference the tree in subsequent definitions.
27 DEF_ATTR_NULL_TREE (ENUM)
29 Constructs a NULL_TREE.
31 DEF_ATTR_INT (ENUM, VALUE)
33 Constructs an INTEGER_CST with value VALUE (an integer representable
34 in HOST_WIDE_INT).
36 DEF_ATTR_IDENT (ENUM, STRING)
38 Constructs an IDENTIFIER_NODE for STRING.
40 DEF_ATTR_TREE_LIST (ENUM, PURPOSE, VALUE, CHAIN)
42 Constructs a TREE_LIST with given PURPOSE, VALUE and CHAIN (given
43 as previous ENUM names). */
45 DEF_ATTR_NULL_TREE (ATTR_NULL)
47 /* Construct a tree for a given integer and a list containing it. */
48 #define DEF_ATTR_FOR_INT(VALUE) \
49 DEF_ATTR_INT (ATTR_##VALUE, VALUE) \
50 DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE, ATTR_NULL, \
51 ATTR_##VALUE, ATTR_NULL)
52 DEF_ATTR_FOR_INT (0)
53 DEF_ATTR_FOR_INT (1)
54 DEF_ATTR_FOR_INT (2)
55 DEF_ATTR_FOR_INT (3)
56 DEF_ATTR_FOR_INT (4)
57 DEF_ATTR_FOR_INT (5)
58 DEF_ATTR_FOR_INT (6)
59 #undef DEF_ATTR_FOR_INT
61 /* Construct a tree for a list of two integers. */
62 #define DEF_LIST_INT_INT(VALUE1, VALUE2) \
63 DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE1##_##VALUE2, ATTR_NULL, \
64 ATTR_##VALUE1, ATTR_LIST_##VALUE2)
65 DEF_LIST_INT_INT (1,0)
66 DEF_LIST_INT_INT (1,2)
67 DEF_LIST_INT_INT (2,0)
68 DEF_LIST_INT_INT (2,3)
69 DEF_LIST_INT_INT (3,0)
70 DEF_LIST_INT_INT (3,4)
71 DEF_LIST_INT_INT (4,0)
72 DEF_LIST_INT_INT (4,5)
73 DEF_LIST_INT_INT (5,0)
74 DEF_LIST_INT_INT (5,6)
75 #undef DEF_LIST_INT_INT
77 /* Construct trees for identifiers. */
78 DEF_ATTR_IDENT (ATTR_CONST, "const")
79 DEF_ATTR_IDENT (ATTR_FORMAT, "format")
80 DEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg")
81 DEF_ATTR_IDENT (ATTR_MALLOC, "malloc")
82 DEF_ATTR_IDENT (ATTR_NONNULL, "nonnull")
83 DEF_ATTR_IDENT (ATTR_NORETURN, "noreturn")
84 DEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow")
85 DEF_ATTR_IDENT (ATTR_LEAF, "leaf")
86 DEF_ATTR_IDENT (ATTR_PRINTF, "printf")
87 DEF_ATTR_IDENT (ATTR_ASM_FPRINTF, "asm_fprintf")
88 DEF_ATTR_IDENT (ATTR_GCC_DIAG, "gcc_diag")
89 DEF_ATTR_IDENT (ATTR_GCC_CDIAG, "gcc_cdiag")
90 DEF_ATTR_IDENT (ATTR_GCC_CXXDIAG, "gcc_cxxdiag")
91 DEF_ATTR_IDENT (ATTR_PURE, "pure")
92 DEF_ATTR_IDENT (ATTR_NOVOPS, "no vops")
93 DEF_ATTR_IDENT (ATTR_SCANF, "scanf")
94 DEF_ATTR_IDENT (ATTR_SENTINEL, "sentinel")
95 DEF_ATTR_IDENT (ATTR_STRFMON, "strfmon")
96 DEF_ATTR_IDENT (ATTR_STRFTIME, "strftime")
97 DEF_ATTR_IDENT (ATTR_TYPEGENERIC, "type generic")
99 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL)
101 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NOVOPS_LIST)
103 DEF_ATTR_TREE_LIST (ATTR_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NULL)
105 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL)
107 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LEAF_LIST, ATTR_LEAF, ATTR_NULL, ATTR_NOTHROW_LIST)
109 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST, \
110 ATTR_NULL, ATTR_NOTHROW_LIST)
111 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LEAF_LIST, ATTR_CONST, \
112 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
113 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE, \
114 ATTR_NULL, ATTR_NOTHROW_LIST)
115 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LEAF_LIST, ATTR_PURE, \
116 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
117 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NOVOPS_LIST, ATTR_NOVOPS, \
118 ATTR_NULL, ATTR_PURE_NOTHROW_LIST)
119 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NOVOPS_LEAF_LIST, ATTR_NOVOPS,\
120 ATTR_NULL, ATTR_PURE_NOTHROW_LEAF_LIST)
121 DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \
122 ATTR_NULL, ATTR_NOTHROW_LIST)
123 DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\
124 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
125 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \
126 ATTR_NULL, ATTR_NOTHROW_LIST)
127 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LEAF_LIST, ATTR_MALLOC, \
128 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
129 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LIST, ATTR_SENTINEL, \
130 ATTR_NULL, ATTR_NOTHROW_LIST)
131 DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LEAF_LIST, ATTR_SENTINEL, \
132 ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
134 /* Functions whose pointer parameter(s) are all nonnull. */
135 DEF_ATTR_TREE_LIST (ATTR_NONNULL_LIST, ATTR_NONNULL, ATTR_NULL, ATTR_NULL)
136 /* Functions whose first parameter is a nonnull pointer. */
137 DEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, ATTR_NULL)
138 /* Functions whose second parameter is a nonnull pointer. */
139 DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, ATTR_NULL)
140 /* Functions whose third parameter is a nonnull pointer. */
141 DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, ATTR_NULL)
142 /* Nothrow functions with the sentinel(1) attribute. */
143 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_SENTINEL_1, ATTR_SENTINEL, ATTR_LIST_1, \
144 ATTR_NOTHROW_LIST)
145 /* Nothrow functions whose pointer parameter(s) are all nonnull. */
146 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL, ATTR_NONNULL, ATTR_NULL, \
147 ATTR_NOTHROW_LIST)
148 /* Nothrow leaf functions whose pointer parameter(s) are all nonnull. */
149 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_LEAF, ATTR_NONNULL, ATTR_NULL, \
150 ATTR_NOTHROW_LEAF_LIST)
151 /* Nothrow functions whose first parameter is a nonnull pointer. */
152 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \
153 ATTR_NOTHROW_LIST)
154 /* Nothrow functions whose second parameter is a nonnull pointer. */
155 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \
156 ATTR_NOTHROW_LIST)
157 /* Nothrow functions whose third parameter is a nonnull pointer. */
158 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \
159 ATTR_NOTHROW_LIST)
160 /* Nothrow functions whose fourth parameter is a nonnull pointer. */
161 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_4, ATTR_NONNULL, ATTR_LIST_4, \
162 ATTR_NOTHROW_LIST)
163 /* Nothrow functions whose fifth parameter is a nonnull pointer. */
164 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_5, ATTR_NONNULL, ATTR_LIST_5, \
165 ATTR_NOTHROW_LIST)
166 /* Nothrow const functions whose pointer parameter(s) are all nonnull. */
167 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL, ATTR_CONST, ATTR_NULL, \
168 ATTR_NOTHROW_NONNULL)
169 /* Nothrow const leaf functions whose pointer parameter(s) are all nonnull. */
170 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL_LEAF, ATTR_CONST, ATTR_NULL, \
171 ATTR_NOTHROW_NONNULL_LEAF)
172 /* Nothrow const functions which are type-generic. */
173 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_TYPEGENERIC, ATTR_TYPEGENERIC, ATTR_NULL, \
174 ATTR_CONST_NOTHROW_LIST)
175 /* Nothrow const leaf functions which are type-generic. */
176 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_TYPEGENERIC_LEAF, ATTR_TYPEGENERIC, ATTR_NULL, \
177 ATTR_CONST_NOTHROW_LEAF_LIST)
178 /* Nothrow pure functions whose pointer parameter(s) are all nonnull. */
179 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL, ATTR_PURE, ATTR_NULL, \
180 ATTR_NOTHROW_NONNULL)
181 /* Nothrow pure leaf functions whose pointer parameter(s) are all nonnull. */
182 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_LEAF, ATTR_PURE, ATTR_NULL, \
183 ATTR_NOTHROW_NONNULL_LEAF)
184 /* Nothrow malloc functions whose pointer parameter(s) are all nonnull. */
185 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL, ATTR_MALLOC, ATTR_NULL, \
186 ATTR_NOTHROW_NONNULL)
187 /* Nothrow malloc leaf functions whose pointer parameter(s) are all nonnull. */
188 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL_LEAF, ATTR_MALLOC, ATTR_NULL, \
189 ATTR_NOTHROW_NONNULL_LEAF)
191 /* Construct a tree for a format attribute. */
192 #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \
193 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
194 ATTR_##TYPE, ATTR_LIST_##VALUES) \
195 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT, \
196 ATTR_##TYPE##_##VALUES, ATTR_NONNULL_##FA)
197 #define DEF_FORMAT_ATTRIBUTE_NOTHROW(TYPE, FA, VALUES) \
198 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
199 ATTR_##TYPE, ATTR_LIST_##VALUES) \
200 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_NOTHROW_##VALUES, ATTR_FORMAT,\
201 ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA)
202 #define DEF_FORMAT_ATTRIBUTE_BOTH(TYPE, FA, VALUES) \
203 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \
204 ATTR_##TYPE, ATTR_LIST_##VALUES) \
205 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT, \
206 ATTR_##TYPE##_##VALUES, ATTR_NONNULL_##FA) \
207 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_NOTHROW_##VALUES, ATTR_FORMAT,\
208 ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA)
209 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0)
210 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2)
211 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,2,2_0)
212 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,2,2_3)
213 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,3,3_0)
214 DEF_FORMAT_ATTRIBUTE_BOTH(PRINTF,3,3_4)
215 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,4,4_0)
216 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,4,4_5)
217 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,5,5_0)
218 DEF_FORMAT_ATTRIBUTE_NOTHROW(PRINTF,5,5_6)
219 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_0)
220 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_2)
221 DEF_FORMAT_ATTRIBUTE_BOTH(SCANF,2,2_0)
222 DEF_FORMAT_ATTRIBUTE_BOTH(SCANF,2,2_3)
223 DEF_FORMAT_ATTRIBUTE_NOTHROW(STRFTIME,3,3_0)
224 DEF_FORMAT_ATTRIBUTE_NOTHROW(STRFMON,3,3_4)
225 #undef DEF_FORMAT_ATTRIBUTE
226 #undef DEF_FORMAT_ATTRIBUTE_NOTHROW
227 #undef DEF_FORMAT_ATTRIBUTE_BOTH
229 /* Construct a tree for a format_arg attribute. */
230 #define DEF_FORMAT_ARG_ATTRIBUTE(FA) \
231 DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_##FA, ATTR_FORMAT_ARG, \
232 ATTR_LIST_##FA, ATTR_NOTHROW_NONNULL_##FA)
233 DEF_FORMAT_ARG_ATTRIBUTE(1)
234 DEF_FORMAT_ARG_ATTRIBUTE(2)
235 #undef DEF_FORMAT_ARG_ATTRIBUTE