Skip to content

Commit a4015d9

Browse files
authored
[flang] Fix crash resolving interface procedure type. (#162205)
When generic interface name shadows specific, bypass to specific procedure while resolving its type.
1 parent eb06c7e commit a4015d9

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,9 @@ inline const DeclTypeSpec *Symbol::GetTypeImpl(int depth) const {
11261126
[&](const HostAssocDetails &x) {
11271127
return x.symbol().GetTypeImpl(depth);
11281128
},
1129+
[&](const GenericDetails &x) {
1130+
return x.specific() ? x.specific()->GetTypeImpl(depth) : nullptr;
1131+
},
11291132
[](const auto &) -> const DeclTypeSpec * { return nullptr; },
11301133
},
11311134
details_);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
#if STEP == 1
3+
! these modules must be read from module files
4+
module generic_shadows_specific_m1
5+
interface f ! reference must be to generic
6+
module procedure f ! must have same name as generic interface
7+
end interface
8+
contains
9+
character function f() ! must be character
10+
f = 'q'
11+
end
12+
end
13+
module generic_shadows_specific_m2
14+
use generic_shadows_specific_m1
15+
end
16+
module generic_shadows_specific_m3
17+
use generic_shadows_specific_m2 ! must be generic_shadows_specific_m2, not generic_shadows_specific_m1
18+
contains
19+
subroutine mustExist() ! not called, but must exist
20+
character x
21+
x = f()
22+
end
23+
end
24+
25+
#else
26+
! Check that expected code produced with no crash.
27+
subroutine reproducer()
28+
use generic_shadows_specific_m2
29+
use generic_shadows_specific_m3
30+
character x
31+
x = f()
32+
end
33+
#endif
34+
35+
!RUN: rm -rf %t && mkdir -p %t
36+
!RUN: %flang_fc1 -fsyntax-only -DSTEP=1 -J%t %s
37+
!RUN: %flang_fc1 -emit-fir -J%t -o - %s | FileCheck %s
38+
39+
!CHECK-LABEL: func.func @_QPreproducer
40+
!CHECK: fir.call @_QMgeneric_shadows_specific_m1Pf

0 commit comments

Comments
 (0)