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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-04-18
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
For for-3.c it is:

static void
expand_omp_for_static_nochunk (struct omp_region *region,
                               struct omp_for_data *fd,
                               gimple *inner_stmt)
{ 
...
  if (POINTER_TYPE_P (type))
    t = fold_build_pointer_plus (n1, t); 
  else
    t = fold_build2 (PLUS_EXPR, type, t, n1);
  t = fold_convert (TREE_TYPE (startvar), t);

where a fix could be to do

Index: omp-expand.c
===================================================================
--- omp-expand.c        (revision 259457)
+++ omp-expand.c        (working copy)
@@ -3501,7 +3501,10 @@ 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);
+      t = fold_convert (unsigned_type_for (TREE_TYPE (n1)), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);

but there are likely a few "copies" of the code.  The for-3.c testcase
also exercises the following spot:

@@ -3515,7 +3518,10 @@ 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);
+      t = fold_convert (unsigned_type_for (TREE_TYPE (n1)), t);
+    }
   else
     t = fold_build2 (PLUS_EXPR, type, t, n1);
   t = fold_convert (TREE_TYPE (startvar), t);

and that's still not enough to fix it fully...

Note that I think even for GENERIC using fold_convert the original way
is wrong.  Given fold_convert is "interesting" we might consider using
POINTERS_EXTEND_UNSIGNED there... (ok, I didn't suggest that).

Reply via email to