public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR80222
Date: Tue, 28 Mar 2017 10:58:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1703281207200.30051@zhemvz.fhfr.qr> (raw)


In the context of PR79671 it was noticed that forcing a ref-all
pointer access via a simple static_cast <C&> (obj) and C
with may_alias on it didn't work.

But it should.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2017-03-28  Richard Biener  <rguenther@suse.de>

	PR middle-end/80222
	* gimple-fold.c (gimple_fold_indirect_ref): Do not touch
	TYPE_REF_CAN_ALIAS_ALL references.
	* fold-const.c (fold_indirect_ref_1): Likewise.

	* g++.dg/pr80222.C: New testcase.

Index: gcc/gimple-fold.c
===================================================================
*** gcc/gimple-fold.c	(revision 246500)
--- gcc/gimple-fold.c	(working copy)
*************** gimple_get_virt_method_for_binfo (HOST_W
*** 6539,6546 ****
    return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
  }
  
! /* Given a pointer value OP0, return a simplified version of an
!    indirection through OP0, or NULL_TREE if no simplification is
     possible.  Note that the resulting type may be different from
     the type pointed to in the sense that it is still compatible
     from the langhooks point of view. */
--- 6539,6546 ----
    return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
  }
  
! /* Given a pointer value T, return a simplified version of an
!    indirection through T, or NULL_TREE if no simplification is
     possible.  Note that the resulting type may be different from
     the type pointed to in the sense that it is still compatible
     from the langhooks point of view. */
*************** gimple_fold_indirect_ref (tree t)
*** 6554,6560 ****
  
    STRIP_NOPS (sub);
    subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype))
      return NULL_TREE;
  
    if (TREE_CODE (sub) == ADDR_EXPR)
--- 6554,6561 ----
  
    STRIP_NOPS (sub);
    subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype)
!       || TYPE_REF_CAN_ALIAS_ALL (ptype))
      return NULL_TREE;
  
    if (TREE_CODE (sub) == ADDR_EXPR)
Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 246500)
--- gcc/fold-const.c	(working copy)
*************** fold_indirect_ref_1 (location_t loc, tre
*** 14006,14012 ****
  
    STRIP_NOPS (sub);
    subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype))
      return NULL_TREE;
  
    if (TREE_CODE (sub) == ADDR_EXPR)
--- 14006,14013 ----
  
    STRIP_NOPS (sub);
    subtype = TREE_TYPE (sub);
!   if (!POINTER_TYPE_P (subtype)
!       || TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (op0)))
      return NULL_TREE;
  
    if (TREE_CODE (sub) == ADDR_EXPR)
Index: gcc/testsuite/g++.dg/pr80222.C
===================================================================
*** gcc/testsuite/g++.dg/pr80222.C	(nonexistent)
--- gcc/testsuite/g++.dg/pr80222.C	(working copy)
***************
*** 0 ****
--- 1,13 ----
+ // { dg-do compile }
+ // { dg-options "-O2 -fdump-tree-optimized" } */
+ 
+ struct C { int i; }__attribute__((may_alias)) ;
+ 
+ C a, b;
+ 
+ int main()
+ {
+   a = static_cast <C&> (b);
+ }
+ 
+ // { dg-final { scan-tree-dump "{ref-all}\\\)&b\];" "optimized" } } */

             reply	other threads:[~2017-03-28 10:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28 10:58 Richard Biener [this message]
2017-05-13  9:15 ` Eric Botcazou
2017-05-13  9:40   ` Richard Biener
2017-05-13 10:24     ` Eric Botcazou
2017-05-15  8:00       ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.1703281207200.30051@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).