[flang-commits] [flang] 4235bf7 - [flang] Adapt PointerIsAssociatedWith for empty derived-type

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Mar 8 13:04:05 PST 2023


Author: Valentin Clement
Date: 2023-03-08T22:03:59+01:00
New Revision: 4235bf7a0844bd1679c80f7a9166fbbfb363b5f4

URL: https://github.com/llvm/llvm-project/commit/4235bf7a0844bd1679c80f7a9166fbbfb363b5f4
DIFF: https://github.com/llvm/llvm-project/commit/4235bf7a0844bd1679c80f7a9166fbbfb363b5f4.diff

LOG: [flang] Adapt PointerIsAssociatedWith for empty derived-type

When a derived-type as no component, its elem_len will be set to
zero when emboxed. Update the function to let empty derived-type
pointer/target succeed the test.

Example extracted from gfortran test pointer_init_8

```
module m
  type :: c
  end type c
  type, extends(c) :: d
  end type d
  type(c), target :: x
end module

use m
  class(c), pointer :: px => x

  if (.not. associated(px, x))   STOP 1
end
```

Reviewed By: klausler

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

Added: 
    

Modified: 
    flang/runtime/pointer.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/pointer.cpp b/flang/runtime/pointer.cpp
index 7305b1e54223c..a0a11e96a6883 100644
--- a/flang/runtime/pointer.cpp
+++ b/flang/runtime/pointer.cpp
@@ -206,7 +206,7 @@ bool RTNAME(PointerIsAssociatedWith)(
   if (!target) {
     return pointer.raw().base_addr != nullptr;
   }
-  if (!target->raw().base_addr || target->ElementBytes() == 0) {
+  if (!target->raw().base_addr) {
     return false;
   }
   int rank{pointer.rank()};


        


More information about the flang-commits mailing list