https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79671

--- Comment #59 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 27 Mar 2017, redi at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79671
> 
> --- Comment #58 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> But this seemingly equivalent code doesn't work:
> 
>   this->functor = static_cast<function_buffer&>(f.functor);

Is function_buffer may_alias?  Then it should work unless the
FE messes up via folding.

struct C { int i; }__attribute__((may_alias)) ;

C a, b;

void foo()
{
  a = static_cast <C&> (b);
}

in .original (correct):

<<cleanup_point <<< Unknown tree: expr_stmt
  (void) (a = *(const struct C & {ref-all}) &b) >>>>>;

in .gimple (wrong-code):

void foo() ()
{
  a = b;
}

caused by gimple_fold_indirect_ref_rhs doing

tree
gimple_fold_indirect_ref (tree t)
{
  tree ptype = TREE_TYPE (t), type = TREE_TYPE (ptype);
  tree sub = t;
  tree subtype;

  STRIP_NOPS (sub);
  subtype = TREE_TYPE (sub);
  if (!POINTER_TYPE_P (subtype))
    return NULL_TREE;

  if (TREE_CODE (sub) == ADDR_EXPR)
    {
      tree op = TREE_OPERAND (sub, 0);
      tree optype = TREE_TYPE (op);
      /* *&p => p */
      if (useless_type_conversion_p (type, optype))
        return op;

some of the transforms properly preserve ptype semantics but most don't

Reply via email to