diff --git a/flang/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h index ea3e5b7558da..5bb86dbf4954 100644 --- a/flang/include/flang/Runtime/pointer.h +++ b/flang/include/flang/Runtime/pointer.h @@ -105,7 +105,7 @@ bool RTNAME(PointerIsAssociated)(const Descriptor &); // True when the pointer is associated with a specific target. bool RTNAME(PointerIsAssociatedWith)( - const Descriptor &, const Descriptor &target); + const Descriptor &, const Descriptor *target); } // extern "C" } // namespace Fortran::runtime diff --git a/flang/runtime/pointer.cpp b/flang/runtime/pointer.cpp index dd41e1f060aa..8aebf1a60304 100644 --- a/flang/runtime/pointer.cpp +++ b/flang/runtime/pointer.cpp @@ -147,16 +147,22 @@ bool RTNAME(PointerIsAssociated)(const Descriptor &pointer) { } bool RTNAME(PointerIsAssociatedWith)( - const Descriptor &pointer, const Descriptor &target) { + const Descriptor &pointer, const Descriptor *target) { + if (!target) { + return pointer.raw().base_addr != nullptr; + } + if (!target->raw().base_addr || target->ElementBytes() == 0) { + return false; + } int rank{pointer.rank()}; - if (pointer.raw().base_addr != target.raw().base_addr || - pointer.ElementBytes() != target.ElementBytes() || - rank != target.rank()) { + if (pointer.raw().base_addr != target->raw().base_addr || + pointer.ElementBytes() != target->ElementBytes() || + rank != target->rank()) { return false; } for (int j{0}; j < rank; ++j) { const Dimension &pDim{pointer.GetDimension(j)}; - const Dimension &tDim{target.GetDimension(j)}; + const Dimension &tDim{target->GetDimension(j)}; if (pDim.Extent() != tDim.Extent() || pDim.ByteStride() != tDim.ByteStride()) { return false;