From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id DFCBC3856DFF; Fri, 6 May 2022 08:38:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFCBC3856DFF Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/hard12)] sync up new type indices for body adjustments X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/hard12 X-Git-Oldrev: 310e96d43803ec7e3a1224dff70d5d7169cb85da X-Git-Newrev: 68ab3c7d4267671172030b12f2ca3341553cb4de Message-Id: <20220506083819.DFCBC3856DFF@sourceware.org> Date: Fri, 6 May 2022 08:38:19 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2022 08:38:20 -0000 https://gcc.gnu.org/g:68ab3c7d4267671172030b12f2ca3341553cb4de commit 68ab3c7d4267671172030b12f2ca3341553cb4de Author: Alexandre Oliva Date: Fri May 6 05:35:02 2022 -0300 sync up new type indices for body adjustments The logic in fill_vector_of_new_param_types may skip some parameters when pushing into m_new_types, but common_initialization doesn't take that into account, and may end up attempting to access the vector past its end when IPA_PARAM_OP_(NEW|SPLIT) operands appear after skipped _COPY ones. This patch adjusts the consumer logic to match the indexing in the producer. It came up in libstdc++-v3's testsuite, in std/ranges/adaptors/filter.cc, but only with wrappers introduced by a pass I'm working on. The _NEW parameters were reference-typed replacements for some by-value ones in my function-wrapping logic, and other IPA transformations cause plenty of unused/irrelevant arguments to be dropped for certain calls. for gcc/ChangeLog * ipa-param-manipulation.c (ipa_param_body_adjustments::common_initialization): Adjust m_new_types indexing to match producer. Diff: --- gcc/ipa-param-manipulation.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc index 5c2d1eb88da..187ff37e95b 100644 --- a/gcc/ipa-param-manipulation.cc +++ b/gcc/ipa-param-manipulation.cc @@ -1350,11 +1350,17 @@ ipa_param_body_adjustments::common_initialization (tree old_fndecl, corresponding m_id->dst_node->clone.performed_splits entries. */ m_new_decls.reserve_exact (adj_len); - for (unsigned i = 0; i < adj_len ; i++) + for (unsigned i = 0, nti = 0; i < adj_len ; i++, nti++) { ipa_adjusted_param *apm = &(*m_adj_params)[i]; unsigned prev_index = apm->prev_clone_index; tree new_parm; + if (apm->op == IPA_PARAM_OP_COPY + && prev_index >= otypes.length ()) + /* Keep nti in sync with the m_new_types indices used in + fill_vector_of_new_param_types, for any non-IPA_PARAM_OP_COPY + parms. */ + nti--; if (apm->op == IPA_PARAM_OP_COPY || apm->prev_clone_adjustment) { @@ -1365,7 +1371,7 @@ ipa_param_body_adjustments::common_initialization (tree old_fndecl, else if (apm->op == IPA_PARAM_OP_NEW || apm->op == IPA_PARAM_OP_SPLIT) { - tree new_type = m_new_types[i]; + tree new_type = m_new_types[nti]; gcc_checking_assert (new_type); new_parm = build_decl (UNKNOWN_LOCATION, PARM_DECL, NULL_TREE, new_type);