[PATCH 1/5] infrastructure to detect out-of-bounds accesses to array parameters

Jeff Law law@redhat.com
Thu Aug 13 19:09:15 GMT 2020


On Fri, 2020-08-07 at 11:08 -0600, Martin Sebor via Gcc-patches wrote:
> On 7/28/20 7:16 PM, Martin Sebor wrote:
> > Patch 1 adds the basic infrastructure to support array/VLA bounds
> > in attribute access.  It extends the access string specification
> > to describe function parameters of array types (including VLAs),
> > extends the attr_access class to parse the string and store
> > the data in a form that's easy to work with, and implements
> > checking of various kinds f mismatches between redeclarations.
> > It doesn't actually enable anything new so no new tests are added.
> 
> Joseph's comments on patch 2 in the series prompted me to change
> how the array (and VLA) function parameters are formatted: instead
> of implementing it mostly outside the pretty printer (which, to do
> completely correctly, would require reimplementing what the pretty
> printer already does) I instead enhanced the pretty printer.  That
> let me simplify the formatting done in the helper.  The attached
> revision reflects this simplification (the only change from
> the original is to attr_access::array_as_string).
> 
> Martin
> [1/5] - Infrastructure to detect out-of-bounds accesses to array parameters.
> 
> gcc/ChangeLog:
> 
> 	PR c/50584
> 	* attribs.c (decl_attributes): Also pass decl along with type
> 	attributes to handlers.
> 	(init_attr_rdwr_indices): Change second argument to attribute chain.
> 	Handle internal attribute representation in addition to external.
> 	(get_parm_access): New function.
> 	(attr_access::to_internal_string): Define new member function.
> 	(attr_access::to_external_string): Define new member function.
> 	(attr_access::vla_bounds): Define new member function.
> 	* attribs.h (struct attr_access): Declare new members.
> 	(attr_access::from_mode_char): Define new member function.
> 	(get_parm_access): Declare new function.
> 	* calls.c (initialize_argument_information): Pass function type
> 	attributes to init_attr_rdwr_indices.
> 	* tree-ssa-uninit.c (maybe_warn_pass_by_reference): Same.
> 
> gcc/c-family/ChangeLog:
> 
> 	PR c/50584
> 	* c-attribs.c (c_common_attribute_table): Add "arg spec" attribute.
> 	(handle_argspec_attribute): New function.
> 	(get_argument, get_argument_type): New functions.
> 	(append_access_attrs): Add overload.  Handle internal attribute
> 	representation in addition to external.
> 	(handle_access_attribute): Handle internal attribute representation
> 	in addition to external.
> 	(build_attr_access_from_parms): New function.
> 	* c-warn.c (parm_array_as_string): Define new function.
> 	(plus_one):  Define new function.
> 	(warn_parm_array_mismatch): Define new function.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c/50584
> 	* gcc.dg/attr-access-read-write-2.c: Adjust text of expected messages.
LGTM.
jeff
> 



More information about the Gcc-patches mailing list