From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2BF05385AC2A; Mon, 15 Nov 2021 20:19:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BF05385AC2A From: "msebor at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Nov 2021 20:19:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103223 --- Comment #7 from Martin Sebor --- 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.=20 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 wi= th 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, alternativ= ely, args_to_drop.) Would this work for what you're thinking of using it for?= =20=20 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 sa= me thing in the middle end. if he above is close, can you show me where you would call the function fro= m?=