Skip to content

Commit ad33759

Browse files
klauslertomtor
authored andcommitted
[flang] Ensure overrides of special procedures (llvm#142465)
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 llvm#142414.
1 parent 3787103 commit ad33759

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
@@ -1067,7 +1067,7 @@ RuntimeTableBuilder::DescribeSpecialGenerics(const Scope &dtScope,
10671067
specials =
10681068
DescribeSpecialGenerics(*parentScope, thisScope, derivedTypeSpec);
10691069
}
1070-
for (auto pair : dtScope) {
1070+
for (const auto &pair : dtScope) {
10711071
const Symbol &symbol{*pair.second};
10721072
if (const auto *generic{symbol.detailsIf<GenericDetails>()}) {
10731073
DescribeSpecialGeneric(*generic, specials, thisScope, derivedTypeSpec);
@@ -1245,7 +1245,7 @@ void RuntimeTableBuilder::DescribeSpecialProc(
12451245
AddValue(values, specialSchema_, procCompName,
12461246
SomeExpr{evaluate::ProcedureDesignator{specific}});
12471247
// index might already be present in the case of an override
1248-
specials.emplace(*index,
1248+
specials.insert_or_assign(*index,
12491249
evaluate::StructureConstructor{
12501250
DEREF(specialSchema_.AsDerived()), std::move(values)});
12511251
}

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)