public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: richard.guenther@gmail.com
Subject: [PATCH v2 01/13] Change default of non-overlapping address space conversion
Date: Tue, 20 Oct 2015 21:28:00 -0000	[thread overview]
Message-ID: <1445376433-14658-2-git-send-email-rth@redhat.com> (raw)
In-Reply-To: <1445376433-14658-1-git-send-email-rth@redhat.com>

The current default of making all undefined coversions being
set to null is not useful.  It has caused all users to lie
and say that spaces are subsets when they are not, just so
that they can override the conversion.
---
 gcc/expr.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/gcc/expr.c b/gcc/expr.c
index 595324d..9287da2 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -8179,34 +8179,40 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
     case ADDR_SPACE_CONVERT_EXPR:
       {
 	tree treeop0_type = TREE_TYPE (treeop0);
-	addr_space_t as_to;
-	addr_space_t as_from;
 
 	gcc_assert (POINTER_TYPE_P (type));
 	gcc_assert (POINTER_TYPE_P (treeop0_type));
 
-	as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
-	as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
+	addr_space_t as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
+	addr_space_t as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
 
         /* Conversions between pointers to the same address space should
 	   have been implemented via CONVERT_EXPR / NOP_EXPR.  */
 	gcc_assert (as_to != as_from);
 
+	op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
+
         /* Ask target code to handle conversion between pointers
 	   to overlapping address spaces.  */
 	if (targetm.addr_space.subset_p (as_to, as_from)
 	    || targetm.addr_space.subset_p (as_from, as_to))
 	  {
-	    op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
 	    op0 = targetm.addr_space.convert (op0, treeop0_type, type);
-	    gcc_assert (op0);
-	    return op0;
 	  }
-
-	/* For disjoint address spaces, converting anything but
-	   a null pointer invokes undefined behaviour.  We simply
-	   always return a null pointer here.  */
-	return CONST0_RTX (mode);
+        else
+          {
+	    /* For disjoint address spaces, converting anything but a null
+	       pointer invokes undefined behaviour.  We truncate or extend the
+	       value as if we'd converted via integers, which handles 0 as
+	       required, and all others as the programmer likely expects.  */
+#ifndef POINTERS_EXTEND_UNSIGNED
+	    const int POINTERS_EXTEND_UNSIGNED = 1;
+#endif
+	    op0 = convert_modes (mode, TYPE_MODE (treeop0_type),
+				 op0, POINTERS_EXTEND_UNSIGNED);
+	  }
+	gcc_assert (op0);
+	return op0;
       }
 
     case POINTER_PLUS_EXPR:
-- 
2.4.3

  reply	other threads:[~2015-10-20 21:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 21:27 [PATCH v2 00/13] Address space support for x86 Richard Henderson
2015-10-20 21:28 ` Richard Henderson [this message]
2015-10-21 14:03   ` [PATCH v2 01/13] Change default of non-overlapping address space conversion Jeff Law
2015-10-20 21:28 ` [PATCH v2 04/13] i386: Disallow address spaces with string insns Richard Henderson
2015-10-20 21:28 ` [PATCH v2 05/13] i386: Add address spaces for fs/gs segments Richard Henderson
2015-10-20 21:28 ` [PATCH v2 09/13] Fix PR 66768 Richard Henderson
2015-10-21 13:56   ` Jeff Law
2015-10-21 17:55     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 10/13] Avoid CSE of MEMs in different address spaces Richard Henderson
2015-10-21 13:49   ` Jeff Law
2015-10-21 17:12     ` Richard Henderson
2015-10-22  7:48       ` Richard Biener
2015-10-20 21:28 ` [PATCH v2 08/13] Add TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID Richard Henderson
2015-10-21 13:59   ` Jeff Law
2015-10-21 20:51     ` Richard Henderson
2015-10-21 21:29       ` Jeff Law
2015-10-22  3:27   ` Sandra Loosemore
2015-10-22  7:59     ` Richard Biener
2015-10-23 17:08       ` Sandra Loosemore
2015-10-22 19:17     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 07/13] i386: Add address space for tls Richard Henderson
2015-10-20 21:28 ` [PATCH v2 06/13] i386: Replace ix86_address_seg with addr_space_t Richard Henderson
2015-10-20 21:28 ` [PATCH v2 02/13] Relax ADDR_SPACE_GENERIC_P checks for default address space hooks Richard Henderson
2015-10-21 14:02   ` Jeff Law
2015-10-21 20:50     ` Richard Henderson
2015-10-20 21:28 ` [PATCH v2 13/13] Add hook for modifying debug info for address spaces Richard Henderson
2015-10-21 13:55   ` Jeff Law
2015-10-21 14:57   ` H.J. Lu
2015-10-21 17:23     ` Richard Henderson
2015-10-21 17:25       ` H.J. Lu
2015-10-21 17:51         ` Richard Henderson
2015-10-21 18:36           ` H.J. Lu
2015-10-21 16:22   ` Ulrich Weigand
2015-10-21 19:13     ` Richard Henderson
2015-10-22 14:19       ` Ulrich Weigand
2015-10-20 21:28 ` [PATCH v2 12/13] Document the x86 " Richard Henderson
2015-10-22  4:59   ` Sandra Loosemore
2015-10-22 20:30     ` Richard Henderson
2015-10-23 17:16       ` Sandra Loosemore
2015-10-20 21:28 ` [PATCH v2 11/13] Test case for conversion from __seg_tls:0 Richard Henderson
2015-11-09 14:46   ` Richard Biener
2015-11-09 17:55     ` Thomas Schwinge
2015-10-20 21:34 ` [PATCH v2 03/13] i386: Handle address spaces in movabs patterns Richard Henderson

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=1445376433-14658-2-git-send-email-rth@redhat.com \
    --to=rth@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /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).