summaryrefslogtreecommitdiff
path: root/flang-rt
diff options
context:
space:
mode:
authorAndre Kuhlenschmidt <andre.kuhlenschmidt@gmail.com>2025-10-01 16:40:00 -0700
committerGitHub <noreply@github.com>2025-10-01 16:40:00 -0700
commit4fccaaef700b64db06b7438802ccc58c3bb5b970 (patch)
tree535695892be9eb5108b4cc56034c5fe44b2f500f /flang-rt
parent52b185075919a3d8ec9dc6b7d7da365e28532735 (diff)
[flang][runtime] fix intrinsics case of extends_type_of (#161466)
Fixes https://github.com/llvm/llvm-project/issues/155459 by making sure the cases are considered in the right order. Previously intrinsics types where overriding the pointer cases which have higher precedence in the specification. Also passes the following [tests](https://github.com/llvm/llvm-test-suite/pull/287).
Diffstat (limited to 'flang-rt')
-rw-r--r--flang-rt/lib/runtime/derived-api.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/flang-rt/lib/runtime/derived-api.cpp b/flang-rt/lib/runtime/derived-api.cpp
index bb08e0397fe9..fe6868292f01 100644
--- a/flang-rt/lib/runtime/derived-api.cpp
+++ b/flang-rt/lib/runtime/derived-api.cpp
@@ -118,14 +118,26 @@ bool RTDEF(SameTypeAs)(const Descriptor &a, const Descriptor &b) {
}
bool RTDEF(ExtendsTypeOf)(const Descriptor &a, const Descriptor &mold) {
+ // The wording of the standard indicates null or unallocated checks take
+ // precedence over the extension checks which take precedence over any
+ // compiler specific behavior.
+ // F'23 16.9.86 p 5
+ // If MOLD is unlimited polymorphic and is either a disassociated pointer or
+ // unallocated allocatable variable, the result is true;
auto aType{a.raw().type};
auto moldType{mold.raw().type};
if ((aType != CFI_type_struct && aType != CFI_type_other) ||
(moldType != CFI_type_struct && moldType != CFI_type_other)) {
- // If either type is intrinsic, they must match.
- return aType == moldType;
- } else if (const typeInfo::DerivedType *
- derivedTypeMold{GetDerivedType(mold)}) {
+ if (!mold.IsAllocated()) {
+ return true;
+ } else if (!a.IsAllocated()) {
+ return false;
+ } else {
+ // If either type is intrinsic and not a pointer or allocatable
+ // then they must match.
+ return aType == moldType;
+ }
+ } else if (const auto *derivedTypeMold{GetDerivedType(mold)}) {
// If A is unlimited polymorphic and is either a disassociated pointer or
// unallocated allocatable, the result is false.
// Otherwise if the dynamic type of A or MOLD is extensible, the result is