Skip to content

Commit

Permalink
[flang] Fix fir.dispatch_table generation with derived-type parameter…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
clementval committed Dec 16, 2022
1 parent b2b680a commit 5d7c5e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flang/lib/Evaluate/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Fir/dispatch.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5d7c5e6

Please sign in to comment.