1 /* Copyright (C
) 2001 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
2, or (at your option
) any later
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
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
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
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_FN_ATTR (NAME
, ATTRS
, PREDICATE
)
48 Specifies that the function with name
NAME (a previous ENUM for an
49 IDENTIFIER_NODE
) has attributes
ATTRS (a previous ENUM
) if
52 DEF_ATTR_NULL_TREE (ATTR_NULL
)
54 /* Note that below we must avoid whitespace in arguments of CONCAT
*.
*/
56 /* Construct a tree for a given integer and a list containing it.
*/
57 #define
DEF_ATTR_FOR_INT(VALUE
) \
58 DEF_ATTR_INT (CONCAT2 (ATTR_
,VALUE
), VALUE
) \
59 DEF_ATTR_TREE_LIST (CONCAT2 (ATTR_LIST_
,VALUE
), ATTR_NULL
, \
60 CONCAT2 (ATTR_
,VALUE
), ATTR_NULL
)
66 #undef DEF_ATTR_FOR_INT
68 /* Construct a tree for a list of two integers.
*/
69 #define
DEF_LIST_INT_INT(VALUE1
, VALUE2
) \
70 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_LIST_
,VALUE1
,_
,VALUE2
), ATTR_NULL
, \
71 CONCAT2 (ATTR_
,VALUE1
), CONCAT2 (ATTR_LIST_
,VALUE2
))
72 DEF_LIST_INT_INT (1,0)
73 DEF_LIST_INT_INT (1,2)
74 DEF_LIST_INT_INT (2,0)
75 DEF_LIST_INT_INT (2,3)
76 DEF_LIST_INT_INT (3,0)
77 DEF_LIST_INT_INT (3,4)
78 #undef DEF_LIST_INT_INT
80 DEF_ATTR_IDENT (ATTR_PRINTF
, "printf")
81 DEF_ATTR_IDENT (ATTR_SCANF
, "scanf")
82 DEF_ATTR_IDENT (ATTR_STRFTIME
, "strftime")
83 DEF_ATTR_IDENT (ATTR_STRFMON
, "strfmon")
85 DEF_ATTR_IDENT (ATTR_FORMAT
, "format")
86 DEF_ATTR_IDENT (ATTR_FORMAT_ARG
, "format_arg")
88 /* Construct a tree for a format attribute.
*/
89 #define
DEF_FORMAT_ATTRIBUTE(TYPE, VALUES
) \
90 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_
,TYPE,_
,VALUES
), ATTR_NULL
, \
91 CONCAT2 (ATTR_
,TYPE), CONCAT2 (ATTR_LIST_
,VALUES
)) \
92 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_FORMAT_
,TYPE,_
,VALUES
), ATTR_FORMAT
, \
93 CONCAT4 (ATTR_
,TYPE,_
,VALUES
), ATTR_NULL
)
94 DEF_FORMAT_ATTRIBUTE(PRINTF
,1_0
)
95 DEF_FORMAT_ATTRIBUTE(PRINTF
,1_2
)
96 DEF_FORMAT_ATTRIBUTE(PRINTF
,2_0
)
97 DEF_FORMAT_ATTRIBUTE(PRINTF
,2_3
)
98 DEF_FORMAT_ATTRIBUTE(PRINTF
,3_0
)
99 DEF_FORMAT_ATTRIBUTE(PRINTF
,3_4
)
100 DEF_FORMAT_ATTRIBUTE(SCANF
,1_0
)
101 DEF_FORMAT_ATTRIBUTE(SCANF
,1_2
)
102 DEF_FORMAT_ATTRIBUTE(SCANF
,2_0
)
103 DEF_FORMAT_ATTRIBUTE(SCANF
,2_3
)
104 DEF_FORMAT_ATTRIBUTE(STRFTIME
,3_0
)
105 DEF_FORMAT_ATTRIBUTE(STRFMON
,3_4
)
106 #undef DEF_FORMAT_ATTRIBUTE
108 DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_1
, ATTR_FORMAT_ARG
, ATTR_LIST_1
, ATTR_NULL
)
109 DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_2
, ATTR_FORMAT_ARG
, ATTR_LIST_2
, ATTR_NULL
)
111 /* Define an attribute for a function
, along with the IDENTIFIER_NODE.
*/
112 #define
DEF_FN_ATTR_IDENT(NAME
, ATTRS
, PREDICATE
) \
113 DEF_ATTR_IDENT (CONCAT2(ATTR_
,NAME
), STRINGX(NAME
)) \
114 DEF_FN_ATTR (CONCAT2(ATTR_
,NAME
), ATTRS
, PREDICATE
)
116 /* The ISO C functions are always
checked (whether
<stdio.h
> is
117 included or not
), since it is common to call printf without
118 including
<stdio.h
>. There shouldn
't be a problem with this,
119 since ISO C reserves these function names whether you include the
120 header file or not. In any case, the checking is harmless. With
121 -ffreestanding, these default attributes are disabled, and must be
122 specified manually if desired. */
124 /* __builtin functions should be checked unconditionally, even with
126 DEF_FN_ATTR_IDENT (__builtin_printf, ATTR_FORMAT_PRINTF_1_2, true)
127 DEF_FN_ATTR_IDENT (__builtin_fprintf, ATTR_FORMAT_PRINTF_2_3, true)
129 /* Functions from ISO/IEC 9899:1990. */
130 #define DEF_C89_ATTR(NAME, ATTRS) DEF_FN_ATTR_IDENT (NAME, ATTRS, flag_hosted)
131 DEF_C89_ATTR (printf, ATTR_FORMAT_PRINTF_1_2)
132 DEF_C89_ATTR (fprintf, ATTR_FORMAT_PRINTF_2_3)
133 DEF_C89_ATTR (sprintf, ATTR_FORMAT_PRINTF_2_3)
134 DEF_C89_ATTR (scanf, ATTR_FORMAT_SCANF_1_2)
135 DEF_C89_ATTR (fscanf, ATTR_FORMAT_SCANF_2_3)
136 DEF_C89_ATTR (sscanf, ATTR_FORMAT_SCANF_2_3)
137 DEF_C89_ATTR (vprintf, ATTR_FORMAT_PRINTF_1_0)
138 DEF_C89_ATTR (vfprintf, ATTR_FORMAT_PRINTF_2_0)
139 DEF_C89_ATTR (vsprintf, ATTR_FORMAT_PRINTF_2_0)
140 DEF_C89_ATTR (strftime, ATTR_FORMAT_STRFTIME_3_0)
143 /* ISO C99 adds the snprintf and vscanf family functions. */
144 #define DEF_C99_ATTR(NAME, ATTRS) \
145 DEF_FN_ATTR_IDENT (NAME, ATTRS, \
147 && (flag_isoc99 || flag_noniso_default_format_attributes)))
148 DEF_C99_ATTR (snprintf, ATTR_FORMAT_PRINTF_3_4)
149 DEF_C99_ATTR (vsnprintf, ATTR_FORMAT_PRINTF_3_0)
150 DEF_C99_ATTR (vscanf, ATTR_FORMAT_SCANF_1_0)
151 DEF_C99_ATTR (vfscanf, ATTR_FORMAT_SCANF_2_0)
152 DEF_C99_ATTR (vsscanf, ATTR_FORMAT_SCANF_2_0)
155 /* Functions not in any version of ISO C. */
156 #define DEF_EXT_ATTR(NAME, ATTRS) \
157 DEF_FN_ATTR_IDENT (NAME, ATTRS, \
158 flag_hosted && flag_noniso_default_format_attributes)
159 /* Uniforum/GNU gettext functions. */
160 DEF_EXT_ATTR (gettext, ATTR_FORMAT_ARG_1)
161 DEF_EXT_ATTR (dgettext, ATTR_FORMAT_ARG_2)
162 DEF_EXT_ATTR (dcgettext, ATTR_FORMAT_ARG_2)
163 /* X/Open strfmon function. */
164 DEF_EXT_ATTR (strfmon, ATTR_FORMAT_STRFMON_3_4)
166 #undef DEF_FN_ATTR_IDENT