diff options
author | Valentin Clement <clementval@gmail.com> | 2023-03-09 15:46:59 +0100 |
---|---|---|
committer | Valentin Clement <clementval@gmail.com> | 2023-03-09 15:47:39 +0100 |
commit | 188c02daaa24a484507a5e20db475180e793ccfd (patch) | |
tree | 01532f5150d1c4d262852a63d44cf559843652f8 /flang/unittests | |
parent | 1a4d0eb866be909fe16da5ebffe4122aa0693d8c (diff) | |
download | llvm-188c02daaa24a484507a5e20db475180e793ccfd.tar.gz |
[flang] Simplify same_type_as condition
Restore the behavior changed in D145384 and add proper
unit tests.
Unallocated unlimited poymorphic allocatable and disassociated
unlimited polymorphic pointer should return false.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D145674
Diffstat (limited to 'flang/unittests')
-rw-r--r-- | flang/unittests/Runtime/Derived.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/flang/unittests/Runtime/Derived.cpp b/flang/unittests/Runtime/Derived.cpp index 7e5436778020..89306c82f5d9 100644 --- a/flang/unittests/Runtime/Derived.cpp +++ b/flang/unittests/Runtime/Derived.cpp @@ -24,21 +24,30 @@ TEST(Derived, SameTypeAs) { 4, nullptr, 0, nullptr, CFI_attribute_pointer)}; EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *r1)); - // CLASS(*), ALLOCATABLE :: p1 - auto p1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, + // CLASS(*), ALLOCATABLE :: a1 + auto a1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, 4, nullptr, 0, nullptr, CFI_attribute_allocatable)}; - p1->raw().elem_len = 0; - p1->raw().type = CFI_type_other; + a1->raw().elem_len = 0; + a1->raw().type = CFI_type_other; - EXPECT_TRUE(RTNAME(SameTypeAs)(*i1, *p1)); - EXPECT_TRUE(RTNAME(SameTypeAs)(*p1, *i1)); - EXPECT_TRUE(RTNAME(SameTypeAs)(*r1, *p1)); + EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *a1)); + EXPECT_FALSE(RTNAME(SameTypeAs)(*a1, *i1)); + EXPECT_FALSE(RTNAME(SameTypeAs)(*r1, *a1)); - // CLASS(*), ALLOCATABLE :: p2 - auto p2{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, + // CLASS(*), ALLOCATABLE :: a2 + auto a2{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, 4, nullptr, 0, nullptr, CFI_attribute_allocatable)}; - p2->raw().elem_len = 0; - p2->raw().type = CFI_type_other; + a2->raw().elem_len = 0; + a2->raw().type = CFI_type_other; + + EXPECT_FALSE(RTNAME(SameTypeAs)(*a1, *a2)); + + // CLASS(*), POINTER :: p1 + auto p1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, + 4, nullptr, 0, nullptr, CFI_attribute_pointer)}; + p1->raw().elem_len = 0; + p1->raw().type = CFI_type_other; - EXPECT_TRUE(RTNAME(SameTypeAs)(*p1, *p2)); + EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *p1)); + EXPECT_FALSE(RTNAME(SameTypeAs)(*p1, *i1)); } |