Skip to content

Commit 53f0d03

Browse files
jeanPerierDanielCChen
authored andcommitted
[flang] Lower passing non assumed-rank/size to assumed-ranks (llvm#79145)
Start implementing assumed-rank support as described in https://github.com/llvm/llvm-project/blob/main/flang/docs/AssumedRank.md This commit holds the minimal support for lowering calls to procedure with assumed-rank arguments where the procedure implementation is done in C. The case for passing assumed-size to assumed-rank is left TODO since it will be done a change in assumed-size lowering that is better done in another patch. Care is taken to set the lower bounds to zero when passing non allocatable no pointer as descriptor to a BIND(C) procedure as required per 18.5.3 point 3. This was not done before while the requirements also applies to non assumed-rank descriptors. This change required special attention with IGNORE_TKR(t) to avoid emitting invalid fir.rebox operations (the actual argument type must be used in this case as the output type). Implementation of Fortran procedure with assumed-rank arguments is still TODO.
1 parent 3911eb4 commit 53f0d03

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

flang/lib/Lower/CallInterface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,25 +1118,25 @@ class Fortran::lower::CallInterfaceImpl {
11181118
Property::Value);
11191119
return;
11201120
}
1121-
11221121
const Fortran::evaluate::characteristics::TypeAndShape *typeAndShape =
11231122
result.GetTypeAndShape();
11241123
assert(typeAndShape && "expect type for non proc pointer result");
11251124
mlirType = translateDynamicType(typeAndShape->type());
1126-
fir::SequenceType::Shape bounds = getBounds(typeAndShape->shape());
11271125
const auto *resTypeAndShape{result.GetTypeAndShape()};
11281126
bool resIsPolymorphic =
11291127
resTypeAndShape && resTypeAndShape->type().IsPolymorphic();
11301128
bool resIsAssumedType =
11311129
resTypeAndShape && resTypeAndShape->type().IsAssumedType();
1132-
if (!bounds.empty())
1133-
mlirType = fir::SequenceType::get(bounds, mlirType);
1130+
if (std::optional<fir::SequenceType::Shape> bounds =
1131+
getBounds(*typeAndShape))
1132+
mlirType = fir::SequenceType::get(*bounds, mlirType);
11341133
if (result.attrs.test(Attr::Allocatable))
1135-
mlirType = fir::wrapInClassOrBoxType(fir::HeapType::get(mlirType),
1136-
resIsPolymorphic, resIsAssumedType);
1134+
mlirType = fir::wrapInClassOrBoxType(
1135+
fir::HeapType::get(mlirType), resIsPolymorphic, resIsAssumedType);
11371136
if (result.attrs.test(Attr::Pointer))
1138-
mlirType = fir::wrapInClassOrBoxType(fir::PointerType::get(mlirType),
1139-
resIsPolymorphic, resIsAssumedType);
1137+
mlirType =
1138+
fir::wrapInClassOrBoxType(fir::PointerType::get(mlirType),
1139+
resIsPolymorphic, resIsAssumedType);
11401140

11411141
if (fir::isa_char(mlirType)) {
11421142
// Character scalar results must be passed as arguments in lowering so

0 commit comments

Comments
 (0)