[flang-commits] [flang] 4143d3e - [flang] Unlimited polymoprhic allocated as character
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Feb 8 07:31:54 PST 2023
Author: Valentin Clement
Date: 2023-02-08T16:31:48+01:00
New Revision: 4143d3ebd2d8fbefc8d7ba2cded304a6049aed7f
URL: https://github.com/llvm/llvm-project/commit/4143d3ebd2d8fbefc8d7ba2cded304a6049aed7f
DIFF: https://github.com/llvm/llvm-project/commit/4143d3ebd2d8fbefc8d7ba2cded304a6049aed7f.diff
LOG: [flang] Unlimited polymoprhic allocated as character
Allocation of unlimited polymorphic allocatable with
character intrinsic type is now done through
`PointerNullifyCharacter` or `AllocatableInitCharacter` so the length
is correctly set.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D143580
Added:
Modified:
flang/lib/Lower/Allocatable.cpp
flang/test/Lower/allocatable-polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 36bade3ea87fa..cfda1ac629773 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -141,7 +141,7 @@ static void genRuntimeSetBounds(fir::FirOpBuilder &builder, mlir::Location loc,
static void genRuntimeInitCharacter(fir::FirOpBuilder &builder,
mlir::Location loc,
const fir::MutableBoxValue &box,
- mlir::Value len) {
+ mlir::Value len, int64_t kind = 0) {
mlir::func::FuncOp callee =
box.isPointer()
? fir::runtime::getRuntimeFunc<mkRTKey(PointerNullifyCharacter)>(
@@ -155,7 +155,8 @@ static void genRuntimeInitCharacter(fir::FirOpBuilder &builder,
llvm::SmallVector<mlir::Value> args;
args.push_back(builder.createConvert(loc, inputTypes[0], box.getAddr()));
args.push_back(builder.createConvert(loc, inputTypes[1], len));
- int kind = box.getEleTy().cast<fir::CharacterType>().getFKind();
+ if (kind == 0)
+ kind = box.getEleTy().cast<fir::CharacterType>().getFKind();
args.push_back(builder.createIntegerConstant(loc, inputTypes[2], kind));
int rank = box.rank();
args.push_back(builder.createIntegerConstant(loc, inputTypes[3], rank));
@@ -663,10 +664,17 @@ class AllocateStmtHelper {
// unlimited polymorphic entity.
if (typeSpec->AsIntrinsic() &&
fir::isUnlimitedPolymorphicType(fir::getBase(box).getType())) {
- genInitIntrinsic(
- box, typeSpec->AsIntrinsic()->category(),
- Fortran::evaluate::ToInt64(typeSpec->AsIntrinsic()->kind()).value(),
- alloc.getSymbol().Rank());
+ if (typeSpec->AsIntrinsic()->category() == TypeCategory::Character) {
+ genRuntimeInitCharacter(
+ builder, loc, box, lenParams[0],
+ Fortran::evaluate::ToInt64(typeSpec->AsIntrinsic()->kind())
+ .value());
+ } else {
+ genInitIntrinsic(
+ box, typeSpec->AsIntrinsic()->category(),
+ Fortran::evaluate::ToInt64(typeSpec->AsIntrinsic()->kind()).value(),
+ alloc.getSymbol().Rank());
+ }
return;
}
diff --git a/flang/test/Lower/allocatable-polymorphic.f90 b/flang/test/Lower/allocatable-polymorphic.f90
index 448c49bc5ca65..674c6b989b0ee 100644
--- a/flang/test/Lower/allocatable-polymorphic.f90
+++ b/flang/test/Lower/allocatable-polymorphic.f90
@@ -536,6 +536,22 @@ subroutine test_allocatable_up_from_mold_rank(a)
! CHECK: %[[BOX_NONE_10:.*]] = fir.convert %[[EMBOX_10]] : (!fir.box<i32>) -> !fir.box<none>
! CHECK: %{{.*}} = fir.call @_FortranAAllocatableAllocateSource(%[[A_BOX_NONE]], %[[BOX_NONE_10]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
+ subroutine test_allocatable_up_character()
+ class(*), allocatable :: a
+ allocate(character*10::a)
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMpolyPtest_allocatable_up_character() {
+! CHECK: %[[A:.*]] = fir.alloca !fir.class<!fir.heap<none>> {bindc_name = "a", uniq_name = "_QMpolyFtest_allocatable_up_characterEa"}
+! CHECK: %[[LEN:.*]] = arith.constant 10 : i64
+! CHECK: %[[A_NONE:.*]] = fir.convert %[[A]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %[[KIND:.*]] = arith.constant 1 : i32
+! CHECK: %[[RANK:.*]] = arith.constant 0 : i32
+! CHECK: %[[CORANK:.*]] = arith.constant 0 : i32
+! CHECK: %{{.*}} = fir.call @_FortranAAllocatableInitCharacter(%[[A_NONE]], %[[LEN]], %[[KIND]], %[[RANK]], %[[CORANK]]) {{.*}} : (!fir.ref<!fir.box<none>>, i64, i32, i32, i32) -> none
+! CHECK: %[[A_NONE:.*]] = fir.convert %[[A:.*]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %{{.*}} = fir.call @_FortranAAllocatableAllocate(%[[A_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
+
end module
More information about the flang-commits
mailing list