Skip to content

[flang] Fix Cray pointers in module file output #130315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Mar 7, 2025

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.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 7, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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.


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 --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

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 llvm#130270.
Copy link
Member

@inaki-amatria inaki-amatria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYSM!

@klausler klausler merged commit 8227f2a into llvm:main Mar 10, 2025
11 checks passed
@klausler klausler deleted the bug130270 branch March 10, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Flang is unable to use a module it compiled
4 participants