1 //===-- flang/unittests/Runtime/Pointer.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 "gtest/gtest.h"
11 #include "flang/Runtime/derived-api.h"
12 #include "flang/Runtime/descriptor.h"
14 using namespace Fortran::runtime
;
16 TEST(Derived
, SameTypeAs
) {
17 // INTEGER, POINTER :: i1
19 Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Integer
, 4}, 4,
20 nullptr, 0, nullptr, CFI_attribute_pointer
)};
21 EXPECT_TRUE(RTNAME(SameTypeAs
)(*i1
, *i1
));
23 auto r1
{Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Real
, 4},
24 4, nullptr, 0, nullptr, CFI_attribute_pointer
)};
25 EXPECT_FALSE(RTNAME(SameTypeAs
)(*i1
, *r1
));
27 // CLASS(*), ALLOCATABLE :: a1
28 auto a1
{Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Real
, 4},
29 4, nullptr, 0, nullptr, CFI_attribute_allocatable
)};
30 a1
->raw().elem_len
= 0;
31 a1
->raw().type
= CFI_type_other
;
33 EXPECT_FALSE(RTNAME(SameTypeAs
)(*i1
, *a1
));
34 EXPECT_FALSE(RTNAME(SameTypeAs
)(*a1
, *i1
));
35 EXPECT_FALSE(RTNAME(SameTypeAs
)(*r1
, *a1
));
37 // CLASS(*), ALLOCATABLE :: a2
38 auto a2
{Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Real
, 4},
39 4, nullptr, 0, nullptr, CFI_attribute_allocatable
)};
40 a2
->raw().elem_len
= 0;
41 a2
->raw().type
= CFI_type_other
;
43 EXPECT_FALSE(RTNAME(SameTypeAs
)(*a1
, *a2
));
45 // CLASS(*), POINTER :: p1
46 auto p1
{Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Real
, 4},
47 4, nullptr, 0, nullptr, CFI_attribute_pointer
)};
48 p1
->raw().elem_len
= 0;
49 p1
->raw().type
= CFI_type_other
;
51 EXPECT_FALSE(RTNAME(SameTypeAs
)(*i1
, *p1
));
52 EXPECT_FALSE(RTNAME(SameTypeAs
)(*p1
, *i1
));
55 TEST(Derived
, ExtendsTypeOf
) {
56 // CLASS(*), POINTER :: i1 - INTEGER dynamic type
58 Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Integer
, 4}, 4,
59 nullptr, 0, nullptr, CFI_attribute_pointer
)};
60 EXPECT_TRUE(RTNAME(ExtendsTypeOf
)(*i1
, *i1
));
62 // CLASS(*), POINTER :: r1 - REAL dynamic type
63 auto r1
{Descriptor::Create(TypeCode
{Fortran::common::TypeCategory::Real
, 4},
64 4, nullptr, 0, nullptr, CFI_attribute_pointer
)};
65 EXPECT_FALSE(RTNAME(SameTypeAs
)(*i1
, *r1
));