assert(component && "expect component for type-bound procedure call.");
fir::ExtendedValue pass =
symMap.lookupSymbol(component->GetFirstSymbol()).toExtendedValue();
+ mlir::Value passObject = fir::getBase(pass);
+ if (fir::isa_ref_type(passObject.getType()))
+ passObject = builder.create<fir::ConvertOp>(
+ loc,
+ passObject.getType().dyn_cast<fir::ReferenceType>().getEleTy(),
+ passObject);
dispatch = builder.create<fir::DispatchOp>(
loc, funcType.getResults(), builder.getStringAttr(procName),
- fir::getBase(pass), operands, nullptr);
+ passObject, operands, nullptr);
}
callResult = dispatch.getResult(0);
callNumResults = dispatch.getNumResults();
#include "mlir/Pass/PassManager.h"
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/TypeSwitch.h"
namespace fir {
#define GEN_PASS_DEF_FIRTOLLVMLOWERING
if (bindingTables.empty())
return emitError(loc) << "no binding tables found";
- if (dispatch.getObject()
- .getType()
- .getEleTy()
- .isa<fir::HeapType, fir::PointerType>())
- TODO(loc,
- "fir.dispatch with allocatable or pointer polymorphic entities");
-
// Get derived type information.
- auto declaredType = dispatch.getObject().getType().getEleTy();
+ 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; });
+
assert(declaredType.isa<fir::RecordType>() && "expecting fir.type");
auto recordType = declaredType.dyn_cast<fir::RecordType>();
std::string typeDescName =
type p1
integer :: a
integer :: b
+ contains
+ procedure, nopass :: proc1 => proc1_p1
end type
type, extends(p1) :: p2
integer :: c
+ contains
+ procedure, nopass :: proc1 => proc1_p2
end type
+
+contains
+ subroutine proc1_p1()
+ print*, 'call proc1_p1'
+ end subroutine
+
+ subroutine proc1_p2()
+ print*, 'call proc1_p2'
+ end subroutine
end module
program test_allocatable
allocate(p1::c3(10))
allocate(p2::c4(20))
+ call c1%proc1()
+ call c2%proc1()
end
! CHECK-LABEL: func.func @_QQmain()