[flang-commits] [flang] 87dfec9 - [flang] Retrieve rank before updating the pointer

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Dec 5 09:27:29 PST 2022


Author: Valentin Clement
Date: 2022-12-05T18:27:19+01:00
New Revision: 87dfec9dc8991a9a14df3ce3443da296354b5d57

URL: https://github.com/llvm/llvm-project/commit/87dfec9dc8991a9a14df3ce3443da296354b5d57
DIFF: https://github.com/llvm/llvm-project/commit/87dfec9dc8991a9a14df3ce3443da296354b5d57.diff

LOG: [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

Added: 
    

Modified: 
    flang/runtime/pointer.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/pointer.cpp b/flang/runtime/pointer.cpp
index 843f9165f8554..1ce913940263e 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()};


        


More information about the flang-commits mailing list