[Openmp-commits] [PATCH] D142508: [OpenMP][libomptarget] Fix alignment calculation for mapping struct members.

Pavel Kopyl via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 25 09:04:22 PST 2023


pavelkopyl updated this revision to Diff 492144.
pavelkopyl added a comment.

- Limit Padding values


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142508/new/

https://reviews.llvm.org/D142508

Files:
  openmp/libomptarget/src/omptarget.cpp


Index: openmp/libomptarget/src/omptarget.cpp
===================================================================
--- openmp/libomptarget/src/omptarget.cpp
+++ openmp/libomptarget/src/omptarget.cpp
@@ -581,11 +581,11 @@
     // Adjust for proper alignment if this is a combined entry (for structs).
     // Look at the next argument - if that is MEMBER_OF this one, then this one
     // is a combined entry.
-    int64_t Padding = 0;
     const int NextI = I + 1;
     if (getParentIndex(ArgTypes[I]) < 0 && NextI < ArgNum &&
         getParentIndex(ArgTypes[NextI]) == I) {
-      Padding = (int64_t)HstPtrBegin % Alignment;
+      int64_t Padding = std::min((int64_t)HstPtrBegin - (int64_t)HstPtrBase,
+                                 (int64_t)HstPtrBegin % Alignment);
       if (Padding) {
         DP("Using a padding of %" PRId64 " bytes for begin address " DPxMOD
            "\n",
@@ -939,7 +939,8 @@
     const int NextI = I + 1;
     if (getParentIndex(ArgTypes[I]) < 0 && NextI < ArgNum &&
         getParentIndex(ArgTypes[NextI]) == I) {
-      int64_t Padding = (int64_t)HstPtrBegin % Alignment;
+      int64_t Padding = std::min((int64_t)HstPtrBegin - (int64_t)ArgBases[I],
+                                 (int64_t)HstPtrBegin % Alignment);
       if (Padding) {
         DP("Using a Padding of %" PRId64 " bytes for begin address " DPxMOD
            "\n",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142508.492144.patch
Type: text/x-patch
Size: 1375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230125/859d825c/attachment.bin>


More information about the Openmp-commits mailing list