From cb76fcd7fb4a4f1e4d1688deca87969124f16fef Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 23 Apr 2020 22:25:04 +0200 Subject: [PATCH] Fix segfault with -O2 -fnon-call-exceptions -ftracer The GIMPLE SSA store merging pass blows up when it is rewriting the stores because it didn't realize that they don't belong to the same EH region. Fixed by refusing to merge them. PR tree-optimization/94717 * gimple-ssa-store-merging.c (try_coalesce_bswap): Return false if one of the stores doesn't have the same landing pad number as the first. (coalesce_immediate_stores): Do not try to coalesce the store using bswap if it doesn't have the same landing pad number as the first. --- gcc/ChangeLog | 8 ++++++ gcc/gimple-ssa-store-merging.c | 2 ++ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/g++.dg/opt/store-merging-4.C | 29 ++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/g++.dg/opt/store-merging-4.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e58d040e04d..e8d397a3713 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-04-23 Eric Botcazou + + PR tree-optimization/94717 + * gimple-ssa-store-merging.c (try_coalesce_bswap): Return false if one + of the stores doesn't have the same landing pad number as the first. + (coalesce_immediate_stores): Do not try to coalesce the store using + bswap if it doesn't have the same landing pad number as the first. + 2020-04-23 Bill Schmidt * gcc/doc/extend.texi (PowerPC AltiVec/VSX Built-in Functions): diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index a6687cd9c98..25753517cc6 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -2435,6 +2435,7 @@ imm_store_chain_info::try_coalesce_bswap (merged_store_group *merged_store, for (unsigned int i = first + 1; i < len; ++i) { if (m_store_info[i]->bitpos != m_store_info[first]->bitpos + width + || m_store_info[i]->lp_nr != merged_store->lp_nr || m_store_info[i]->ins_stmt == NULL) return false; width += m_store_info[i]->bitsize; @@ -2682,6 +2683,7 @@ imm_store_chain_info::coalesce_immediate_stores () if (info->bitpos == merged_store->start + merged_store->width && merged_store->stores.length () == 1 && merged_store->stores[0]->ins_stmt != NULL + && info->lp_nr == merged_store->lp_nr && info->ins_stmt != NULL) { unsigned int try_size; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 249a1520581..f9ab061922e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-04-23 Eric Botcazou + + * g++.dg/opt/store-merging-4.C: New test. + 2020-04-23 Iain Sandoe PR c++/94288 diff --git a/gcc/testsuite/g++.dg/opt/store-merging-4.C b/gcc/testsuite/g++.dg/opt/store-merging-4.C new file mode 100644 index 00000000000..8a51dcd4c06 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/store-merging-4.C @@ -0,0 +1,29 @@ +// PR tree-optimization/94717 +// Reported by Zdenek Sojka + +// { dg-do compile } +// { dg-options "-O2 -fnon-call-exceptions -ftracer" } + +int abs (int); + +static inline void +bar (int d) +{ + d && abs (d); +} + +struct S +{ + int a; + int b; + int c; + S (unsigned a, unsigned b) : a (a), b (b) { } +}; + +void +foo (S *x) +{ + bar (x->c); + new S (x->a, x->b); + bar (0); +} -- 2.30.2