diff --git a/flang/runtime/derived-api.cpp b/flang/runtime/derived-api.cpp --- a/flang/runtime/derived-api.cpp +++ b/flang/runtime/derived-api.cpp @@ -110,6 +110,10 @@ } bool RTNAME(ExtendsTypeOf)(const Descriptor &a, const Descriptor &mold) { + if (a.raw().type != CFI_type_struct && a.raw().type != CFI_type_other && + mold.raw().type != CFI_type_struct && mold.raw().type != CFI_type_other) + return a.raw().type == mold.raw().type; + const typeInfo::DerivedType *derivedTypeA{GetDerivedType(a)}; const typeInfo::DerivedType *derivedTypeMold{GetDerivedType(mold)}; diff --git a/flang/unittests/Runtime/Derived.cpp b/flang/unittests/Runtime/Derived.cpp --- a/flang/unittests/Runtime/Derived.cpp +++ b/flang/unittests/Runtime/Derived.cpp @@ -51,3 +51,16 @@ EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *p1)); EXPECT_FALSE(RTNAME(SameTypeAs)(*p1, *i1)); } + +TEST(Derived, ExtendsTypeOf) { + // CLASS(*), POINTER :: i1 - INTEGER dynamic type + auto i1{ + Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Integer, 4}, 4, + nullptr, 0, nullptr, CFI_attribute_pointer)}; + EXPECT_TRUE(RTNAME(ExtendsTypeOf)(*i1, *i1)); + + // CLASS(*), POINTER :: r1 - REAL dynamic type + auto r1{Descriptor::Create(TypeCode{Fortran::common::TypeCategory::Real, 4}, + 4, nullptr, 0, nullptr, CFI_attribute_pointer)}; + EXPECT_FALSE(RTNAME(SameTypeAs)(*i1, *r1)); +}