Skip to content

Commit 4fccaae

Browse files
authored
[flang][runtime] fix intrinsics case of extends_type_of (#161466)
Fixes #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](llvm/llvm-test-suite#287).
1 parent 52b1850 commit 4fccaae

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

flang-rt/lib/runtime/derived-api.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,26 @@ bool RTDEF(SameTypeAs)(const Descriptor &a, const Descriptor &b) {
118118
}
119119

120120
bool RTDEF(ExtendsTypeOf)(const Descriptor &a, const Descriptor &mold) {
121+
// The wording of the standard indicates null or unallocated checks take
122+
// precedence over the extension checks which take precedence over any
123+
// compiler specific behavior.
124+
// F'23 16.9.86 p 5
125+
// If MOLD is unlimited polymorphic and is either a disassociated pointer or
126+
// unallocated allocatable variable, the result is true;
121127
auto aType{a.raw().type};
122128
auto moldType{mold.raw().type};
123129
if ((aType != CFI_type_struct && aType != CFI_type_other) ||
124130
(moldType != CFI_type_struct && moldType != CFI_type_other)) {
125-
// If either type is intrinsic, they must match.
126-
return aType == moldType;
127-
} else if (const typeInfo::DerivedType *
128-
derivedTypeMold{GetDerivedType(mold)}) {
131+
if (!mold.IsAllocated()) {
132+
return true;
133+
} else if (!a.IsAllocated()) {
134+
return false;
135+
} else {
136+
// If either type is intrinsic and not a pointer or allocatable
137+
// then they must match.
138+
return aType == moldType;
139+
}
140+
} else if (const auto *derivedTypeMold{GetDerivedType(mold)}) {
129141
// If A is unlimited polymorphic and is either a disassociated pointer or
130142
// unallocated allocatable, the result is false.
131143
// Otherwise if the dynamic type of A or MOLD is extensible, the result is

0 commit comments

Comments
 (0)