public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10249] sra: Fix corner case of total scalarization with virtual inheritance (PR 102505)
@ 2021-11-02 10:19 Martin Jambor
0 siblings, 0 replies; only message in thread
From: Martin Jambor @ 2021-11-02 10:19 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7d398e42d3d4ded84cb7a86396c75c5aaf518283
commit r10-10249-g7d398e42d3d4ded84cb7a86396c75c5aaf518283
Author: Martin Jambor <mjambor@suse.cz>
Date: Tue Nov 2 11:17:51 2021 +0100
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.
This backport also has commit f217e87972a2a207e793101fc05cfc9dd095c678
squashed into it in order to avoid PR 102886 that the fix introduced
on trunk.
gcc/ChangeLog:
2021-10-20 Martin Jambor <mjambor@suse.cz>
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 <mjambor@suse.cz>
PR tree-optimization/102505
* g++.dg/torture/pr102505.C: New test.
(cherry picked from commit 701ee067807b80957c65bd7ff94b6099a27181de)
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 85b9cc9ed7f..09d951a261b 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -3265,6 +3265,8 @@ totally_scalarize_subtree (struct access *root)
continue;
HOST_WIDE_INT pos = root->offset + int_bit_position (fld);
+ if (pos + fsize > root->offset + root->size)
+ return false;
enum total_sra_field_state
state = total_should_skip_creating_access (root,
&last_seen_sibling,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-02 10:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 10:19 [gcc r10-10249] sra: Fix corner case of total scalarization with virtual inheritance (PR 102505) Martin Jambor
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).