https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94216
--- Comment #10 from rguenther at suse dot de <rguenther at suse dot de> --- On Thu, 19 Mar 2020, Richard Biener wrote: > On Thu, 19 Mar 2020, jakub at gcc dot gnu.org wrote: > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94216 > > > > --- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- > > (In reply to Richard Biener from comment #5) > > > (In reply to Jakub Jelinek from comment #1) > > > > I wonder if we shouldn't do: > > > > --- gcc/fold-const.c.jj 2020-03-18 12:47:36.000000000 +0100 > > > > +++ gcc/fold-const.c 2020-03-18 17:34:14.586455801 +0100 > > > > @@ -82,6 +82,7 @@ along with GCC; see the file COPYING3. > > > > #include "attribs.h" > > > > #include "tree-vector-builder.h" > > > > #include "vec-perm-indices.h" > > > > +#include "tree-ssa.h" > > > > > > > > /* Nonzero if we are folding constants inside an initializer; zero > > > > otherwise. */ > > > > @@ -10262,6 +10263,10 @@ fold_binary_loc (location_t loc, enum tr > > > > switch (code) > > > > { > > > > case MEM_REF: > > > > + STRIP_USELESS_TYPE_CONVERSION (arg0); > > > > > > We already applied STRIP_NOPS to arg0 > > > > Though, if we don't want to strip non-useless conversions, that is wrong > > even > > for the two special cases we have afterwards. > > So, shouldn't case MEM_REF: start then with > > arg0 = op0; > > STRIP_USELESS_TYPE_CONVERSION (arg0); > > arg1 = op1; > > ? > > While we "abuse" fold_binary (MEM_REF,...) to make MEM_REFs valid > we still expect some basic hygiene there.. > > > Or fold_convert to the type of op0 if the type conversion isn't useless? > > Also, isn't the arg1 handling incorrect or at least dangerous? > > I mean, if it does int_const_binop (PLUS_EXPR, arg1, ...) in both cases > > then it will have the type of arg1 which is op1 after STRIP_NOPS, so could > > have > > completely different type. One needs to hope that the last argument to > > fold_binary_loc of MEM_REF will always be an INTEGER_CST from which nothing > > can > > be stripped... > > ..for example INTEGER_CST 2nd argument (implicit in the use of > int_const_binop). For the 2nd arg we could be more explicit and > instead of arg1 use op1. Likewise we should probably use > > if (TREE_CODE (op0) == ADDR_EXPR > && TREE_CODE (TREE_OPERAND (op0, 0)) == MEM_REF) > > that is, we don't even expect to need to strip nops here. I'll try > to bootstrap/test such changes to see where other possible issues > in fold_build_addr_expr callers lie... That worked well without any further visible fallout.