[flang-commits] [flang] [flang] Fix Cray pointers in module file output (PR #130315)
via flang-commits
flang-commits at lists.llvm.org
Fri Mar 7 09:54:55 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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 https://github.com/llvm/llvm-project/issues/130270.
---
Full diff: https://github.com/llvm/llvm-project/pull/130315.diff
2 Files Affected:
- (modified) flang/lib/Semantics/mod-file.cpp (+14-5)
- (added) flang/test/Semantics/modfile73.f90 (+19)
``````````diff
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 1dfd9c35b3f43..aaa542358fb7d 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -978,11 +978,9 @@ void ModFileWriter::PutObjectEntity(
<< ") " << symbol.name() << '\n';
}
if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointer)) {
- if (!symbol.owner().crayPointers().empty()) {
- for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
- if (pointer == symbol) {
- os << "pointer(" << symbol.name() << "," << pointee << ")\n";
- }
+ for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
+ if (pointer == symbol) {
+ os << "pointer(" << symbol.name() << "," << pointee << ")\n";
}
}
}
@@ -1725,6 +1723,17 @@ void SubprogramSymbolCollector::DoSymbol(
if (!scope.IsDerivedType()) {
need_.push_back(symbol);
}
+ if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointer)) {
+ for (const auto &[pointee, pointer] : symbol.owner().crayPointers()) {
+ if (&*pointer == &symbol) {
+ auto iter{symbol.owner().find(pointee)};
+ CHECK(iter != symbol.owner().end());
+ DoSymbol(*iter->second);
+ }
+ }
+ } else if (symbol.test(Fortran::semantics::Symbol::Flag::CrayPointee)) {
+ DoSymbol(GetCrayPointer(symbol));
+ }
}
void SubprogramSymbolCollector::DoType(const DeclTypeSpec *type) {
diff --git a/flang/test/Semantics/modfile73.f90 b/flang/test/Semantics/modfile73.f90
new file mode 100644
index 0000000000000..f24ce8024c100
--- /dev/null
+++ b/flang/test/Semantics/modfile73.f90
@@ -0,0 +1,19 @@
+! RUN: %python %S/test_modfile.py %s %flang_fc1
+module m
+ contains
+ function f() result(ptr)
+ character :: str
+ pointer(ptr, str)
+ ptr = 0
+ end
+end
+
+!Expect: m.mod
+!module m
+!contains
+!function f() result(ptr)
+!integer(8)::ptr
+!pointer(ptr,str)
+!character(1_8,1)::str
+!end
+!end
``````````
</details>
https://github.com/llvm/llvm-project/pull/130315
More information about the flang-commits
mailing list