PR c/69643
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Feb 2016 22:05:17 +0000 (22:05 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 5 Feb 2016 22:05:17 +0000 (22:05 +0000)
  * tree.c (tree_nop_conversion_p): Do not strip casts into or
  out of non-standard address spaces.
testsuite/
  * gcc.target/i386/addr-space-4.c: New.
  * gcc.target/i386/addr-space-5.c: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233189 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/addr-space-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/addr-space-5.c [new file with mode: 0644]
gcc/tree.c

index 5ad6983..9e61921 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-06  Richard Henderson  <rth@redhat.com>
+
+       PR c/69643
+       * tree.c (tree_nop_conversion_p): Do not strip casts into or
+       out of non-standard address spaces.
+
 2016-02-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/69691
index 61306d0..d8f088d 100644 (file)
@@ -1,3 +1,9 @@
+2016-02-06  Richard HEnderson  <rth@redhat.com>
+
+       PR c/69643
+       * gcc.target/i386/addr-space-4.c: New.
+       * gcc.target/i386/addr-space-5.c: New.
+
 2016-02-05  Mikael Morin  <mikael@gcc.gnu.org>
 
        PR fortran/66089
diff --git a/gcc/testsuite/gcc.target/i386/addr-space-4.c b/gcc/testsuite/gcc.target/i386/addr-space-4.c
new file mode 100644 (file)
index 0000000..3e0966d
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+/* { dg-final { scan-assembler "gs:" } } */
+
+#define uintptr_t __SIZE_TYPE__
+
+struct S { int a, b, c; };
+
+extern struct S __seg_gs s;
+
+int foo (void)
+{
+  int r;
+  r = s.c;
+  return r;
+}
diff --git a/gcc/testsuite/gcc.target/i386/addr-space-5.c b/gcc/testsuite/gcc.target/i386/addr-space-5.c
new file mode 100644 (file)
index 0000000..4f73f95
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+/* { dg-final { scan-assembler "gs:" } } */
+
+#define uintptr_t __SIZE_TYPE__
+
+struct S { int a, b, c; };
+
+extern struct S s;
+
+int ct_state3 (void)
+{
+  int r;
+  r = *((int __seg_gs *) (uintptr_t) &s.c);
+  return r;
+}
index fa7646b..07cb9d9 100644 (file)
@@ -12219,6 +12219,23 @@ block_ultimate_origin (const_tree block)
 bool
 tree_nop_conversion_p (const_tree outer_type, const_tree inner_type)
 {
+  /* Do not strip casts into or out of differing address spaces.  */
+  if (POINTER_TYPE_P (outer_type)
+      && TYPE_ADDR_SPACE (TREE_TYPE (outer_type)) != ADDR_SPACE_GENERIC)
+    {
+      if (!POINTER_TYPE_P (inner_type)
+         || (TYPE_ADDR_SPACE (TREE_TYPE (outer_type))
+             != TYPE_ADDR_SPACE (TREE_TYPE (inner_type))))
+       return false;
+    }
+  else if (POINTER_TYPE_P (inner_type)
+          && TYPE_ADDR_SPACE (TREE_TYPE (inner_type)) != ADDR_SPACE_GENERIC)
+    {
+      /* We already know that outer_type is not a pointer with
+        a non-generic address space.  */
+      return false;
+    }
+
   /* Use precision rather then machine mode when we can, which gives
      the correct answer even for submode (bit-field) types.  */
   if ((INTEGRAL_TYPE_P (outer_type)