[flang-commits] [flang] 74a5d74 - [flang][runtime] MayAlias() must be false for unallocated descriptors

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Feb 15 13:25:30 PST 2023


Author: Peter Klausler
Date: 2023-02-15T13:25:16-08:00
New Revision: 74a5d7471fbd8d5826c2a04585d34718a594a591

URL: https://github.com/llvm/llvm-project/commit/74a5d7471fbd8d5826c2a04585d34718a594a591
DIFF: https://github.com/llvm/llvm-project/commit/74a5d7471fbd8d5826c2a04585d34718a594a591.diff

LOG: [flang][runtime] MayAlias() must be false for unallocated descriptors

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.

Differential Revision: https://reviews.llvm.org/D144134

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 2f9814dad721..ca8039b6b0eb 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -126,6 +126,11 @@ static inline bool RangesOverlap(const char *aStart, const char *aEnd,
 // 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 @@ static bool MayAlias(const Descriptor &x, const Descriptor &y) {
   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;


        


More information about the flang-commits mailing list