1c87b03e5Sespie/* Copyright (C) 2001, 2002 Free Software Foundation, Inc. 2c87b03e5Sespie Contributed by Joseph Myers <jsm28@cam.ac.uk>. 3c87b03e5Sespie 4c87b03e5SespieThis file is part of GCC. 5c87b03e5Sespie 6c87b03e5SespieGCC is free software; you can redistribute it and/or modify it under 7c87b03e5Sespiethe terms of the GNU General Public License as published by the Free 8c87b03e5SespieSoftware Foundation; either version 2, or (at your option) any later 9c87b03e5Sespieversion. 10c87b03e5Sespie 11c87b03e5SespieGCC is distributed in the hope that it will be useful, but WITHOUT ANY 12c87b03e5SespieWARRANTY; without even the implied warranty of MERCHANTABILITY or 13c87b03e5SespieFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14c87b03e5Sespiefor more details. 15c87b03e5Sespie 16c87b03e5SespieYou should have received a copy of the GNU General Public License 17c87b03e5Sespiealong with GCC; see the file COPYING. If not, write to the Free 18c87b03e5SespieSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 19c87b03e5Sespie02111-1307, USA. */ 20c87b03e5Sespie 21c87b03e5Sespie/* This header provides a declarative way of describing the attributes 22c87b03e5Sespie that are applied to some functions by default. 23c87b03e5Sespie 24c87b03e5Sespie Before including this header, you must define the following macros. 25c87b03e5Sespie In each case where there is an ENUM, it is an identifier used to 26c87b03e5Sespie reference the tree in subsequent definitions. 27c87b03e5Sespie 28c87b03e5Sespie DEF_ATTR_NULL_TREE (ENUM) 29c87b03e5Sespie 30c87b03e5Sespie Constructs a NULL_TREE. 31c87b03e5Sespie 32c87b03e5Sespie DEF_ATTR_INT (ENUM, VALUE) 33c87b03e5Sespie 34c87b03e5Sespie Constructs an INTEGER_CST with value VALUE (an integer representable 35c87b03e5Sespie in HOST_WIDE_INT). 36c87b03e5Sespie 37c87b03e5Sespie DEF_ATTR_IDENT (ENUM, STRING) 38c87b03e5Sespie 39c87b03e5Sespie Constructs an IDENTIFIER_NODE for STRING. 40c87b03e5Sespie 41c87b03e5Sespie DEF_ATTR_TREE_LIST (ENUM, PURPOSE, VALUE, CHAIN) 42c87b03e5Sespie 43c87b03e5Sespie Constructs a TREE_LIST with given PURPOSE, VALUE and CHAIN (given 44c87b03e5Sespie as previous ENUM names). 45c87b03e5Sespie 46c87b03e5Sespie DEF_FN_ATTR (NAME, ATTRS, PREDICATE) 47c87b03e5Sespie 48c87b03e5Sespie Specifies that the function with name NAME (a previous ENUM for an 49c87b03e5Sespie IDENTIFIER_NODE) has attributes ATTRS (a previous ENUM) if 50c87b03e5Sespie PREDICATE is true. */ 51c87b03e5Sespie 52c87b03e5SespieDEF_ATTR_NULL_TREE (ATTR_NULL) 53c87b03e5Sespie 54c87b03e5Sespie/* Note that below we must avoid whitespace in arguments of CONCAT*. */ 55c87b03e5Sespie 56c87b03e5Sespie/* Construct a tree for a given integer and a list containing it. */ 57c87b03e5Sespie#define DEF_ATTR_FOR_INT(VALUE) \ 58c87b03e5Sespie DEF_ATTR_INT (CONCAT2 (ATTR_,VALUE), VALUE) \ 59c87b03e5Sespie DEF_ATTR_TREE_LIST (CONCAT2 (ATTR_LIST_,VALUE), ATTR_NULL, \ 60c87b03e5Sespie CONCAT2 (ATTR_,VALUE), ATTR_NULL) 61c87b03e5SespieDEF_ATTR_FOR_INT (0) 62c87b03e5SespieDEF_ATTR_FOR_INT (1) 63c87b03e5SespieDEF_ATTR_FOR_INT (2) 64c87b03e5SespieDEF_ATTR_FOR_INT (3) 65c87b03e5SespieDEF_ATTR_FOR_INT (4) 66c87b03e5Sespie#undef DEF_ATTR_FOR_INT 67c87b03e5Sespie 68c87b03e5Sespie/* Construct a tree for a list of two integers. */ 69c87b03e5Sespie#define DEF_LIST_INT_INT(VALUE1, VALUE2) \ 70c87b03e5Sespie DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_LIST_,VALUE1,_,VALUE2), ATTR_NULL, \ 71c87b03e5Sespie CONCAT2 (ATTR_,VALUE1), CONCAT2 (ATTR_LIST_,VALUE2)) 72c87b03e5SespieDEF_LIST_INT_INT (1,0) 73c87b03e5SespieDEF_LIST_INT_INT (1,2) 74*cd3be6e5SavsmDEF_LIST_INT_INT (1,3) 75c87b03e5SespieDEF_LIST_INT_INT (2,0) 76c87b03e5SespieDEF_LIST_INT_INT (2,3) 77c87b03e5SespieDEF_LIST_INT_INT (3,0) 78*cd3be6e5SavsmDEF_LIST_INT_INT (3,2) 79c87b03e5SespieDEF_LIST_INT_INT (3,4) 80*cd3be6e5SavsmDEF_LIST_INT_INT (1,3_2) 81c87b03e5Sespie#undef DEF_LIST_INT_INT 82c87b03e5Sespie 83c87b03e5Sespie/* Construct tress for identifiers. */ 84*cd3be6e5SavsmDEF_ATTR_IDENT (ATTR_BOUNDED, "bounded") 85*cd3be6e5SavsmDEF_ATTR_IDENT (ATTR_BUFFER, "buffer") 86c87b03e5SespieDEF_ATTR_IDENT (ATTR_CONST, "const") 87c87b03e5SespieDEF_ATTR_IDENT (ATTR_FORMAT, "format") 88c87b03e5SespieDEF_ATTR_IDENT (ATTR_FORMAT_ARG, "format_arg") 89c87b03e5SespieDEF_ATTR_IDENT (ATTR_MALLOC, "malloc") 90c87b03e5SespieDEF_ATTR_IDENT (ATTR_NONNULL, "nonnull") 91c87b03e5SespieDEF_ATTR_IDENT (ATTR_NORETURN, "noreturn") 92c87b03e5SespieDEF_ATTR_IDENT (ATTR_NOTHROW, "nothrow") 93c87b03e5SespieDEF_ATTR_IDENT (ATTR_PRINTF, "printf") 94c87b03e5SespieDEF_ATTR_IDENT (ATTR_PURE, "pure") 95c87b03e5SespieDEF_ATTR_IDENT (ATTR_SCANF, "scanf") 96*cd3be6e5SavsmDEF_ATTR_IDENT (ATTR_SIZE, "size") 97c87b03e5SespieDEF_ATTR_IDENT (ATTR_STRFMON, "strfmon") 98*cd3be6e5SavsmDEF_ATTR_IDENT (ATTR_STRING, "string") 99c87b03e5SespieDEF_ATTR_IDENT (ATTR_STRFTIME, "strftime") 100c87b03e5Sespie 101c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_NOTHROW_LIST, ATTR_NOTHROW, ATTR_NULL, ATTR_NULL) 102c87b03e5Sespie 103c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_CONST_NOTHROW_LIST, ATTR_CONST, \ 104c87b03e5Sespie ATTR_NULL, ATTR_NOTHROW_LIST) 105c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE, \ 106c87b03e5Sespie ATTR_NULL, ATTR_NOTHROW_LIST) 107c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \ 108c87b03e5Sespie ATTR_NULL, ATTR_NOTHROW_LIST) 109c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_MALLOC_NOTHROW_LIST, ATTR_MALLOC, \ 110c87b03e5Sespie ATTR_NULL, ATTR_NOTHROW_LIST) 111c87b03e5Sespie 112c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_NONNULL_1, ATTR_NONNULL, ATTR_LIST_1, \ 113c87b03e5Sespie ATTR_NOTHROW_LIST) 114c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_NONNULL_2, ATTR_NONNULL, ATTR_LIST_2, \ 115c87b03e5Sespie ATTR_NOTHROW_LIST) 116c87b03e5SespieDEF_ATTR_TREE_LIST (ATTR_NONNULL_3, ATTR_NONNULL, ATTR_LIST_3, \ 117c87b03e5Sespie ATTR_NOTHROW_LIST) 118c87b03e5Sespie 119c87b03e5Sespie/* Construct a tree for a format attribute. */ 120c87b03e5Sespie#define DEF_FORMAT_ATTRIBUTE(TYPE, FA, VALUES) \ 121c87b03e5Sespie DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NULL, \ 122c87b03e5Sespie CONCAT2 (ATTR_,TYPE), CONCAT2 (ATTR_LIST_,VALUES)) \ 123c87b03e5Sespie DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_FORMAT_,TYPE,_,VALUES), ATTR_FORMAT, \ 124c87b03e5Sespie CONCAT4 (ATTR_,TYPE,_,VALUES), CONCAT2 (ATTR_NONNULL_,FA)) 125c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,1,1_0) 126c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,1,1_2) 127c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,2,2_0) 128c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,2,2_3) 129c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,3,3_0) 130c87b03e5SespieDEF_FORMAT_ATTRIBUTE(PRINTF,3,3_4) 131c87b03e5SespieDEF_FORMAT_ATTRIBUTE(SCANF,1,1_0) 132c87b03e5SespieDEF_FORMAT_ATTRIBUTE(SCANF,1,1_2) 133c87b03e5SespieDEF_FORMAT_ATTRIBUTE(SCANF,2,2_0) 134c87b03e5SespieDEF_FORMAT_ATTRIBUTE(SCANF,2,2_3) 135c87b03e5SespieDEF_FORMAT_ATTRIBUTE(STRFTIME,3,3_0) 136c87b03e5SespieDEF_FORMAT_ATTRIBUTE(STRFMON,3,3_4) 137c87b03e5Sespie#undef DEF_FORMAT_ATTRIBUTE 138c87b03e5Sespie 139c87b03e5Sespie/* Construct a tree for a format_arg attribute. */ 140c87b03e5Sespie#define DEF_FORMAT_ARG_ATTRIBUTE(FA) \ 141c87b03e5Sespie DEF_ATTR_TREE_LIST (CONCAT2 (ATTR_FORMAT_ARG_,FA), ATTR_FORMAT_ARG, \ 142c87b03e5Sespie CONCAT2 (ATTR_LIST_,FA), CONCAT2 (ATTR_NONNULL_,FA)) 143c87b03e5SespieDEF_FORMAT_ARG_ATTRIBUTE(1) 144c87b03e5SespieDEF_FORMAT_ARG_ATTRIBUTE(2) 145c87b03e5Sespie#undef DEF_FORMAT_ARG_ATTRIBUTE 146c87b03e5Sespie 147*cd3be6e5Savsm/* Construct a tree for a bounded attribute. */ 148*cd3be6e5Savsm 149*cd3be6e5Savsm/* Generate a fragment for future use in a bounded attr, e.g. ATTR_BUFFER_2_3 */ 150*cd3be6e5Savsm#define DEF_ATTR_BOUNDED_FRAG(TYPE, VALUES) \ 151*cd3be6e5Savsm DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NULL, \ 152*cd3be6e5Savsm CONCAT2 (ATTR_,TYPE), CONCAT2 (ATTR_LIST_,VALUES)) 153*cd3be6e5Savsm/* Create bounded attribute chained to nothrow, e.g. of the 154*cd3be6e5Savsm form ATTR_NOTHROW_BOUNDED_BUFFER_2_3 */ 155*cd3be6e5Savsm#define DEF_NOTHROW_BOUNDED_ATTRIBUTE(TYPE, VALUES) \ 156*cd3be6e5Savsm DEF_ATTR_TREE_LIST (CONCAT4 (ATTR_NOTHROW_BOUNDED_,TYPE,_,VALUES), ATTR_BOUNDED, \ 157*cd3be6e5Savsm CONCAT4 (ATTR_,TYPE,_,VALUES), ATTR_NOTHROW_LIST) 158*cd3be6e5Savsm/* Chain multiple nothrow bounded buffer attributes together */ 159*cd3be6e5Savsm#define DEF_MULTIPLE_NOTHROW_BOUNDED_BUFFER_ATTRIBUTE(VAL1,VAL2) \ 160*cd3be6e5Savsm DEF_ATTR_TREE_LIST (CONCAT4(ATTR_NOTHROW_BOUNDED_BUFFER_,VAL1,_,VAL2),ATTR_BOUNDED,\ 161*cd3be6e5Savsm CONCAT2(ATTR_BUFFER_,VAL1), \ 162*cd3be6e5Savsm CONCAT2(ATTR_NOTHROW_BOUNDED_BUFFER_,VAL2)) 163*cd3be6e5Savsm/* Chain a bounded attribute to a format printf attribute */ 164*cd3be6e5Savsm#define DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(TYPE, VALUES, PREPEND,PRINTVALS) \ 165*cd3be6e5Savsm DEF_ATTR_TREE_LIST (CONCAT4 (PREPEND,TYPE,_,VALUES), \ 166*cd3be6e5Savsm ATTR_BOUNDED, CONCAT4 (ATTR_,TYPE,_,VALUES), \ 167*cd3be6e5Savsm CONCAT2(ATTR_FORMAT_PRINTF_,PRINTVALS)) 168*cd3be6e5SavsmDEF_ATTR_BOUNDED_FRAG(BUFFER,1_2) 169*cd3be6e5SavsmDEF_ATTR_BOUNDED_FRAG(BUFFER,1_3) 170*cd3be6e5SavsmDEF_ATTR_BOUNDED_FRAG(BUFFER,2_3) 171*cd3be6e5SavsmDEF_ATTR_BOUNDED_FRAG(SIZE,1_3_2) 172*cd3be6e5SavsmDEF_ATTR_BOUNDED_FRAG(STRING,1_2) 173*cd3be6e5SavsmDEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,1_2) 174*cd3be6e5SavsmDEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,1_3) 175*cd3be6e5SavsmDEF_NOTHROW_BOUNDED_ATTRIBUTE(BUFFER,2_3) 176*cd3be6e5SavsmDEF_NOTHROW_BOUNDED_ATTRIBUTE(SIZE,1_3_2) 177*cd3be6e5SavsmDEF_MULTIPLE_NOTHROW_BOUNDED_BUFFER_ATTRIBUTE(2_3,1_3) 178*cd3be6e5SavsmDEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(STRING,1_2,ATTR_PRINTF_3_4_BOUNDED_,3_4) 179*cd3be6e5SavsmDEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE(STRING,1_2,ATTR_PRINTF_3_0_BOUNDED_,3_0) 180*cd3be6e5Savsm 181*cd3be6e5Savsm#undef DEF_ATTR_BOUNDED_FRAG 182*cd3be6e5Savsm#undef DEF_NOTHROW_BOUNDED_ATTRIBUTE 183*cd3be6e5Savsm#undef DEF_MULTIPLE_NOTHROW_BOUNDED_ATTRIBUTE 184*cd3be6e5Savsm#undef DEF_FORMAT_PRINTF_BOUNDED_ATTRIBUTE 185*cd3be6e5Savsm 186c87b03e5Sespie/* Define an attribute for a function, along with the IDENTIFIER_NODE. */ 187c87b03e5Sespie#define DEF_FN_ATTR_IDENT(NAME, ATTRS, PREDICATE) \ 188c87b03e5Sespie DEF_ATTR_IDENT (CONCAT2(ATTR_,NAME), STRINGX(NAME)) \ 189c87b03e5Sespie DEF_FN_ATTR (CONCAT2(ATTR_,NAME), ATTRS, PREDICATE) 190c87b03e5Sespie 191c87b03e5Sespie/* The ISO C functions are always checked (whether <stdio.h> is 192c87b03e5Sespie included or not), since it is common to call printf without 193c87b03e5Sespie including <stdio.h>. There shouldn't be a problem with this, 194c87b03e5Sespie since ISO C reserves these function names whether you include the 195c87b03e5Sespie header file or not. In any case, the checking is harmless. With 196c87b03e5Sespie -ffreestanding, these default attributes are disabled, and must be 197c87b03e5Sespie specified manually if desired. */ 198c87b03e5Sespie 199c87b03e5Sespie/* Functions from ISO/IEC 9899:1990. */ 200c87b03e5Sespie#define DEF_C89_ATTR(NAME, ATTRS) DEF_FN_ATTR_IDENT (NAME, ATTRS, flag_hosted) 201c87b03e5SespieDEF_C89_ATTR (fscanf, ATTR_FORMAT_SCANF_2_3) 202c87b03e5SespieDEF_C89_ATTR (vfprintf, ATTR_FORMAT_PRINTF_2_0) 203c87b03e5SespieDEF_C89_ATTR (strftime, ATTR_FORMAT_STRFTIME_3_0) 204c87b03e5Sespie#undef DEF_C89_ATTR 205c87b03e5Sespie 206c87b03e5Sespie/* ISO C99 adds the snprintf and vscanf family functions. */ 207c87b03e5Sespie#define DEF_C99_ATTR(NAME, ATTRS) \ 208c87b03e5Sespie DEF_FN_ATTR_IDENT (NAME, ATTRS, \ 209c87b03e5Sespie (flag_hosted \ 210c87b03e5Sespie && (flag_isoc99 || flag_noniso_default_format_attributes))) 211c87b03e5SespieDEF_C99_ATTR (vfscanf, ATTR_FORMAT_SCANF_2_0) 212c87b03e5Sespie#undef DEF_C99_ATTR 213c87b03e5Sespie#undef DEF_FN_ATTR_IDENT 214