From: Valentin Clement Date: Mon, 5 Dec 2022 17:26:16 +0000 (+0100) Subject: [flang] Retrieve rank before updating the pointer X-Git-Tag: upstream/17.0.6~25256 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87dfec9dc8991a9a14df3ce3443da296354b5d57;p=platform%2Fupstream%2Fllvm.git [flang] Retrieve rank before updating the pointer The code is iterating on the rank of the pointer to set the bounds. If the rank is retrieved after the `pointer = target` it does not reflect the actual rank of the pointer. This could happen in code like the following: ``` type t1 integer :: a end type type(t), pointer :: p(:) class(t), pointer :: q(:,:) q(0:1,-2:2) => p(10:1:-1) ``` Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D139327 --- diff --git a/flang/runtime/pointer.cpp b/flang/runtime/pointer.cpp index 843f916..1ce9139 100644 --- a/flang/runtime/pointer.cpp +++ b/flang/runtime/pointer.cpp @@ -87,9 +87,9 @@ void RTNAME(PointerAssociateLowerBounds)(Descriptor &pointer, void RTNAME(PointerAssociateRemapping)(Descriptor &pointer, const Descriptor &target, const Descriptor &bounds, const char *sourceFile, int sourceLine) { + int rank{pointer.rank()}; pointer = target; pointer.raw().attribute = CFI_attribute_pointer; - int rank{pointer.rank()}; Terminator terminator{sourceFile, sourceLine}; SubscriptValue byteStride{/*captured from first dimension*/}; std::size_t boundElementBytes{bounds.ElementBytes()};