Message ID | 2889898.e9J7NaK4W3@fomalhaut |
---|---|
State | New |
Headers | show |
Series | Fix PR tree-optimization/108199 | expand |
On Wed, Jan 11, 2023 at 11:00 AM Eric Botcazou via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > > this fixes the problematic interaction between bitfields, unions, SSO and SRA. > > Tested on x86-64/Linux and SPARC/Solaris, OK for all active branches? OK. Thanks, Richard. > > 2023-01-11 Eric Botcazou <ebotcazou@adacore.com> > Andreas Krebbel <krebbel@linux.ibm.com> > > PR tree-optimization/108199 > * tree-sra.cc (sra_modify_expr): Deal with reverse storage order > for bit-field references. > > > 2023-01-11 Eric Botcazou <ebotcazou@adacore.com> > > * gcc.dg/sso-17.c: New test. > > -- > Eric Botcazou
diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index f0182a45485..ad0c738645d 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -3858,7 +3858,23 @@ sra_modify_expr (tree *expr, gimple_stmt_iterator *gsi, bool write) } } else - *expr = repl; + { + /* If we are going to replace a scalar field in a structure with + reverse storage order by a stand-alone scalar, we are going to + effectively byte-swap the scalar and we also need to byte-swap + the portion of it represented by the bit-field. */ + if (bfr && REF_REVERSE_STORAGE_ORDER (bfr)) + { + REF_REVERSE_STORAGE_ORDER (bfr) = 0; + TREE_OPERAND (bfr, 2) + = size_binop (MINUS_EXPR, TYPE_SIZE (TREE_TYPE (repl)), + size_binop (PLUS_EXPR, TREE_OPERAND (bfr, 1), + TREE_OPERAND (bfr, 2))); + } + + *expr = repl; + } + sra_stats.exprs++; } else if (write && access->grp_to_be_debug_replaced)