1//===-- flang/unittests/Runtime/Pointer.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 "gtest/gtest.h"
10#include "tools.h"
11#include "flang/Runtime/derived-api.h"
12#include "flang/Runtime/descriptor.h"
13
14using namespace Fortran::runtime;
15
16TEST(Derived, SameTypeAs) {
17 // INTEGER, POINTER :: i1
18 auto 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));
22
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));
26
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;
32
33 EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *a1));
34 EXPECT_FALSE(RTNAME(SameTypeAs)(*a1, *i1));
35 EXPECT_FALSE(RTNAME(SameTypeAs)(*r1, *a1));
36
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;
42
43 EXPECT_FALSE(RTNAME(SameTypeAs)(*a1, *a2));
44
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;
50
51 EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *p1));
52 EXPECT_FALSE(RTNAME(SameTypeAs)(*p1, *i1));
53}
54
55TEST(Derived, ExtendsTypeOf) {
56 // CLASS(*), POINTER :: i1 - INTEGER dynamic type
57 auto i1{
58 Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Integer, 4}, 4,
59 nullptr, 0, nullptr, CFI_attribute_pointer)};
60 EXPECT_TRUE(RTNAME(ExtendsTypeOf)(*i1, *i1));
61
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));
66}
67

source code of flang/unittests/Runtime/Derived.cpp