1/* Copyright (C) 2001, 2002 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, 59 Temple Place - Suite 330, Boston, MA 1902111-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 52DEF_ATTR_NULL_TREE (ATTR_NULL) 53 54/* Note that below we must avoid whitespace in arguments of CONCAT*. */ 55 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) 61DEF_ATTR_FOR_INT (0) 62DEF_ATTR_FOR_INT (1) 63DEF_ATTR_FOR_INT (2) 64DEF_ATTR_FOR_INT (3) 65DEF_ATTR_FOR_INT (4) 66#undef DEF_ATTR_FOR_INT 67 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)) 72DEF_LIST_INT_INT (1,0) 73DEF_LIST_INT_INT (1,2) 74DEF_LIST_INT_INT (1,3) 75DEF_LIST_INT_INT (2,0) 76DEF_LIST_INT_INT (2,3) 77DEF_LIST_INT_INT (3,0) 78DEF_LIST_INT_INT (3,2) 79DEF_LIST_INT_INT (3,4) 80DEF_LIST_INT_INT (1,3_2) 81#undef DEF_LIST_INT_INT 82 83/* Construct tress for identifiers. */ 84DEF_ATTR_IDENT (ATTR_BOUNDED, "bounded") 85DEF_ATTR_IDENT (ATTR_BUFFER, "buffer") 86DEF_ATTR_IDENT (ATTR_CONST, "const") 87DEF_ATTR_IDENT (ATTR_FORMAT, "format") 88DEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg") 89DEF_ATTR_IDENT (ATTR_MALLOC, "malloc") 90DEF_ATTR_IDENT (ATTR_NONNULL, "nonnull") 91DEF_ATTR_IDENT (ATTR_NORETURN, "noreturn") 92DEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow") 93DEF_ATTR_IDENT (ATTR_PRINTF, "printf") 94DEF_ATTR_IDENT (ATTR_PURE, "pure") 95DEF_ATTR_IDENT (ATTR_SCANF, "scanf") 96DEF_ATTR_IDENT (ATTR_SIZE, "size") 97DEF_ATTR_IDENT (ATTR_STRFMON, "strfmon") 98DEF_ATTR_IDENT (ATTR_STRING, "string") 99DEF_ATTR_IDENT (ATTR_STRFTIME, "strftime") 100 101DEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL) 102 103DEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST, \ 104 ATTR_NULL, ATTR_NOTHROW_LIST) 105DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE, \ 106 ATTR_NULL, ATTR_NOTHROW_LIST) 107DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \ 108 ATTR_NULL, ATTR_NOTHROW_LIST) 109DEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \ 110 ATTR_NULL, ATTR_NOTHROW_LIST) 111 112DEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \ 113 ATTR_NOTHROW_LIST) 114DEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \ 115 ATTR_NOTHROW_LIST) 116DEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \ 117 ATTR_NOTHROW_LIST) 118 119/* Construct a tree for a format attribute. */ 120#define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \ 121 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NULL, \ 122 CONCAT2 (ATTR_,TYPE), CONCAT2 (ATTR_LIST_,VALUES)) \ 123 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_FORMAT_,TYPE,_,VALUES), ATTR_FORMAT, \ 124 CONCAT4 (ATTR_,TYPE,_,VALUES), CONCAT2 (ATTR_NONNULL_,FA)) 125DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0) 126DEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2) 127DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_0) 128DEF_FORMAT_ATTRIBUTE(PRINTF,2,2_3) 129DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_0) 130DEF_FORMAT_ATTRIBUTE(PRINTF,3,3_4) 131DEF_FORMAT_ATTRIBUTE(SCANF,1,1_0) 132DEF_FORMAT_ATTRIBUTE(SCANF,1,1_2) 133DEF_FORMAT_ATTRIBUTE(SCANF,2,2_0) 134DEF_FORMAT_ATTRIBUTE(SCANF,2,2_3) 135DEF_FORMAT_ATTRIBUTE(STRFTIME,3,3_0) 136DEF_FORMAT_ATTRIBUTE(STRFMON,3,3_4) 137#undef DEF_FORMAT_ATTRIBUTE 138 139/* Construct a tree for a format_arg attribute. */ 140#define DEF_FORMAT_ARG_ATTRIBUTE(FA) \ 141 DEF_ATTR_TREE_LIST (CONCAT2 (ATTR_FORMAT_ARG_,FA), ATTR_FORMAT_ARG, \ 142 CONCAT2 (ATTR_LIST_,FA), CONCAT2 (ATTR_NONNULL_,FA)) 143DEF_FORMAT_ARG_ATTRIBUTE(1) 144DEF_FORMAT_ARG_ATTRIBUTE(2) 145#undef DEF_FORMAT_ARG_ATTRIBUTE 146 147/* Construct a tree for a bounded attribute. */ 148 149/* Generate a fragment for future use in a bounded attr, e.g. ATTR_BUFFER_2_3 */ 150#define DEF_ATTR_BOUNDED_FRAG(TYPE, VALUES) \ 151 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NULL, \ 152 CONCAT2 (ATTR_,TYPE), CONCAT2 (ATTR_LIST_,VALUES)) 153/* Create bounded attribute chained to nothrow, e.g. of the 154 form ATTR_NOTHROW_BOUNDED_BUFFER_2_3 */ 155#define DEF_NOTHROW_BOUNDED_ATTRIBUTE(TYPE, VALUES) \ 156 DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_NOTHROW_BOUNDED_,TYPE,_,VALUES), ATTR_BOUNDED, \ 157 CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NOTHROW_LIST) 158/* Chain multiple nothrow bounded buffer attributes together */ 159#define DEF_MULTIPLE_NOTHROW_BOUNDED_BUFFER_ATTRIBUTE(VAL1,VAL2) \ 160 DEF_ATTR_TREE_LIST (CONCAT4(ATTR_NOTHROW_BOUNDED_BUFFER_,VAL1,_,VAL2),ATTR_BOUNDED,\ 161 CONCAT2(ATTR_BUFFER_,VAL1), \ 162 CONCAT2(ATTR_NOTHROW_BOUNDED_BUFFER_,VAL2)) 163/* Chain a bounded attribute to a format printf attribute */ 164#define DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(TYPE, VALUES, PREPEND,PRINTVALS) \ 165 DEF_ATTR_TREE_LIST (CONCAT4 (PREPEND,TYPE,_,VALUES), \ 166 ATTR_BOUNDED, CONCAT4 (ATTR_,TYPE,_,VALUES), \ 167 CONCAT2(ATTR_FORMAT_PRINTF_,PRINTVALS)) 168DEF_ATTR_BOUNDED_FRAG(BUFFER,1_2) 169DEF_ATTR_BOUNDED_FRAG(BUFFER,1_3) 170DEF_ATTR_BOUNDED_FRAG(BUFFER,2_3) 171DEF_ATTR_BOUNDED_FRAG(SIZE,1_3_2) 172DEF_ATTR_BOUNDED_FRAG(STRING,1_2) 173DEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,1_2) 174DEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,1_3) 175DEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,2_3) 176DEF_NOTHROW_BOUNDED_ATTRIBUTE(SIZE,1_3_2) 177DEF_MULTIPLE_NOTHROW_BOUNDED_BUFFER_ATTRIBUTE(2_3,1_3) 178DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(STRING,1_2,ATTR_PRINTF_3_4_BOUNDED_,3_4) 179DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(STRING,1_2,ATTR_PRINTF_3_0_BOUNDED_,3_0) 180 181#undef DEF_ATTR_BOUNDED_FRAG 182#undef DEF_NOTHROW_BOUNDED_ATTRIBUTE 183#undef DEF_MULTIPLE_NOTHROW_BOUNDED_ATTRIBUTE 184#undef DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE 185 186/* Define an attribute for a function, along with the IDENTIFIER_NODE. */ 187#define DEF_FN_ATTR_IDENT(NAME, ATTRS, PREDICATE) \ 188 DEF_ATTR_IDENT (CONCAT2(ATTR_,NAME), STRINGX(NAME)) \ 189 DEF_FN_ATTR (CONCAT2(ATTR_,NAME), ATTRS, PREDICATE) 190 191/* The ISO C functions are always checked (whether <stdio.h> is 192 included or not), since it is common to call printf without 193 including <stdio.h>. There shouldn't be a problem with this, 194 since ISO C reserves these function names whether you include the 195 header file or not. In any case, the checking is harmless. With 196 -ffreestanding, these default attributes are disabled, and must be 197 specified manually if desired. */ 198 199/* Functions from ISO/IEC 9899:1990. */ 200#define DEF_C89_ATTR(NAME, ATTRS) DEF_FN_ATTR_IDENT (NAME, ATTRS, flag_hosted) 201DEF_C89_ATTR (fscanf, ATTR_FORMAT_SCANF_2_3) 202DEF_C89_ATTR (vfprintf, ATTR_FORMAT_PRINTF_2_0) 203DEF_C89_ATTR (strftime, ATTR_FORMAT_STRFTIME_3_0) 204#undef DEF_C89_ATTR 205 206/* ISO C99 adds the snprintf and vscanf family functions. */ 207#define DEF_C99_ATTR(NAME, ATTRS) \ 208 DEF_FN_ATTR_IDENT (NAME, ATTRS, \ 209 (flag_hosted \ 210 && (flag_isoc99 || flag_noniso_default_format_attributes))) 211DEF_C99_ATTR (vfscanf, ATTR_FORMAT_SCANF_2_0) 212#undef DEF_C99_ATTR 213#undef DEF_FN_ATTR_IDENT 214