From 54aa6b58fe2fe73bbe67e0485777e0c410a18673 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Fri, 22 Nov 2019 17:14:17 +0000 Subject: PR middle-end/83859 - attributes to associate pointer arguments and sizes gcc/ChangeLog: PR middle-end/83859 * attribs.h (struct attr_access): New. * attribs.c (decl_attributes): Add an informational note. * builtins.c (check_access): Make extern. Consistently set no-warning after issuing a warning. Handle calls through function pointers. Set no-warning. * builtins.h (check_access): Declare. * calls.c (rdwr_access_hash): New type. (rdwr_map): Same. (init_attr_rdwr_indices): New function. (maybe_warn_rdwr_sizes): Same. (initialize_argument_information): Call init_attr_rdwr_indices. Call maybe_warn_rdwr_sizes. (get_size_range): Avoid null argument. * doc/extend.texi (attribute access): Document new attribute. gcc/c-family/ChangeLog: PR middle-end/83859 * c-attribs.c (handle_access_attribute): New function. (c_common_attribute_table): Add new attribute. (get_argument_type): New function. (append_access_attrs): New function. (get_nonnull_operand): Rename... (get_attribute_operand): ...to this. * c-common.c (get_nonnull_operand): Rename... (get_attribute_operand): ...to this. gcc/testsuite/ChangeLog: PR middle-end/83859 * c-c++-common/attr-nonstring-8.c: Adjust text of expected warning. * gcc.dg/Wstringop-overflow-23.c: New test. * gcc.dg/Wstringop-overflow-24.c: New test. * gcc.dg/attr-access-read-only.c: New test. * gcc.dg/attr-access-read-write.c: New test. * gcc.dg/attr-access-read-write-2.c: New test. * gcc.dg/attr-access-write-only.c: New test. From-SVN: r278624 --- gcc/attribs.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'gcc/attribs.h') diff --git a/gcc/attribs.h b/gcc/attribs.h index 23a7321..9bc1600 100644 --- a/gcc/attribs.h +++ b/gcc/attribs.h @@ -218,4 +218,24 @@ 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 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 { read_only, write_only, read_write }; + access_mode mode; +}; + #endif // GCC_ATTRIBS_H -- cgit v1.1