b825a22890
PR middle-end/10138 - warn for uninitialized arrays passed as const arguments PR middle-end/95136 - missing -Wuninitialized on an array access with a variable offset gcc/c-family/ChangeLog: PR middle-end/10138 PR middle-end/95136 * c-attribs.c (append_access_attrs): Handle attr_access::none. (handle_access_attribute): Same. gcc/ChangeLog: PR middle-end/10138 PR middle-end/95136 * attribs.c (init_attr_rdwr_indices): Move function here. * attribs.h (rdwr_access_hash, rdwr_map): Define. (attr_access): Add 'none'. (init_attr_rdwr_indices): Declared function. * builtins.c (warn_for_access)): New function. (check_access): Call it. * builtins.h (checK-access): Add an optional argument. * calls.c (rdwr_access_hash, rdwr_map): Move to attribs.h. (init_attr_rdwr_indices): Declare extern. (append_attrname): Handle attr_access::none. (maybe_warn_rdwr_sizes): Same. (initialize_argument_information): Update comments. * doc/extend.texi (attribute access): Document 'none'. * tree-ssa-uninit.c (struct wlimits): New. (maybe_warn_operand): New function. (maybe_warn_pass_by_reference): Same. (warn_uninitialized_vars): Refactor code into maybe_warn_operand. Also call for function calls. (pass_late_warn_uninitialized::execute): Adjust comments. (execute_early_warn_uninitialized): Same. gcc/testsuite/ChangeLog: PR middle-end/10138 PR middle-end/95136 * c-c++-common/Wsizeof-pointer-memaccess1.c: Prune out valid Wuninitialized. * c-c++-common/uninit-pr51010.c: Adjust expected warning format. * c-c++-common/goacc/uninit-dim-clause.c: Same. * c-c++-common/goacc/uninit-firstprivate-clause.c: Same. * c-c++-common/goacc/uninit-if-clause.c: Same. * c-c++-common/gomp/pr70550-1.c: Same. * c-c++-common/gomp/pr70550-2.c: Adjust. * g++.dg/20090107-1.C: Same. * g++.dg/20090121-1.C: Same. * g++.dg/ext/attr-access.C: Avoid -Wuninitialized. * gcc.dg/tree-ssa/forwprop-6.c: Prune out -Wuninitialized. * gcc.dg/Warray-bounds-52.c: Prune out valid -Wuninitialized. * gcc.dg/Warray-bounds-53.c: Same. * gcc.dg/Warray-bounds-54.c: Same. * gcc.dg/Wstringop-overflow-33.c: New test. * gcc.dg/attr-access-none.c: New test. * gcc.dg/attr-access-read-only.c: Adjust. * gcc.dg/attr-access-read-write.c: Same. * gcc.dg/attr-access-write-only.c: Same. * gcc.dg/pr71581.c: Adjust text of expected warning. * gcc.dg/uninit-15.c: Same. * gcc.dg/uninit-32.c: New test. * gcc.dg/uninit-33.c: New test. * gcc.dg/uninit-34.c: New test. * gcc.dg/uninit-36.c: New test. * gcc.dg/uninit-B-O0.c: Adjust text of expected warning. * gcc.dg/uninit-I-O0.c: Same. * gcc.dg/uninit-pr19430-O0.c: Same. * gcc.dg/uninit-pr19430.c: Same. * gcc.dg/uninit-pr95136.c: New test. * gfortran.dg/assignment_4.f90: Expect -Wuninitialized. * gfortran.dg/goacc/uninit-dim-clause.f95: Adjust text of expected warning. * gfortran.dg/goacc/uninit-firstprivate-clause.f95 * gfortran.dg/goacc/uninit-if-clause.f95 * gfortran.dg/pr66545_2.f90
252 lines
8.3 KiB
C
252 lines
8.3 KiB
C
/* Declarations and definitions dealing with attribute handling.
|
|
Copyright (C) 2013-2020 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GCC_ATTRIBS_H
|
|
#define GCC_ATTRIBS_H
|
|
|
|
extern const struct attribute_spec *lookup_attribute_spec (const_tree);
|
|
extern void init_attributes (void);
|
|
|
|
/* Process the attributes listed in ATTRIBUTES and install them in *NODE,
|
|
which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL,
|
|
it should be modified in place; if a TYPE, a copy should be created
|
|
unless ATTR_FLAG_TYPE_IN_PLACE is set in FLAGS. FLAGS gives further
|
|
information, in the form of a bitwise OR of flags in enum attribute_flags
|
|
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, 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);
|
|
|
|
extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *,
|
|
const char *);
|
|
|
|
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);
|
|
|
|
/* Return a type like TTYPE except that its TYPE_ATTRIBUTES
|
|
is ATTRIBUTE.
|
|
|
|
Such modified types already made are recorded so that duplicates
|
|
are not made. */
|
|
|
|
extern tree build_type_attribute_variant (tree, tree);
|
|
extern tree build_decl_attribute_variant (tree, tree);
|
|
extern tree build_type_attribute_qual_variant (tree, tree, int);
|
|
|
|
extern bool attribute_value_equal (const_tree, const_tree);
|
|
|
|
/* Return 0 if the attributes for two types are incompatible, 1 if they
|
|
are compatible, and 2 if they are nearly compatible (which causes a
|
|
warning to be generated). */
|
|
extern int comp_type_attributes (const_tree, const_tree);
|
|
|
|
/* Default versions of target-overridable functions. */
|
|
extern tree merge_decl_attributes (tree, tree);
|
|
extern tree merge_type_attributes (tree, tree);
|
|
|
|
/* Remove any instances of attribute ATTR_NAME in LIST and return the
|
|
modified list. */
|
|
|
|
extern tree remove_attribute (const char *, tree);
|
|
|
|
/* Given two attributes lists, return a list of their union. */
|
|
|
|
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);
|
|
|
|
/* Handle a "dllimport" or "dllexport" attribute. */
|
|
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. */
|
|
|
|
static inline tree
|
|
canonicalize_attr_name (tree attr_name)
|
|
{
|
|
const size_t l = IDENTIFIER_LENGTH (attr_name);
|
|
const char *s = IDENTIFIER_POINTER (attr_name);
|
|
|
|
if (l > 4 && s[0] == '_' && s[1] == '_' && s[l - 1] == '_' && s[l - 2] == '_')
|
|
return get_identifier_with_length (s + 2, l - 4);
|
|
|
|
return attr_name;
|
|
}
|
|
|
|
/* Compare attribute identifiers ATTR1 and ATTR2 with length ATTR1_LEN and
|
|
ATTR2_LEN. */
|
|
|
|
static inline bool
|
|
cmp_attribs (const char *attr1, size_t attr1_len,
|
|
const char *attr2, size_t attr2_len)
|
|
{
|
|
return attr1_len == attr2_len && strncmp (attr1, attr2, attr1_len) == 0;
|
|
}
|
|
|
|
/* Compare attribute identifiers ATTR1 and ATTR2. */
|
|
|
|
static inline bool
|
|
cmp_attribs (const char *attr1, const char *attr2)
|
|
{
|
|
return cmp_attribs (attr1, strlen (attr1), attr2, strlen (attr2));
|
|
}
|
|
|
|
/* Given an identifier node IDENT and a string ATTR_NAME, return true
|
|
if the identifier node is a valid attribute name for the string. */
|
|
|
|
static inline bool
|
|
is_attribute_p (const char *attr_name, const_tree ident)
|
|
{
|
|
return cmp_attribs (attr_name, strlen (attr_name),
|
|
IDENTIFIER_POINTER (ident), IDENTIFIER_LENGTH (ident));
|
|
}
|
|
|
|
/* Given an attribute name ATTR_NAME and a list of attributes LIST,
|
|
return a pointer to the attribute's list element if the attribute
|
|
is part of the list, or NULL_TREE if not found. If the attribute
|
|
appears more than once, this only returns the first occurrence; the
|
|
TREE_CHAIN of the return value should be passed back in if further
|
|
occurrences are wanted. ATTR_NAME must be in the form 'text' (not
|
|
'__text__'). */
|
|
|
|
static inline tree
|
|
lookup_attribute (const char *attr_name, tree list)
|
|
{
|
|
gcc_checking_assert (attr_name[0] != '_');
|
|
/* In most cases, list is NULL_TREE. */
|
|
if (list == NULL_TREE)
|
|
return NULL_TREE;
|
|
else
|
|
{
|
|
size_t attr_len = strlen (attr_name);
|
|
/* 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. */
|
|
return private_lookup_attribute (attr_name, attr_len, list);
|
|
}
|
|
}
|
|
|
|
/* Given an attribute name ATTR_NAME and a list of attributes LIST,
|
|
return a pointer to the attribute's list first element if the attribute
|
|
starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
|
|
'__text__'). */
|
|
|
|
static inline tree
|
|
lookup_attribute_by_prefix (const char *attr_name, tree list)
|
|
{
|
|
gcc_checking_assert (attr_name[0] != '_');
|
|
/* In most cases, list is NULL_TREE. */
|
|
if (list == NULL_TREE)
|
|
return NULL_TREE;
|
|
else
|
|
{
|
|
size_t attr_len = strlen (attr_name);
|
|
while (list)
|
|
{
|
|
size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list));
|
|
|
|
if (attr_len > ident_len)
|
|
{
|
|
list = TREE_CHAIN (list);
|
|
continue;
|
|
}
|
|
|
|
const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
|
|
gcc_checking_assert (attr_len == 0 || p[0] != '_');
|
|
|
|
if (strncmp (attr_name, p, attr_len) == 0)
|
|
break;
|
|
|
|
list = TREE_CHAIN (list);
|
|
}
|
|
|
|
return 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 attribute pointer argument. */
|
|
tree ptr;
|
|
/* The size of the pointed-to object or NULL when not specified. */
|
|
tree size;
|
|
|
|
/* The zero-based number of each of the formal function arguments. */
|
|
unsigned ptrarg;
|
|
unsigned sizarg;
|
|
|
|
/* The access mode. */
|
|
enum access_mode { none, read_only, write_only, read_write };
|
|
access_mode mode;
|
|
};
|
|
|
|
/* 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);
|
|
|
|
#endif // GCC_ATTRIBS_H
|