summaryrefslogtreecommitdiff
path: root/flang/unittests
diff options
context:
space:
mode:
authorValentin Clement <clementval@gmail.com>2023-03-20 10:00:08 +0100
committerValentin Clement <clementval@gmail.com>2023-03-20 10:00:43 +0100
commit52e239794f35be6a68b2273f88a99d9207e77cab (patch)
treec692e616a2bbcedd86035bc5d19f56bbad331355 /flang/unittests
parent257f4fd3b9e47cf66d4fcd20b598a17fcd2282f5 (diff)
downloadllvm-52e239794f35be6a68b2273f88a99d9207e77cab.tar.gz
[flang] Add AllocatableInit functions for use in allocate lowering
`AllocatableInitIntrinsic`, `AllocatableInitCharacter` and `AllocatableInitDerived` are meant to be used to initialize a descriptor when it is instantiated and not to be used multiple times in a scope. Add `AllocatableInitDerivedForAllocate`, `AllocatableInitCharacterForAllocate` and `AllocatableInitDerivedForAllocate` to be used for the allocation in allocate statement. These new functions are meant to be used on an initialized descriptor and will return directly if the descriptor is allocated so the error handling is done by the call to `AllocatableAllocate`. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D146290
Diffstat (limited to 'flang/unittests')
-rw-r--r--flang/unittests/Runtime/Allocatable.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/flang/unittests/Runtime/Allocatable.cpp b/flang/unittests/Runtime/Allocatable.cpp
index 8e1ec467b89f..ed8e91932049 100644
--- a/flang/unittests/Runtime/Allocatable.cpp
+++ b/flang/unittests/Runtime/Allocatable.cpp
@@ -94,3 +94,20 @@ TEST(AllocatableTest, AllocateFromScalarSource) {
EXPECT_EQ(*a->OffsetElement<float>(), 3.4F);
a->Destroy();
}
+
+TEST(AllocatableTest, DoubleAllocation) {
+ // CLASS(*), ALLOCATABLE :: r
+ // ALLOCATE(REAL::r)
+ auto r{createAllocatable(TypeCategory::Real, 4, 0)};
+ EXPECT_FALSE(r->IsAllocated());
+ EXPECT_TRUE(r->IsAllocatable());
+ RTNAME(AllocatableAllocate)(*r);
+ EXPECT_TRUE(r->IsAllocated());
+
+ // Make sure AllocatableInitIntrinsicForAllocate doesn't reset the decsriptor
+ // if it is allocated.
+ // ALLOCATE(INTEGER::r)
+ RTNAME(AllocatableInitIntrinsicForAllocate)
+ (*r, Fortran::common::TypeCategory::Integer, 4);
+ EXPECT_TRUE(r->IsAllocated());
+}