The following patch restores checking of integer<->pointer conversions
which I broke with a cut&paste error when introducing ptrofftype_p
and friends.  It also contains a fix from Jakub for the fallout in
omp expansion.

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

Richard.

2018-04-26  Richard Biener  <rguent...@suse.de>

        PR middle-end/85450
        * tree-cfg.c (verify_gimple_assign_unary): Restore proper
        checking of integer<->pointer conversions.
        * omp-expand.c (expand_omp_for_static_nochunk): Avoid
        sign-/zero-extending pointer types.
        (expand_omp_for_static_chunk): Likewise.

Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c      (revision 259638)
+++ gcc/tree-cfg.c      (working copy)
@@ -3842,7 +3842,7 @@ verify_gimple_assign_unary (gassign *stm
            || (POINTER_TYPE_P (rhs1_type)
                && INTEGRAL_TYPE_P (lhs_type)
                && (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
-                   || ptrofftype_p (sizetype))))
+                   || ptrofftype_p (lhs_type))))
          return false;
 
        /* Allow conversion from integral to offset type and vice versa.  */
Index: gcc/omp-expand.c
===================================================================
--- gcc/omp-expand.c    (revision 259638)
+++ gcc/omp-expand.c    (working copy)
@@ -3501,7 +3501,12 @@ expand_omp_for_static_nochunk (struct om
   t = fold_convert (itype, s0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-    t = fold_build_pointer_plus (n1, t);
+    {
+      t = fold_build_pointer_plus (n1, t);
+      if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+         && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+       t = fold_convert (signed_type_for (type), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -3515,7 +3520,12 @@ expand_omp_for_static_nochunk (struct om
   t = fold_convert (itype, e0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-    t = fold_build_pointer_plus (n1, t);
+    {
+      t = fold_build_pointer_plus (n1, t);
+      if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+         && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+       t = fold_convert (signed_type_for (type), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -4000,7 +4010,12 @@ expand_omp_for_static_chunk (struct omp_
   t = fold_convert (itype, s0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-    t = fold_build_pointer_plus (n1, t);
+    {
+      t = fold_build_pointer_plus (n1, t);
+      if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+         && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+       t = fold_convert (signed_type_for (type), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);
@@ -4014,7 +4029,12 @@ expand_omp_for_static_chunk (struct omp_
   t = fold_convert (itype, e0);
   t = fold_build2 (MULT_EXPR, itype, t, step);
   if (POINTER_TYPE_P (type))
-    t = fold_build_pointer_plus (n1, t);
+    {
+      t = fold_build_pointer_plus (n1, t);
+      if (!POINTER_TYPE_P (TREE_TYPE (startvar))
+         && TYPE_PRECISION (TREE_TYPE (startvar)) > TYPE_PRECISION (type))
+       t = fold_convert (signed_type_for (type), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);

Reply via email to