|
| 1 | +//===-- flang/unittests/Runtime/Support.cpp ----------------------*- C++-*-===// |
| 2 | +// |
| 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 |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "flang/Runtime/support.h" |
| 10 | +#include "gtest/gtest.h" |
| 11 | +#include "tools.h" |
| 12 | +#include "flang/Runtime/descriptor.h" |
| 13 | + |
| 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); |
| 21 | + |
| 22 | + StaticDescriptor<2, false> statDesc; |
| 23 | + Descriptor &result{statDesc.descriptor()}; |
| 24 | + |
| 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()); |
| 31 | + EXPECT_EQ( |
| 32 | + result.GetDimension(0).LowerBound(), x->GetDimension(0).LowerBound()); |
| 33 | + EXPECT_EQ(result.GetDimension(1).Extent(), x->GetDimension(1).Extent()); |
| 34 | + EXPECT_EQ( |
| 35 | + result.GetDimension(1).LowerBound(), x->GetDimension(1).LowerBound()); |
| 36 | + |
| 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); |
| 47 | + |
| 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); |
| 58 | +} |
0 commit comments