diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp --- a/flang/runtime/assign.cpp +++ b/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(&x)}; const char *xDescLast{xDesc + x.SizeInBytes()}; const char *yDesc{reinterpret_cast(&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;