OSDN Git Service

* config/locale/generic/c_locale.h: Include <cstdlib> and
[pf3gnuchains/gcc-fork.git] / gcc / builtin-attrs.def
1 /* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
2    Contributed by Joseph Myers <jsm28@cam.ac.uk>.
3
4 This file is part of GCC.
5
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 2, or (at your option) any later
9 version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.  */
20
21 /* This header provides a declarative way of describing the attributes
22    that are applied to some functions by default.
23
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.
27
28    DEF_ATTR_NULL_TREE (ENUM)
29
30      Constructs a NULL_TREE.
31
32    DEF_ATTR_INT (ENUM, VALUE)
33
34      Constructs an INTEGER_CST with value VALUE (an integer representable
35      in HOST_WIDE_INT).
36
37    DEF_ATTR_IDENT (ENUM, STRING)
38
39      Constructs an IDENTIFIER_NODE for STRING.
40
41    DEF_ATTR_TREE_LIST (ENUM, PURPOSE, VALUE, CHAIN)
42
43      Constructs a TREE_LIST with given PURPOSE, VALUE and CHAIN (given
44      as previous ENUM names).
45
46    DEF_FN_ATTR (NAME, ATTRS, PREDICATE)
47
48      Specifies that the function with name NAME (a previous ENUM for an
49      IDENTIFIER_NODE) has attributes ATTRS (a previous ENUM) if
50      PREDICATE is true.  */
51
52 DEF_ATTR_NULL_TREE (ATTR_NULL)
53
54 /* Construct a tree for a given integer and a list containing it.  */
55 #define DEF_ATTR_FOR_INT(VALUE)                                 \
56   DEF_ATTR_INT (ATTR_##VALUE, VALUE)                    \
57   DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE, ATTR_NULL,     \
58                       ATTR_##VALUE, ATTR_NULL)
59 DEF_ATTR_FOR_INT (0)
60 DEF_ATTR_FOR_INT (1)
61 DEF_ATTR_FOR_INT (2)
62 DEF_ATTR_FOR_INT (3)
63 DEF_ATTR_FOR_INT (4)
64 #undef DEF_ATTR_FOR_INT
65
66 /* Construct a tree for a list of two integers.  */
67 #define DEF_LIST_INT_INT(VALUE1, VALUE2)                                 \
68   DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE1##_##VALUE2, ATTR_NULL,          \
69                       ATTR_##VALUE1, ATTR_LIST_##VALUE2)
70 DEF_LIST_INT_INT (1,0)
71 DEF_LIST_INT_INT (1,2)
72 DEF_LIST_INT_INT (2,0)
73 DEF_LIST_INT_INT (2,3)
74 DEF_LIST_INT_INT (3,0)
75 DEF_LIST_INT_INT (3,4)
76 #undef DEF_LIST_INT_INT
77
78 /* Construct tress for identifiers.  */
79 DEF_ATTR_IDENT (ATTR_CONST, "const")
80 DEF_ATTR_IDENT (ATTR_FORMAT, "format")
81 DEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg")
82 DEF_ATTR_IDENT (ATTR_MALLOC, "malloc")
83 DEF_ATTR_IDENT (ATTR_NONNULL, "nonnull")
84 DEF_ATTR_IDENT (ATTR_NORETURN, "noreturn")
85 DEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow")
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_SCANF, "scanf")
93 DEF_ATTR_IDENT (ATTR_STRFMON, "strfmon")
94 DEF_ATTR_IDENT (ATTR_STRFTIME, "strftime")
95
96 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL)
97
98 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST,        \
99                         ATTR_NULL, ATTR_NOTHROW_LIST)
100 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE,          \
101                         ATTR_NULL, ATTR_NOTHROW_LIST)
102 DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN,  \
103                         ATTR_NULL, ATTR_NOTHROW_LIST)
104 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC,      \
105                         ATTR_NULL, ATTR_NOTHROW_LIST)
106
107 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \
108                         ATTR_NOTHROW_LIST)
109 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \
110                         ATTR_NOTHROW_LIST)
111 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \
112                         ATTR_NOTHROW_LIST)
113 /* Nothrow functions whose first and second parameters are nonnull pointers. */
114 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1_2, ATTR_NONNULL, ATTR_LIST_2, \
115                         ATTR_NOTHROW_NONNULL_1)
116 /* Nothrow functions whose first and fourth parameters are nonnull pointers. */
117 DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1_4, ATTR_NONNULL, ATTR_LIST_4, \
118                         ATTR_NOTHROW_NONNULL_1)
119 /* Nothrow const functions whose first parameter is a nonnull pointer. */
120 DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL_1, ATTR_CONST, ATTR_NULL, \
121                         ATTR_NOTHROW_NONNULL_1)
122 /* Nothrow pure functions whose first parameter is a nonnull pointer. */
123 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_1, ATTR_PURE, ATTR_NULL, \
124                         ATTR_NOTHROW_NONNULL_1)
125 /* Nothrow pure functions whose first and second parameters are nonnull pointers. */
126 DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL_1_2, ATTR_PURE, ATTR_NULL, \
127                         ATTR_NOTHROW_NONNULL_1_2)
128 /* Nothrow malloc functions whose first parameter is a nonnull pointer. */
129 DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL_1, ATTR_MALLOC, ATTR_NULL, \
130                         ATTR_NOTHROW_NONNULL_1)
131
132 /* Construct a tree for a format attribute.  */
133 #define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES)                           \
134   DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL,                 \
135                       ATTR_##TYPE, ATTR_LIST_##VALUES)                   \
136   DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT,        \
137                       ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA)
138 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0)
139 DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2)
140 DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_0)
141 DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_3)
142 DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_0)
143 DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_4)
144 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_0)
145 DEF_FORMAT_ATTRIBUTE(SCANF,1,1_2)
146 DEF_FORMAT_ATTRIBUTE(SCANF,2,2_0)
147 DEF_FORMAT_ATTRIBUTE(SCANF,2,2_3)
148 DEF_FORMAT_ATTRIBUTE(STRFTIME,3,3_0)
149 DEF_FORMAT_ATTRIBUTE(STRFMON,3,3_4)
150 #undef DEF_FORMAT_ATTRIBUTE
151
152 /* Construct a tree for a format_arg attribute.  */
153 #define DEF_FORMAT_ARG_ATTRIBUTE(FA)                                    \
154   DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_##FA, ATTR_FORMAT_ARG,            \
155                       ATTR_LIST_##FA, ATTR_NOTHROW_NONNULL_##FA)
156 DEF_FORMAT_ARG_ATTRIBUTE(1)
157 DEF_FORMAT_ARG_ATTRIBUTE(2)
158 #undef DEF_FORMAT_ARG_ATTRIBUTE
159
160 /* Define an attribute for a function, along with the IDENTIFIER_NODE.  */
161 #define DEF_FN_ATTR_IDENT(NAME, ATTRS, PREDICATE)       \
162   DEF_ATTR_IDENT (ATTR_##NAME, #NAME)                   \
163   DEF_FN_ATTR (ATTR_##NAME, ATTRS, PREDICATE)
164
165 /* The ISO C functions are always checked (whether <stdio.h> is
166    included or not), since it is common to call printf without
167    including <stdio.h>.  There shouldn't be a problem with this,
168    since ISO C reserves these function names whether you include the
169    header file or not.  In any case, the checking is harmless.  With
170    -ffreestanding, these default attributes are disabled, and must be
171    specified manually if desired.  */
172
173 /* Functions from ISO/IEC 9899:1990.  */
174 #define DEF_C89_ATTR(NAME, ATTRS) DEF_FN_ATTR_IDENT (NAME, ATTRS, flag_hosted)
175 DEF_C89_ATTR (fscanf, ATTR_FORMAT_SCANF_2_3)
176 DEF_C89_ATTR (vfprintf, ATTR_FORMAT_PRINTF_2_0)
177 DEF_C89_ATTR (strftime, ATTR_FORMAT_STRFTIME_3_0)
178 #undef DEF_C89_ATTR
179
180 /* ISO C99 adds the snprintf and vscanf family functions.  */
181 #define DEF_C99_ATTR(NAME, ATTRS)                                           \
182   DEF_FN_ATTR_IDENT (NAME, ATTRS,                                           \
183                (flag_hosted                                                 \
184                 && (flag_isoc99 || flag_noniso_default_format_attributes)))
185 DEF_C99_ATTR (vfscanf, ATTR_FORMAT_SCANF_2_0)
186 #undef DEF_C99_ATTR
187
188 /* Functions not in any version of ISO C.  */
189 #define DEF_EXT_ATTR(NAME, ATTRS)                                       \
190   DEF_FN_ATTR_IDENT (NAME, ATTRS,                                       \
191                flag_hosted && flag_noniso_default_format_attributes)
192 /* Uniforum/GNU gettext functions.  */
193 DEF_EXT_ATTR (gettext, ATTR_FORMAT_ARG_1)
194 DEF_EXT_ATTR (dgettext, ATTR_FORMAT_ARG_2)
195 DEF_EXT_ATTR (dcgettext, ATTR_FORMAT_ARG_2)
196 /* X/Open strfmon function.  */
197 DEF_EXT_ATTR (strfmon, ATTR_FORMAT_STRFMON_3_4)
198 #undef DEF_EXT_ATTR
199 #undef DEF_FN_ATTR_IDENT