[flang-commits] [flang] 5d7c5e6 - [flang] Fix fir.dispatch_table generation with derived-type parameter with kind type parameter

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Dec 16 12:22:02 PST 2022


Author: Valentin Clement
Date: 2022-12-16T21:21:54+01:00
New Revision: 5d7c5e619963861ede2ce8112cc8947f81c8ebbd

URL: https://github.com/llvm/llvm-project/commit/5d7c5e619963861ede2ce8112cc8947f81c8ebbd
DIFF: https://github.com/llvm/llvm-project/commit/5d7c5e619963861ede2ce8112cc8947f81c8ebbd.diff

LOG: [flang] Fix fir.dispatch_table generation with derived-type parameter with kind type parameter

When generating the `fir.dispatch_table` operation, the name of the parent
derived-type needs to be mangled. For this the type instantiation
DerivedTypeSpec needs to be retrieved to have the correct kind type parameters.

Reviewed By: PeteSteinfeld

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

Added: 
    

Modified: 
    flang/lib/Evaluate/type.cpp
    flang/test/Fir/dispatch.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index 79bd8366fb2b8..5b356aa8377fe 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -209,7 +209,11 @@ const semantics::DerivedTypeSpec *GetDerivedTypeSpec(const DynamicType &type) {
 static const semantics::Symbol *FindParentComponent(
     const semantics::DerivedTypeSpec &derived) {
   const semantics::Symbol &typeSymbol{derived.typeSymbol()};
-  if (const semantics::Scope * scope{typeSymbol.scope()}) {
+  const semantics::Scope *scope{derived.scope()};
+  if (!scope) {
+    scope = typeSymbol.scope();
+  }
+  if (scope) {
     const auto &dtDetails{typeSymbol.get<semantics::DerivedTypeDetails>()};
     if (auto extends{dtDetails.GetParentComponentName()}) {
       if (auto iter{scope->find(*extends)}; iter != scope->cend()) {

diff  --git a/flang/test/Fir/dispatch.f90 b/flang/test/Fir/dispatch.f90
index eadc9251ba06f..dcb52bed7d967 100644
--- a/flang/test/Fir/dispatch.f90
+++ b/flang/test/Fir/dispatch.f90
@@ -44,6 +44,16 @@ module dispatch1
     procedure :: a1_proc => a2_proc
   end type
 
+  type ty_kind(i, j)
+    integer, kind :: i, j
+    integer :: a(i)
+  end Type
+
+  type, extends(ty_kind) :: ty_kind_ex
+    integer :: b(j)
+  end type
+  type(ty_kind(10,20)) :: tk1
+  type(ty_kind_ex(10,20)) :: tke1
 contains
 
   subroutine display1_p1(this)
@@ -280,6 +290,9 @@ program test_type_to_class
 ! Check the layout of the binding table. This is easier to do in FIR than in 
 ! LLVM IR.
 
+! BT-LABEL: fir.dispatch_table @_QMdispatch1Tty_kindK10K20
+! BT-LABEL: fir.dispatch_table @_QMdispatch1Tty_kind_exK10K20 extends("_QMdispatch1Tty_kindK10K20")
+
 ! BT-LABEL: fir.dispatch_table @_QMdispatch1Tp1 {
 ! BT: fir.dt_entry "aproc", @_QMdispatch1Paproc
 ! BT: fir.dt_entry "display1", @_QMdispatch1Pdisplay1_p1


        


More information about the flang-commits mailing list