builtin-attrs.def 12 KB

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