[flang-commits] [flang] 49d718d - [flang] Pass box address for bind(c) assumed type dummy argument
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Mar 17 09:58:59 PDT 2023
Author: Valentin Clement
Date: 2023-03-17T17:58:53+01:00
New Revision: 49d718db86aa69eb63cb782024bdf39524557c5d
URL: https://github.com/llvm/llvm-project/commit/49d718db86aa69eb63cb782024bdf39524557c5d
DIFF: https://github.com/llvm/llvm-project/commit/49d718db86aa69eb63cb782024bdf39524557c5d.diff
LOG: [flang] Pass box address for bind(c) assumed type dummy argument
When interfacing with C code, assumed type should be passed as
basic pointer.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D146300
Added:
Modified:
flang/lib/Lower/CallInterface.cpp
flang/test/Lower/polymorphic-types.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 9e86541660685..8f4b52ac654ea 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -965,7 +965,14 @@ class Fortran::lower::CallInterfaceImpl {
mlir::Type boxType = fir::wrapInClassOrBoxType(
type, obj.type.type().IsPolymorphic(), obj.type.type().IsAssumedType());
- if (obj.attrs.test(Attrs::Allocatable) || obj.attrs.test(Attrs::Pointer)) {
+ if (obj.type.type().IsAssumedType() && isBindC) {
+ mlir::Type voidPtrType = fir::ReferenceType::get(
+ mlir::NoneType::get(&interface.converter.getMLIRContext()));
+ addFirOperand(voidPtrType, nextPassedArgPosition(), Property::BaseAddress,
+ attrs);
+ addPassedArg(PassEntityBy::BaseAddress, entity, characteristics);
+ } else if (obj.attrs.test(Attrs::Allocatable) ||
+ obj.attrs.test(Attrs::Pointer)) {
// Pass as fir.ref<fir.box> or fir.ref<fir.class>
mlir::Type boxRefType = fir::ReferenceType::get(boxType);
addFirOperand(boxRefType, nextPassedArgPosition(), Property::MutableBox,
diff --git a/flang/test/Lower/polymorphic-types.f90 b/flang/test/Lower/polymorphic-types.f90
index 62ddff090354d..ebd846d25dec4 100644
--- a/flang/test/Lower/polymorphic-types.f90
+++ b/flang/test/Lower/polymorphic-types.f90
@@ -172,13 +172,13 @@ subroutine assumed_type_dummy(a) bind(c)
end subroutine assumed_type_dummy
! CHECK-LABEL: func.func @assumed_type_dummy(
- ! CHECK-SAME: %{{.*}}: !fir.box<none>
+ ! CHECK-SAME: %{{.*}}: !fir.ref<none>
subroutine assumed_type_dummy_array(a) bind(c)
type(*) :: a(:)
end subroutine assumed_type_dummy_array
! CHECK-LABEL: func.func @assumed_type_dummy_array(
- ! CHECK-SAME: %{{.*}}: !fir.box<!fir.array<?xnone>>
+ ! CHECK-SAME: %{{.*}}: !fir.ref<none>
end module
More information about the flang-commits
mailing list