[flang-commits] [flang] 943b4c9 - [flang] Handle dispatch on nopass procedure from array element

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Nov 2 08:52:32 PDT 2022


Author: Valentin Clement
Date: 2022-11-02T16:52:25+01:00
New Revision: 943b4c90a9644dbceea231a86d59520dd3c2a6db

URL: https://github.com/llvm/llvm-project/commit/943b4c90a9644dbceea231a86d59520dd3c2a6db
DIFF: https://github.com/llvm/llvm-project/commit/943b4c90a9644dbceea231a86d59520dd3c2a6db.diff

LOG: [flang] Handle dispatch on nopass procedure from array element

When a fir.dispatch is done with a NOPASS type-bound
procedure, the object in fir.dispatch is just used to gather the vtable.
Therefore, no transformation is done on it and the original entity
is used. The current code generation didn't expect the entity to be an array.
This patch update the code generation to be able to retrieve the vtable
accordingly.

Reviewed By: PeteSteinfeld

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

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp
    flang/test/Fir/dispatch.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index fae601b84671d..be49a0bf509be 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -915,12 +915,17 @@ struct DispatchOpConversion : public FIROpConversion<fir::DispatchOp> {
       return emitError(loc) << "no binding tables found";
 
     // Get derived type information.
-    auto declaredType = llvm::TypeSwitch<mlir::Type, mlir::Type>(
-                            dispatch.getObject().getType().getEleTy())
-                            .Case<fir::PointerType, fir::HeapType>(
-                                [](auto p) { return p.getEleTy(); })
-                            .Default([](mlir::Type t) { return t; });
-
+    auto declaredType =
+        llvm::TypeSwitch<mlir::Type, mlir::Type>(
+            dispatch.getObject().getType().getEleTy())
+            .Case<fir::PointerType, fir::HeapType, fir::SequenceType>(
+                [](auto p) {
+                  if (auto seq =
+                          p.getEleTy().template dyn_cast<fir::SequenceType>())
+                    return seq.getEleTy();
+                  return p.getEleTy();
+                })
+            .Default([](mlir::Type t) { return t; });
     assert(declaredType.isa<fir::RecordType>() && "expecting fir.type");
     auto recordType = declaredType.dyn_cast<fir::RecordType>();
     std::string typeDescName =

diff  --git a/flang/test/Fir/dispatch.f90 b/flang/test/Fir/dispatch.f90
index e3e75f20ea45d..7b462df81c52f 100644
--- a/flang/test/Fir/dispatch.f90
+++ b/flang/test/Fir/dispatch.f90
@@ -120,6 +120,21 @@ subroutine display_class(p)
     call p%proc_pass(1)
   end subroutine
 
+  subroutine no_pass_array(a)
+    class(p1) :: a(:)
+    call a(1)%proc_nopass()
+  end subroutine
+
+  subroutine no_pass_array_allocatable(a)
+    class(p1), allocatable :: a(:)
+    call a(1)%proc_nopass()
+  end subroutine
+
+  subroutine no_pass_array_pointer(a)
+    class(p1), allocatable :: a(:)
+    call a(1)%proc_nopass()
+  end subroutine
+
 end module
 
 program test_type_to_class
@@ -232,6 +247,9 @@ program test_type_to_class
 ! CHECK: %[[FUNC_PTR:.*]] = inttoptr i64 %[[FUNC_ADDR]] to ptr
 ! CHECK: call void %[[FUNC_PTR]](ptr %[[INT32]], ptr %[[CLASS]])
 
+! CHECK-LABEL: _QMdispatch1Pno_pass_array
+! CHECK-LABEL: _QMdispatch1Pno_pass_array_allocatable
+! CHECK-LABEL: _QMdispatch1Pno_pass_array_pointer
 
 ! Check the layout of the binding table. This is easier to do in FIR than in 
 ! LLVM IR.


        


More information about the flang-commits mailing list