Skip to content

Commit 8227f2a

Browse files
authored
[flang] Fix Cray pointers in module file output (#130315)
The relationship between a Cray pointee and its pointer is not in the symbol table entry, but instead in a per-scope map. Use this information to ensure that if a pointee/pointer is needed in the module file, so is its pointer/pointee. Fixes #130270.
1 parent 40d9096 commit 8227f2a

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

flang/lib/Semantics/mod-file.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,9 @@ void ModFileWriter::PutObjectEntity(
978978
<< ") " << symbol.name() << '\n';
979979
}
980980
if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointer)) {
981-
if (!symbol.owner().crayPointers().empty()) {
982-
for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
983-
if (pointer == symbol) {
984-
os << "pointer(" << symbol.name() << "," << pointee << ")\n";
985-
}
981+
for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
982+
if (pointer == symbol) {
983+
os << "pointer(" << symbol.name() << "," << pointee << ")\n";
986984
}
987985
}
988986
}
@@ -1725,6 +1723,17 @@ void SubprogramSymbolCollector::DoSymbol(
17251723
if (!scope.IsDerivedType()) {
17261724
need_.push_back(symbol);
17271725
}
1726+
if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointer)) {
1727+
for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
1728+
if (&*pointer == &symbol) {
1729+
auto iter{symbol.owner().find(pointee)};
1730+
CHECK(iter != symbol.owner().end());
1731+
DoSymbol(*iter->second);
1732+
}
1733+
}
1734+
} else if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointee)) {
1735+
DoSymbol(GetCrayPointer(symbol));
1736+
}
17281737
}
17291738

17301739
void SubprogramSymbolCollector::DoType(const DeclTypeSpec *type) {

flang/test/Semantics/modfile74.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: %python %S/test_modfile.py %s %flang_fc1
2+
module m
3+
contains
4+
function f() result(ptr)
5+
character :: str
6+
pointer(ptr, str)
7+
ptr = 0
8+
end
9+
end
10+
11+
!Expect: m.mod
12+
!module m
13+
!contains
14+
!function f() result(ptr)
15+
!integer(8)::ptr
16+
!pointer(ptr,str)
17+
!character(1_8,1)::str
18+
!end
19+
!end

0 commit comments

Comments
 (0)