Skip to content

Commit 3cdee35

Browse files
committed
[flang] Ensure overrides of special procedures
When a derived type declares a generic procedure binding of interest to the runtime library, such as for ASSIGNMENT(=), it overrides any binding that might have been present for the parent type. Fixes #142414.
1 parent 4b23d4c commit 3cdee35

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

flang/lib/Semantics/runtime-type-info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ RuntimeTableBuilder::DescribeSpecialGenerics(const Scope &dtScope,
10631063
specials =
10641064
DescribeSpecialGenerics(*parentScope, thisScope, derivedTypeSpec);
10651065
}
1066-
for (auto pair : dtScope) {
1066+
for (const auto &pair : dtScope) {
10671067
const Symbol &symbol{*pair.second};
10681068
if (const auto *generic{symbol.detailsIf<GenericDetails>()}) {
10691069
DescribeSpecialGeneric(*generic, specials, thisScope, derivedTypeSpec);
@@ -1241,7 +1241,7 @@ void RuntimeTableBuilder::DescribeSpecialProc(
12411241
AddValue(values, specialSchema_, procCompName,
12421242
SomeExpr{evaluate::ProcedureDesignator{specific}});
12431243
// index might already be present in the case of an override
1244-
specials.emplace(*index,
1244+
specials.insert_or_assign(*index,
12451245
evaluate::StructureConstructor{
12461246
DEREF(specialSchema_.AsDerived()), std::move(values)});
12471247
}

flang/test/Semantics/typeinfo13.f90

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
2+
!Ensure ASSIGNMENT(=) overrides are applied to the special procedures table.
3+
module m
4+
type base
5+
contains
6+
procedure :: baseAssign
7+
generic :: assignment(=) => baseAssign
8+
end type
9+
type, extends(base) :: child
10+
contains
11+
procedure :: override
12+
generic :: assignment(=) => override
13+
end type
14+
contains
15+
impure elemental subroutine baseAssign(to, from)
16+
class(base), intent(out) :: to
17+
type(base), intent(in) :: from
18+
end
19+
impure elemental subroutine override(to, from)
20+
class(child), intent(out) :: to
21+
type(child), intent(in) :: from
22+
end
23+
end
24+
25+
!CHECK: .s.child, SAVE, TARGET (CompilerCreated, ReadOnly): ObjectEntity type: TYPE(specialbinding) shape: 0_8:0_8 init:[specialbinding::specialbinding(which=2_1,isargdescriptorset=1_1,istypebound=1_1,isargcontiguousset=0_1,proc=override)]
26+
!CHECK: .v.child, SAVE, TARGET (CompilerCreated, ReadOnly): ObjectEntity type: TYPE(binding) shape: 0_8:1_8 init:[binding::binding(proc=baseassign,name=.n.baseassign),binding(proc=override,name=.n.override)]

0 commit comments

Comments
 (0)