public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/103223] [12 regression] Access attribute dropped when ipa-sra is applied
Date: Mon, 15 Nov 2021 20:19:42 +0000	[thread overview]
Message-ID: <bug-103223-4-bYc0F6qoJ2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103223-4@http.gcc.gnu.org/bugzilla/>

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?

  parent reply	other threads:[~2021-11-15 20:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-13 10:05 [Bug tree-optimization/103223] New: [12 regression] Access attribute prevents IPA optimization hubicka at gcc dot gnu.org
2021-11-13 23:56 ` [Bug tree-optimization/103223] [12 regression] Access attribute dropped when ipa-sra is applied hubicka at gcc dot gnu.org
2021-11-15  9:02 ` rguenth at gcc dot gnu.org
2021-11-15 15:50 ` jamborm at gcc dot gnu.org
2021-11-15 15:58 ` jamborm at gcc dot gnu.org
2021-11-15 16:12 ` msebor at gcc dot gnu.org
2021-11-15 18:12 ` jamborm at gcc dot gnu.org
2021-11-15 20:19 ` msebor at gcc dot gnu.org [this message]
2021-11-15 21:02 ` hubicka at kam dot mff.cuni.cz
2021-11-15 22:32 ` msebor at gcc dot gnu.org
2021-11-22  7:35 ` admin at levyhsu dot com
2021-11-22  7:53 ` hubicka at kam dot mff.cuni.cz
2022-05-06  8:31 ` [Bug ipa/103223] [12/13 " jakub at gcc dot gnu.org
2023-05-08 12:23 ` [Bug ipa/103223] [12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103223-4-bYc0F6qoJ2@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).