1 //===-- flang/unittests/Runtime/Support.cpp ----------------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "flang/Runtime/support.h"
10 #include "gtest/gtest.h"
12 #include "flang/Runtime/descriptor.h"
14 using namespace Fortran::runtime
;
15 using Fortran::common::TypeCategory
;
16 TEST(CopyAndUpdateDescriptor
, Basic
) {
17 auto x
{MakeArray
<TypeCategory::Integer
, 4>(
18 std::vector
<int>{2, 3}, std::vector
<std::int32_t>{0, 1, 2, 3, 4, 5})};
19 x
->GetDimension(0).SetLowerBound(11);
20 x
->GetDimension(1).SetLowerBound(12);
22 StaticDescriptor
<2, false> statDesc
;
23 Descriptor
&result
{statDesc
.descriptor()};
25 RTNAME(CopyAndUpdateDescriptor
)
26 (result
, *x
, nullptr, CFI_attribute_pointer
, LowerBoundModifier::Preserve
);
27 ASSERT_EQ(result
.rank(), 2);
28 EXPECT_EQ(result
.raw().base_addr
, x
->raw().base_addr
);
29 EXPECT_TRUE(result
.IsPointer());
30 EXPECT_EQ(result
.GetDimension(0).Extent(), x
->GetDimension(0).Extent());
32 result
.GetDimension(0).LowerBound(), x
->GetDimension(0).LowerBound());
33 EXPECT_EQ(result
.GetDimension(1).Extent(), x
->GetDimension(1).Extent());
35 result
.GetDimension(1).LowerBound(), x
->GetDimension(1).LowerBound());
37 RTNAME(CopyAndUpdateDescriptor
)
38 (result
, *x
, nullptr, CFI_attribute_allocatable
,
39 LowerBoundModifier::SetToZeroes
);
40 ASSERT_EQ(result
.rank(), 2);
41 EXPECT_EQ(result
.raw().base_addr
, x
->raw().base_addr
);
42 EXPECT_TRUE(result
.IsAllocatable());
43 EXPECT_EQ(result
.GetDimension(0).Extent(), x
->GetDimension(0).Extent());
44 EXPECT_EQ(result
.GetDimension(0).LowerBound(), 0);
45 EXPECT_EQ(result
.GetDimension(1).Extent(), x
->GetDimension(1).Extent());
46 EXPECT_EQ(result
.GetDimension(1).LowerBound(), 0);
48 RTNAME(CopyAndUpdateDescriptor
)
49 (result
, *x
, nullptr, CFI_attribute_other
, LowerBoundModifier::SetToOnes
);
50 ASSERT_EQ(result
.rank(), 2);
51 EXPECT_EQ(result
.raw().base_addr
, x
->raw().base_addr
);
52 EXPECT_FALSE(result
.IsAllocatable());
53 EXPECT_FALSE(result
.IsPointer());
54 EXPECT_EQ(result
.GetDimension(0).Extent(), x
->GetDimension(0).Extent());
55 EXPECT_EQ(result
.GetDimension(0).LowerBound(), 1);
56 EXPECT_EQ(result
.GetDimension(1).Extent(), x
->GetDimension(1).Extent());
57 EXPECT_EQ(result
.GetDimension(1).LowerBound(), 1);
60 TEST(IsAssumedSize
, Basic
) {
61 auto x
{MakeArray
<TypeCategory::Integer
, 4>(
62 std::vector
<int>{2, 3}, std::vector
<std::int32_t>{0, 1, 2, 3, 4, 5})};
63 EXPECT_FALSE(RTNAME(IsAssumedSize
)(*x
));
64 x
->GetDimension(1).SetExtent(-1);
65 EXPECT_TRUE(RTNAME(IsAssumedSize
)(*x
));
66 auto scalar
{MakeArray
<TypeCategory::Integer
, 4>(
67 std::vector
<int>{}, std::vector
<std::int32_t>{0})};
68 EXPECT_FALSE(RTNAME(IsAssumedSize
)(*scalar
));