1/* Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. 2 Contributed by Joseph Myers <jsm28@cam.ac.uk>. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 2, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License 17along with GCC; see the file COPYING. If not, write to the Free 18Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 1902110-1301, 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 46DEF_ATTR_NULL_TREE (ATTR_NULL) 47 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) 53DEF_ATTR_FOR_INT (0) 54DEF_ATTR_FOR_INT (1) 55DEF_ATTR_FOR_INT (2) 56DEF_ATTR_FOR_INT (3) 57DEF_ATTR_FOR_INT (4) 58DEF_ATTR_FOR_INT (5) 59DEF_ATTR_FOR_INT (6) 60#undef DEF_ATTR_FOR_INT 61 62/* Construct a tree for a list of two integers. */ 63#define DEF_LIST_INT_INT(VALUE1, VALUE2) \ 64 DEF_ATTR_TREE_LIST (ATTR_LIST_##VALUE1##_##VALUE2, ATTR_NULL, \ 65 ATTR_##VALUE1, ATTR_LIST_##VALUE2) 66DEF_LIST_INT_INT (1,0) 67DEF_LIST_INT_INT (1,2) 68DEF_LIST_INT_INT (2,0) 69DEF_LIST_INT_INT (2,3) 70DEF_LIST_INT_INT (3,0) 71DEF_LIST_INT_INT (3,4) 72DEF_LIST_INT_INT (4,0) 73DEF_LIST_INT_INT (4,5) 74DEF_LIST_INT_INT (5,0) 75DEF_LIST_INT_INT (5,6) 76#undef DEF_LIST_INT_INT 77 78/* Construct trees for identifiers. */ 79DEF_ATTR_IDENT (ATTR_CONST, "const") 80DEF_ATTR_IDENT (ATTR_FORMAT, "format") 81DEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg") 82DEF_ATTR_IDENT (ATTR_MALLOC, "malloc") 83DEF_ATTR_IDENT (ATTR_NONNULL, "nonnull") 84DEF_ATTR_IDENT (ATTR_NORETURN, "noreturn") 85DEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow") 86DEF_ATTR_IDENT (ATTR_PRINTF, "printf") 87DEF_ATTR_IDENT (ATTR_ASM_FPRINTF, "asm_fprintf") 88DEF_ATTR_IDENT (ATTR_GCC_DIAG, "gcc_diag") 89DEF_ATTR_IDENT (ATTR_GCC_CDIAG, "gcc_cdiag") 90DEF_ATTR_IDENT (ATTR_GCC_CXXDIAG, "gcc_cxxdiag") 91DEF_ATTR_IDENT (ATTR_PURE, "pure") 92DEF_ATTR_IDENT (ATTR_NOVOPS, "no vops") 93DEF_ATTR_IDENT (ATTR_SCANF, "scanf") 94DEF_ATTR_IDENT (ATTR_SENTINEL, "sentinel") 95DEF_ATTR_IDENT (ATTR_STRFMON, "strfmon") 96DEF_ATTR_IDENT (ATTR_STRFTIME, "strftime") 97 98DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL) 99 100DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL) 101 102DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST, \ 103 ATTR_NULL, ATTR_NOTHROW_LIST) 104DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE, \ 105 ATTR_NULL, ATTR_NOTHROW_LIST) 106DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NOVOPS_LIST, ATTR_NOVOPS, \ 107 ATTR_NULL, ATTR_PURE_NOTHROW_LIST) 108DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \ 109 ATTR_NULL, ATTR_NOTHROW_LIST) 110DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \ 111 ATTR_NULL, ATTR_NOTHROW_LIST) 112DEF_ATTR_TREE_LIST (ATTR_SENTINEL_NOTHROW_LIST, ATTR_SENTINEL, \ 113 ATTR_NULL, ATTR_NOTHROW_LIST) 114 115/* Functions whose pointer parameter(s) are all nonnull. */ 116DEF_ATTR_TREE_LIST (ATTR_NONNULL_LIST, ATTR_NONNULL, ATTR_NULL, ATTR_NULL) 117/* Functions whose first parameter is a nonnull pointer. */ 118DEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, ATTR_NULL) 119/* Functions whose second parameter is a nonnull pointer. */ 120DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, ATTR_NULL) 121/* Nothrow functions with the sentinel(1) attribute. */ 122DEF_ATTR_TREE_LIST (ATTR_NOTHROW_SENTINEL_1, ATTR_SENTINEL, ATTR_LIST_1, \ 123 ATTR_NOTHROW_LIST) 124/* Nothrow functions whose pointer parameter(s) are all nonnull. */ 125DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL, ATTR_NONNULL, ATTR_NULL, \ 126 ATTR_NOTHROW_LIST) 127/* Nothrow functions whose first parameter is a nonnull pointer. */ 128DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \ 129 ATTR_NOTHROW_LIST) 130/* Nothrow functions whose second parameter is a nonnull pointer. */ 131DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \ 132 ATTR_NOTHROW_LIST) 133/* Nothrow functions whose third parameter is a nonnull pointer. */ 134DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \ 135 ATTR_NOTHROW_LIST) 136/* Nothrow functions whose fourth parameter is a nonnull pointer. */ 137DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_4, ATTR_NONNULL, ATTR_LIST_4, \ 138 ATTR_NOTHROW_LIST) 139/* Nothrow functions whose fifth parameter is a nonnull pointer. */ 140DEF_ATTR_TREE_LIST (ATTR_NOTHROW_NONNULL_5, ATTR_NONNULL, ATTR_LIST_5, \ 141 ATTR_NOTHROW_LIST) 142/* Nothrow const functions whose pointer parameter(s) are all nonnull. */ 143DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_NONNULL, ATTR_CONST, ATTR_NULL, \ 144 ATTR_NOTHROW_NONNULL) 145/* Nothrow pure functions whose pointer parameter(s) are all nonnull. */ 146DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NONNULL, ATTR_PURE, ATTR_NULL, \ 147 ATTR_NOTHROW_NONNULL) 148/* Nothrow malloc functions whose pointer parameter(s) are all nonnull. */ 149DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_NONNULL, ATTR_MALLOC, ATTR_NULL, \ 150 ATTR_NOTHROW_NONNULL) 151 152/* Construct a tree for a format attribute. */ 153#define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \ 154 DEF_ATTR_TREE_LIST (ATTR_##TYPE##_##VALUES, ATTR_NULL, \ 155 ATTR_##TYPE, ATTR_LIST_##VALUES) \ 156 DEF_ATTR_TREE_LIST (ATTR_FORMAT_##TYPE##_##VALUES, ATTR_FORMAT, \ 157 ATTR_##TYPE##_##VALUES, ATTR_NOTHROW_NONNULL_##FA) 158DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0) 159DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2) 160DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_0) 161DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_3) 162DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_0) 163DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_4) 164DEF_FORMAT_ATTRIBUTE(PRINTF,4,4_0) 165DEF_FORMAT_ATTRIBUTE(PRINTF,4,4_5) 166DEF_FORMAT_ATTRIBUTE(PRINTF,5,5_0) 167DEF_FORMAT_ATTRIBUTE(PRINTF,5,5_6) 168DEF_FORMAT_ATTRIBUTE(SCANF,1,1_0) 169DEF_FORMAT_ATTRIBUTE(SCANF,1,1_2) 170DEF_FORMAT_ATTRIBUTE(SCANF,2,2_0) 171DEF_FORMAT_ATTRIBUTE(SCANF,2,2_3) 172DEF_FORMAT_ATTRIBUTE(STRFTIME,3,3_0) 173DEF_FORMAT_ATTRIBUTE(STRFMON,3,3_4) 174#undef DEF_FORMAT_ATTRIBUTE 175 176/* Construct a tree for a format_arg attribute. */ 177#define DEF_FORMAT_ARG_ATTRIBUTE(FA) \ 178 DEF_ATTR_TREE_LIST (ATTR_FORMAT_ARG_##FA, ATTR_FORMAT_ARG, \ 179 ATTR_LIST_##FA, ATTR_NOTHROW_NONNULL_##FA) 180DEF_FORMAT_ARG_ATTRIBUTE(1) 181DEF_FORMAT_ARG_ATTRIBUTE(2) 182#undef DEF_FORMAT_ARG_ATTRIBUTE 183 184