]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/attribs.h
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / attribs.h
index 06e6993e95820b12a0cb7a32a59b9ac47881b56e..138c509bce13df8b01953483fd82de6c62b2b836 100644 (file)
@@ -1,5 +1,5 @@
 /* Declarations and definitions dealing with attribute handling.
-   Copyright (C) 2013-2017 Free Software Foundation, Inc.
+   Copyright (C) 2013-2021 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -31,10 +31,11 @@ extern void init_attributes (void);
    from tree.h.  Depending on these flags, some attributes may be
    returned to be applied at a later stage (for example, to apply
    a decl attribute to the declaration rather than to its type).  */
-extern tree decl_attributes (tree *, tree, int);
+extern tree decl_attributes (tree *, tree, int, tree = NULL_TREE);
 
 extern bool cxx11_attribute_p (const_tree);
 extern tree get_attribute_name (const_tree);
+extern tree get_attribute_namespace (const_tree);
 extern void apply_tm_attr (tree, tree);
 extern tree make_attribute (const char *, const char *, tree);
 
@@ -43,7 +44,6 @@ extern struct scoped_attributes* register_scoped_attributes (const struct attrib
 
 extern char *sorted_attr_string (tree);
 extern bool common_function_versions (tree, tree);
-extern char *make_unique_name (tree, const char *, bool);
 extern tree make_dispatcher_decl (const tree);
 extern bool is_function_default_version (const tree);
 
@@ -64,6 +64,9 @@ extern bool attribute_value_equal (const_tree, const_tree);
    warning to be generated).  */
 extern int comp_type_attributes (const_tree, const_tree);
 
+extern tree affects_type_identity_attributes (tree, bool = true);
+extern tree restrict_type_identity_attributes_to (tree, tree);
+
 /* Default versions of target-overridable functions.  */
 extern tree merge_decl_attributes (tree, tree);
 extern tree merge_type_attributes (tree, tree);
@@ -77,6 +80,16 @@ extern tree remove_attribute (const char *, tree);
 
 extern tree merge_attributes (tree, tree);
 
+/* Duplicate all attributes with name NAME in ATTR list to *ATTRS if
+   they are missing there.  */
+
+extern void duplicate_one_attribute (tree *, tree, const char *);
+
+/* Duplicate all attributes from user DECL to the corresponding
+   builtin that should be propagated.  */
+
+extern void copy_attributes_to_builtin (tree);
+
 /* Given two Windows decl attributes lists, possibly including
    dllimport, return a list of their union .  */
 extern tree merge_dllimport_decl_attributes (tree, tree);
@@ -87,6 +100,20 @@ extern tree handle_dll_attribute (tree *, tree, tree, int, bool *);
 extern int attribute_list_equal (const_tree, const_tree);
 extern int attribute_list_contained (const_tree, const_tree);
 
+/* The backbone of lookup_attribute().  ATTR_LEN is the string length
+   of ATTR_NAME, and LIST is not NULL_TREE.
+
+   The function is called from lookup_attribute in order to optimize
+   for size.  */
+extern tree private_lookup_attribute (const char *attr_name, size_t attr_len,
+                                     tree list);
+
+extern unsigned decls_mismatched_attributes (tree, tree, tree,
+                                            const char* const[],
+                                            pretty_printer*);
+
+extern void maybe_diag_alias_attributes (tree, tree);
+
 /* For a given IDENTIFIER_NODE, strip leading and trailing '_' characters
    so that we have a canonical form of attribute names.  */
 
@@ -151,17 +178,7 @@ lookup_attribute (const char *attr_name, tree list)
       /* Do the strlen() before calling the out-of-line implementation.
         In most cases attr_name is a string constant, and the compiler
         will optimize the strlen() away.  */
-      while (list)
-       {
-         tree attr = get_attribute_name (list);
-         size_t ident_len = IDENTIFIER_LENGTH (attr);
-         if (cmp_attribs (attr_name, attr_len, IDENTIFIER_POINTER (attr),
-                          ident_len))
-           break;
-         list = TREE_CHAIN (list);
-       }
-
-      return list;
+      return private_lookup_attribute (attr_name, attr_len, list);
     }
 }
 
@@ -203,4 +220,99 @@ lookup_attribute_by_prefix (const char *attr_name, tree list)
     }
 }
 
+/* Description of a function argument declared with attribute access.
+   Used as an "iterator" over all such arguments in a function declaration
+   or call.  */
+
+struct attr_access
+{
+  /* The beginning and end of the internal string representation.  */
+  const char *str, *end;
+  /* The attribute pointer argument.  */
+  tree ptr;
+  /* For a declaration, a TREE_CHAIN of VLA bound expressions stored
+     in TREE_VALUE and their positions in the argument list (stored
+     in TREE_PURPOSE).  Each expression may be a PARM_DECL or some
+     other DECL (for ordinary variables), or an EXPR for other
+     expressions (e.g., funcion calls).  */
+  tree size;
+
+  /* The zero-based position of each of the formal function arguments.
+     For the optional SIZARG, UINT_MAX when not specified.  For VLAs
+     with multiple variable bounds, SIZARG is the position corresponding
+     to the most significant bound in the argument list.  Positions of
+     subsequent bounds are in the TREE_PURPOSE field of the SIZE chain.  */
+  unsigned ptrarg;
+  unsigned sizarg;
+  /* For internal specifications only, the constant minimum size of
+     the array, zero if not specified, and HWI_M1U for the unspecified
+     VLA [*] notation.  Meaningless for external (explicit) access
+     specifications.  */
+  unsigned HOST_WIDE_INT minsize;
+
+  /* The access mode.  */
+  access_mode mode;
+
+  /* Set for an attribute added internally rather than by an explicit
+     declaration. */
+  bool internal_p;
+  /* Set for the T[static MINSIZE] array notation for nonzero MINSIZE
+     less than HWI_M1U.  */
+  bool static_p;
+
+  /* Return the number of specified VLA bounds.  */
+  unsigned vla_bounds (unsigned *) const;
+
+  /* Return internal representation as STRING_CST.  */
+  tree to_internal_string () const;
+
+  /* Return the human-readable representation of the external attribute
+     specification (as it might appear in the source code) as STRING_CST.  */
+  tree to_external_string () const;
+
+  /* Return argument of array type formatted as a readable string.  */
+  std::string array_as_string (tree) const;
+
+  /* Return the access mode corresponding to the character code.  */
+  static access_mode from_mode_char (char);
+
+  /* Reset front end-specific attribute access data from attributes.  */
+  static void free_lang_data (tree);
+
+  /* The character codes corresponding to all the access modes.  */
+  static constexpr char mode_chars[5] = { '-', 'r', 'w', 'x', '^' };
+
+  /* The strings corresponding to just the external access modes.  */
+  static constexpr char mode_names[4][11] =
+    {
+     "none", "read_only", "write_only", "read_write"
+    };
+};
+
+inline access_mode
+attr_access::from_mode_char (char c)
+{
+  switch (c)
+    {
+    case mode_chars[access_none]: return access_none;
+    case mode_chars[access_read_only]: return access_read_only;
+    case mode_chars[access_write_only]: return access_write_only;
+    case mode_chars[access_read_write]: return access_read_write;
+    case mode_chars[access_deferred]: return access_deferred;
+    }
+  gcc_unreachable ();
+}
+
+/* Used to define rdwr_map below.  */
+struct rdwr_access_hash: int_hash<int, -1> { };
+
+/* A mapping between argument number corresponding to attribute access
+   mode (read_only, write_only, or read_write) and operands.  */
+struct attr_access;
+typedef hash_map<rdwr_access_hash, attr_access> rdwr_map;
+
+extern void init_attr_rdwr_indices (rdwr_map *, tree);
+extern attr_access *get_parm_access (rdwr_map &, tree,
+                                    tree = current_function_decl);
+
 #endif // GCC_ATTRIBS_H