From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id 950023858D39; Thu, 21 Oct 2021 12:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 950023858D39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4607] sra: Fix corner case of total scalarization with virtual inheritance (PR 102505) X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: d6a3c0cfb852dbeee4255e3588e9a1f52e376042 X-Git-Newrev: 701ee067807b80957c65bd7ff94b6099a27181de Message-Id: <20211021125609.950023858D39@sourceware.org> Date: Thu, 21 Oct 2021 12:56:09 +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: Thu, 21 Oct 2021 12:56:09 -0000 https://gcc.gnu.org/g:701ee067807b80957c65bd7ff94b6099a27181de commit r12-4607-g701ee067807b80957c65bd7ff94b6099a27181de Author: Martin Jambor Date: Thu Oct 21 14:26:45 2021 +0200 sra: Fix corner case of total scalarization with virtual inheritance (PR 102505) PR 102505 is a situation where of SRA takes its initial top-level access size from a get_ref_base_and_extent called on a COMPONENT_REF, and thus derived frm the FIELD_DECL, which however does not include a virtual base. Total scalarization then goes on traversing the type, which however has virtual base past the non-virtual bits, tricking SRA to create sub-accesses outside of the supposedly encompassing accesses, which in turn triggers the verifier within the pass. The patch below fixes that by failing total scalarization when this situation is detected. gcc/ChangeLog: 2021-10-20 Martin Jambor PR tree-optimization/102505 * tree-sra.c (totally_scalarize_subtree): Check that the encountered field fits within the acces we would like to put it in. gcc/testsuite/ChangeLog: 2021-10-20 Martin Jambor PR tree-optimization/102505 * g++.dg/torture/pr102505.C: New test. Diff: --- gcc/testsuite/g++.dg/torture/pr102505.C | 15 +++++++++++++++ gcc/tree-sra.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/gcc/testsuite/g++.dg/torture/pr102505.C b/gcc/testsuite/g++.dg/torture/pr102505.C new file mode 100644 index 00000000000..a846751a0d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr102505.C @@ -0,0 +1,15 @@ +struct D { int i; int pad alignas(16); }; +struct B : virtual D +{ + int j =84; + int k =84; +}; + +struct C: B { }; + +int main() +{ + C c; + if (c.j != 84 || c.k != 84) + __builtin_abort(); +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 9b786e29e4e..f561e1a2133 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -3288,6 +3288,8 @@ totally_scalarize_subtree (struct access *root) continue; HOST_WIDE_INT pos = root->offset + int_bit_position (fld); + if (pos + fsize > root->size) + return false; enum total_sra_field_state state = total_should_skip_creating_access (root, &last_seen_sibling,