Skip to content

Commit 4ed9092

Browse files
authored
[Flang][Lower] Handle mangling of a generic name with a homonym specific procedure (llvm#106693)
This may happen when using modules. Fixes llvm#93707
1 parent bdfd780 commit 4ed9092

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

flang/lib/Lower/Mangler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ std::string Fortran::lower::mangle::mangleName(
165165
return mangleName(procBinding.symbol(), scopeBlockIdMap,
166166
keepExternalInScope, underscoring);
167167
},
168+
[&](const Fortran::semantics::GenericDetails &generic)
169+
-> std::string {
170+
if (generic.specific())
171+
return mangleName(*generic.specific(), scopeBlockIdMap,
172+
keepExternalInScope, underscoring);
173+
else
174+
llvm::report_fatal_error(
175+
"attempt to mangle a generic name but "
176+
"it has no specific procedure of the same name");
177+
},
168178
[&](const Fortran::semantics::DerivedTypeDetails &) -> std::string {
169179
// Derived type mangling must use mangleName(DerivedTypeSpec) so
170180
// that kind type parameter values can be mangled.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
! RUN: split-file %s %t
2+
! RUN: bbc -emit-fir %t/mangling_mod_a.f90 -o - | FileCheck %s --check-prefix=FIR
3+
! RUN: bbc -emit-fir %t/mangling_mod_b.f90 -o - | FileCheck %s --check-prefix=MANGLE
4+
! RUN: bbc -emit-fir %t/mangling_mod_c.f90 -o - | FileCheck %s --check-prefix=MANGLE
5+
! RUN: bbc -emit-fir %t/mangling_mod_d.f90 -o - | FileCheck %s --check-prefix=MANGLE
6+
7+
! FIR: module
8+
! MANGLE: func.func private @_QPmy_sub(!fir.ref<i32>)
9+
10+
!--- mangling_mod_a.f90
11+
module mangling_mod_a
12+
interface
13+
subroutine my_sub(a)
14+
integer :: a
15+
end subroutine my_sub
16+
end interface
17+
18+
! Generic interface
19+
interface my_sub
20+
procedure :: my_sub
21+
end interface
22+
contains
23+
end module mangling_mod_a
24+
25+
!--- mangling_mod_b.f90
26+
module mangling_mod_b
27+
use mangling_mod_a
28+
29+
contains
30+
subroutine my_sub2(a)
31+
integer :: a
32+
call my_sub(a)
33+
end subroutine my_sub2
34+
35+
end module mangling_mod_b
36+
37+
!--- mangling_mod_c.f90
38+
module mangling_mod_c
39+
use mangling_mod_b
40+
41+
contains
42+
subroutine my_sub3(a)
43+
integer :: a
44+
45+
call my_sub(a)
46+
end subroutine my_sub3
47+
end module mangling_mod_c
48+
49+
!--- mangling_mod_d.f90
50+
module mangling_mod_d
51+
use mangling_mod_b
52+
use mangling_mod_c
53+
54+
contains
55+
subroutine my_sub4(a)
56+
integer :: a
57+
58+
call my_sub(a)
59+
end subroutine my_sub4
60+
end module mangling_mod_d

0 commit comments

Comments
 (0)