[flang-commits] [PATCH] D144134: [flang][runtime] MayAlias() must be false for Unallocated descriptors

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Feb 15 13:18:32 PST 2023


klausler created this revision.
klausler added a reviewer: vzakhari.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jeroen.dobbelaere, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

When either descriptor argument to MayAlias() is not allocated, the
result must be false by definition, since the values of the extents
in the dimensional information may be uninitialized.


https://reviews.llvm.org/D144134

Files:
  flang/runtime/assign.cpp


Index: flang/runtime/assign.cpp
===================================================================
--- flang/runtime/assign.cpp
+++ flang/runtime/assign.cpp
@@ -126,6 +126,11 @@
 // possibly overlap in memory?  Note that the descriptors themeselves
 // are included in the test.
 static bool MayAlias(const Descriptor &x, const Descriptor &y) {
+  const char *xBase{x.OffsetElement()};
+  const char *yBase{y.OffsetElement()};
+  if (!xBase || !yBase) {
+    return false; // not both allocated
+  }
   const char *xDesc{reinterpret_cast<const char *>(&x)};
   const char *xDescLast{xDesc + x.SizeInBytes()};
   const char *yDesc{reinterpret_cast<const char *>(&y)};
@@ -133,8 +138,6 @@
   std::int64_t xLeast, xMost, yLeast, yMost;
   MaximalByteOffsetRange(x, xLeast, xMost);
   MaximalByteOffsetRange(y, yLeast, yMost);
-  const char *xBase{x.OffsetElement()};
-  const char *yBase{y.OffsetElement()};
   if (RangesOverlap(xDesc, xDescLast, yBase + yLeast, yBase + yMost) ||
       RangesOverlap(yDesc, yDescLast, xBase + xLeast, xBase + xMost)) {
     // A descriptor overlaps with the storage described by the other;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144134.497777.patch
Type: text/x-patch
Size: 1123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230215/7d88ea74/attachment-0001.bin>


More information about the flang-commits mailing list