https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103223

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
For an attribute access that's explicitly specified on the declaration of a
function I think these steps should work:

1) Call init_attr_rdwr_indices() to initialize the mapping for the original
function with type fntype:

  rdwr_map rdwr_idx;
  init_attr_rdwr_indices (&rdwr_idx, TYPE_ATTRIBUTES (fntype));

2) Iterate over the mapping, rdwr_idx, creating an attribute access for each
pair of function arguments coupled by the attribute (i.e., pointer and size)
that also appears in the cloned function, and dropping those that don't. 
Append each specification to a chain of attributes.

3) Call decl_attributes() on the chain.

So maybe an API like this:

  bool copy_attr_access (tree newdecl, tree decl_to_clone, bitmap
args_to_copy);

where newdecl is the function cloned from the original decl_to_clone but with
fewer arguments and args_to_copy is a bitmap of the positions of the
decl_to_clone arguments for which to copy the access spec?  (Or, alternatively,
args_to_drop.)  Would this work for what you're thinking of using it for?  

This approach won't work for an explicitly specified attribute access where IPA
substitutes a constant for the bound, as in:

  __attribute__ ((access (write_only, 1, 2))) void f (int *a, int n) { ... }

when transformed into with 7 being the value of n:

  void f.constprop.7 (int *a) { ... }

Ideally, we want to change the cloned function to this:

  void f.constprop.7 (int a[7]) { ... }

so that calls it with fewer than 7 elements are diagnosed.  But there's no way
to specify __attribute__ ((access)) like that.  That's done internally, in
stages, by the front end by adding an "arg spec" attribute to the argument a as
it's seen in the argument list.  Once the argument list is fully processed the
front end then creates the attribute access specification for the function from
the "arg spec" attributes on all the arguments.  We need a way to do the same
thing in the middle end.

if he above is close, can you show me where you would call the function from?

Reply via email to