[flang-commits] [PATCH] D139160: [flang] Don't propagate PRIVATE into submodule module files

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Dec 1 17:21:58 PST 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

Module files for submodules should not contain PRIVATE attributes,
since everything in them is local to the parent module and
accessible to all descendant submodules.


https://reviews.llvm.org/D139160

Files:
  flang/lib/Semantics/mod-file.cpp
  flang/lib/Semantics/mod-file.h


Index: flang/lib/Semantics/mod-file.h
===================================================================
--- flang/lib/Semantics/mod-file.h
+++ flang/lib/Semantics/mod-file.h
@@ -51,6 +51,7 @@
       useExtraAttrsBuf_}; // attrs added to used entity
   llvm::raw_string_ostream decls_{declsBuf_};
   llvm::raw_string_ostream contains_{containsBuf_};
+  bool isSubmodule_{false};
 
   void WriteAll(const Scope &);
   void WriteOne(const Scope &);
@@ -72,6 +73,9 @@
   void PutGeneric(const Symbol &);
   void PutUse(const Symbol &);
   void PutUseExtraAttr(Attr, const Symbol &, const Symbol &);
+  llvm::raw_ostream &PutAttrs(llvm::raw_ostream &, Attrs,
+      const std::string * = nullptr, std::string before = ","s,
+      std::string after = ""s) const;
 };
 
 class ModFileReader {
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ flang/lib/Semantics/mod-file.cpp
@@ -53,9 +53,6 @@
 static void PutShapeSpec(llvm::raw_ostream &, const ShapeSpec &);
 static void PutShape(
     llvm::raw_ostream &, const ArraySpec &, char open, char close);
-llvm::raw_ostream &PutAttrs(llvm::raw_ostream &, Attrs,
-    const std::string * = nullptr, std::string before = ","s,
-    std::string after = ""s);
 
 static llvm::raw_ostream &PutAttr(llvm::raw_ostream &, Attr);
 static llvm::raw_ostream &PutType(llvm::raw_ostream &, const DeclTypeSpec &);
@@ -132,6 +129,7 @@
 // Write the module file for symbol, which must be a module or submodule.
 void ModFileWriter::Write(const Symbol &symbol) {
   auto *ancestor{symbol.get<ModuleDetails>().ancestor()};
+  isSubmodule_ = ancestor != nullptr;
   auto ancestorName{ancestor ? ancestor->GetName().value().ToString() : ""s};
   auto path{context_.moduleDirectory() + '/' +
       ModFileName(symbol.name(), ancestorName, context_.moduleFileSuffix())};
@@ -310,6 +308,9 @@
               sep = ',';
             }
             decls_ << '\n';
+            if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
+              decls_ << "private::" << symbol.name() << '\n';
+            }
           },
           [&](const CommonBlockDetails &x) {
             decls_ << "common/" << symbol.name();
@@ -514,7 +515,7 @@
     }
   }
   decls_ << "end interface\n";
-  if (symbol.attrs().test(Attr::PRIVATE)) {
+  if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
     PutGenericName(decls_ << "private::", symbol) << '\n';
   }
 }
@@ -538,7 +539,7 @@
   uses_ << '\n';
   PutUseExtraAttr(Attr::VOLATILE, symbol, use);
   PutUseExtraAttr(Attr::ASYNCHRONOUS, symbol, use);
-  if (symbol.attrs().test(Attr::PRIVATE)) {
+  if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
     PutGenericName(useExtraAttrs_ << "private::", symbol) << '\n';
   }
 }
@@ -681,7 +682,7 @@
 void ModFileWriter::PutProcEntity(llvm::raw_ostream &os, const Symbol &symbol) {
   if (symbol.attrs().test(Attr::INTRINSIC)) {
     os << "intrinsic::" << symbol.name() << '\n';
-    if (symbol.attrs().test(Attr::PRIVATE)) {
+    if (!isSubmodule_ && symbol.attrs().test(Attr::PRIVATE)) {
       os << "private::" << symbol.name() << '\n';
     }
     return;
@@ -772,10 +773,13 @@
 
 // Put out each attribute to os, surrounded by `before` and `after` and
 // mapped to lower case.
-llvm::raw_ostream &PutAttrs(llvm::raw_ostream &os, Attrs attrs,
-    const std::string *bindName, std::string before, std::string after) {
+llvm::raw_ostream &ModFileWriter::PutAttrs(llvm::raw_ostream &os, Attrs attrs,
+    const std::string *bindName, std::string before, std::string after) const {
   attrs.set(Attr::PUBLIC, false); // no need to write PUBLIC
   attrs.set(Attr::EXTERNAL, false); // no need to write EXTERNAL
+  if (isSubmodule_) {
+    attrs.set(Attr::PRIVATE, false);
+  }
   if (bindName) {
     os << before << "bind(c, name=\"" << *bindName << "\")" << after;
     attrs.set(Attr::BIND_C, false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139160.479484.patch
Type: text/x-patch
Size: 3933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221202/72a862a0/attachment-0001.bin>


More information about the flang-commits mailing list