re PR libgomp/90641 (libgomp.c-c++-common/lastprivate-conditional-1.c etc FAIL)
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 May 2019 21:27:00 +0000 (23:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 27 May 2019 21:27:00 +0000 (23:27 +0200)
PR libgomp/90641
* work.c (gomp_init_work_share): Instead of aligning final ordered
value to multiples of long long alignment, align to that the
first part (ordered team ids) and if inline_ordered_team_ids
is not on a long long alignment boundary within the structure,
use __alignof__ (long long) - 1 pad size always.
* loop.c (GOMP_loop_start): Fix *mem computation if
inline_ordered_team_ids is not aligned on long long alignment boundary
within the structure.
* loop-ull.c (GOMP_loop_ull_start): Likewise.
* sections.c (GOMP_sections2_start): Likewise.

From-SVN: r271671

libgomp/ChangeLog
libgomp/loop.c
libgomp/loop_ull.c
libgomp/sections.c
libgomp/work.c

index f88e06abf68c1d6472e7d0e1785c9a9dc89bb5b3..73bc23e80d0e4b23a318a29f4d0c055487cc079a 100644 (file)
@@ -1,3 +1,17 @@
+2019-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR libgomp/90641
+       * work.c (gomp_init_work_share): Instead of aligning final ordered
+       value to multiples of long long alignment, align to that the
+       first part (ordered team ids) and if inline_ordered_team_ids
+       is not on a long long alignment boundary within the structure,
+       use __alignof__ (long long) - 1 pad size always.
+       * loop.c (GOMP_loop_start): Fix *mem computation if
+       inline_ordered_team_ids is not aligned on long long alignment boundary
+       within the structure.
+       * loop-ull.c (GOMP_loop_ull_start): Likewise.
+       * sections.c (GOMP_sections2_start): Likewise.
+
 2019-05-24  Jakub Jelinek  <jakub@redhat.com>
 
        * testsuite/libgomp.c-c++-common/lastprivate-conditional-1.c: New test.
index 7248cb561440f1ef9e99c9cf4f92ea332798b896..37861d1d4f38a999a992ca96193c6f7c4d461bf9 100644 (file)
@@ -267,14 +267,17 @@ GOMP_loop_start (long start, long end, long incr, long sched,
       if (mem)
        {
          uintptr_t size = (uintptr_t) *mem;
+#define INLINE_ORDERED_TEAM_IDS_OFF \
+  ((offsetof (struct gomp_work_share, inline_ordered_team_ids)         \
+    + __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
          if (size > (sizeof (struct gomp_work_share)
-                     - offsetof (struct gomp_work_share,
-                                 inline_ordered_team_ids)))
-           thr->ts.work_share->ordered_team_ids
-             = gomp_malloc_cleared (size);
+                     - INLINE_ORDERED_TEAM_IDS_OFF))
+           *mem
+             = (void *) (thr->ts.work_share->ordered_team_ids
+                         = gomp_malloc_cleared (size));
          else
-           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
-         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+           *mem = memset (((char *) thr->ts.work_share)
+                          + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
        }
       gomp_work_share_init_done ();
     }
@@ -287,7 +290,18 @@ GOMP_loop_start (long start, long end, long incr, long sched,
                                                  first_reductions);
        }
       if (mem)
-       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       {
+         if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+              & (__alignof__ (long long) - 1)) == 0)
+           *mem = (void *) thr->ts.work_share->ordered_team_ids;
+         else
+           {
+             uintptr_t p = (uintptr_t) thr->ts.work_share->ordered_team_ids;
+             p += __alignof__ (long long) - 1;
+             p &= ~(__alignof__ (long long) - 1);
+             *mem = (void *) p;
+           }
+       }
     }
 
   if (!istart)
index 502bb5e0e13253cee46ac978915f644fb5548bc6..edf1c323f2980c52341881b72471c993fe8c6c42 100644 (file)
@@ -266,14 +266,17 @@ GOMP_loop_ull_start (bool up, gomp_ull start, gomp_ull end,
       if (mem)
        {
          uintptr_t size = (uintptr_t) *mem;
+#define INLINE_ORDERED_TEAM_IDS_OFF \
+  ((offsetof (struct gomp_work_share, inline_ordered_team_ids)         \
+    + __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
          if (size > (sizeof (struct gomp_work_share)
-                     - offsetof (struct gomp_work_share,
-                                 inline_ordered_team_ids)))
-           thr->ts.work_share->ordered_team_ids
-             = gomp_malloc_cleared (size);
+                     - INLINE_ORDERED_TEAM_IDS_OFF))
+           *mem
+             = (void *) (thr->ts.work_share->ordered_team_ids
+                         = gomp_malloc_cleared (size));
          else
-           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
-         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+           *mem = memset (((char *) thr->ts.work_share)
+                          + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
        }
       gomp_work_share_init_done ();
     }
@@ -286,7 +289,18 @@ GOMP_loop_ull_start (bool up, gomp_ull start, gomp_ull end,
                                                  first_reductions);
        }
       if (mem)
-       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       {
+         if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+              & (__alignof__ (long long) - 1)) == 0)
+           *mem = (void *) thr->ts.work_share->ordered_team_ids;
+         else
+           {
+             uintptr_t p = (uintptr_t) thr->ts.work_share->ordered_team_ids;
+             p += __alignof__ (long long) - 1;
+             p &= ~(__alignof__ (long long) - 1);
+             *mem = (void *) p;
+           }
+       }
     }
 
   return ialias_call (GOMP_loop_ull_runtime_next) (istart, iend);
index bf7baae54c5677cbf8bf26b97ddaedaa93712146..887943670cc0bbafe8557c186f417d2ea3229caa 100644 (file)
@@ -118,14 +118,17 @@ GOMP_sections2_start (unsigned count, uintptr_t *reductions, void **mem)
       if (mem)
        {
          uintptr_t size = (uintptr_t) *mem;
+#define INLINE_ORDERED_TEAM_IDS_OFF \
+  ((offsetof (struct gomp_work_share, inline_ordered_team_ids)         \
+    + __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
          if (size > (sizeof (struct gomp_work_share)
-                     - offsetof (struct gomp_work_share,
-                                 inline_ordered_team_ids)))
-           thr->ts.work_share->ordered_team_ids
-             = gomp_malloc_cleared (size);
+                     - INLINE_ORDERED_TEAM_IDS_OFF))
+           *mem
+             = (void *) (thr->ts.work_share->ordered_team_ids
+                         = gomp_malloc_cleared (size));
          else
-           memset (thr->ts.work_share->ordered_team_ids, '\0', size);
-         *mem = (void *) thr->ts.work_share->ordered_team_ids;
+           *mem = memset (((char *) thr->ts.work_share)
+                          + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
        }
       gomp_work_share_init_done ();
     }
@@ -138,7 +141,18 @@ GOMP_sections2_start (unsigned count, uintptr_t *reductions, void **mem)
                                                  first_reductions);
        }
       if (mem)
-       *mem = (void *) thr->ts.work_share->ordered_team_ids;
+       {
+         if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+              & (__alignof__ (long long) - 1)) == 0)
+           *mem = (void *) thr->ts.work_share->ordered_team_ids;
+         else
+           {
+             uintptr_t p = (uintptr_t) thr->ts.work_share->ordered_team_ids;
+             p += __alignof__ (long long) - 1;
+             p &= ~(__alignof__ (long long) - 1);
+             *mem = (void *) p;
+           }
+       }
     }
 
 #ifdef HAVE_SYNC_BUILTINS
index 22adb8b9fcd14481be19cadbf42980445301658f..a589b8b523113a8d43cfc0921faf8e14f4bd06d9 100644 (file)
@@ -110,9 +110,12 @@ gomp_init_work_share (struct gomp_work_share *ws, size_t ordered,
 
       if (__builtin_expect (ordered != 1, 0))
        {
-         ordered += nthreads * sizeof (*ws->ordered_team_ids) - 1;
-         ordered = ordered + __alignof__ (long long) - 1;
-         ordered &= ~(__alignof__ (long long) - 1);
+         size_t o = nthreads * sizeof (*ws->ordered_team_ids);
+         o += __alignof__ (long long) - 1;
+         if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
+              & (__alignof__ (long long) - 1)) == 0)
+           o &= ~(__alignof__ (long long) - 1);
+         ordered += o - 1;
        }
       else
        ordered = nthreads * sizeof (*ws->ordered_team_ids);