[flang-commits] [PATCH] D123706: [flang] Emit a portability warning for padding in COMMON

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Apr 13 15:58:37 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc709f503d796: [flang] Emit a portability warning for padding in COMMON (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123706/new/

https://reviews.llvm.org/D123706

Files:
  flang/lib/Semantics/compute-offsets.cpp


Index: flang/lib/Semantics/compute-offsets.cpp
===================================================================
--- flang/lib/Semantics/compute-offsets.cpp
+++ flang/lib/Semantics/compute-offsets.cpp
@@ -50,7 +50,8 @@
   void DoEquivalenceSet(const EquivalenceSet &);
   SymbolAndOffset Resolve(const SymbolAndOffset &);
   std::size_t ComputeOffset(const EquivalenceObject &);
-  void DoSymbol(Symbol &);
+  // Returns amount of padding that was needed for alignment
+  std::size_t DoSymbol(Symbol &);
   SizeAndAlignment GetSizeAndAlignment(const Symbol &, bool entire);
   std::size_t Align(std::size_t, std::size_t);
 
@@ -150,7 +151,13 @@
   std::size_t minAlignment{0};
   for (auto &object : details.objects()) {
     Symbol &symbol{*object};
-    DoSymbol(symbol);
+    auto errorSite{
+        commonBlock.name().empty() ? symbol.name() : commonBlock.name()};
+    if (std::size_t padding{DoSymbol(symbol)}) {
+      context_.Say(errorSite,
+          "COMMON block /%s/ requires %zd bytes of padding before '%s' for alignment"_port_en_US,
+          commonBlock.name(), padding, symbol.name());
+    }
     auto eqIter{equivalenceBlock_.end()};
     auto iter{dependents_.find(symbol)};
     if (iter == dependents_.end()) {
@@ -161,8 +168,6 @@
     } else {
       SymbolAndOffset &dep{iter->second};
       Symbol &base{*dep.symbol};
-      auto errorSite{
-          commonBlock.name().empty() ? symbol.name() : commonBlock.name()};
       if (const auto *baseBlock{FindCommonBlockContaining(base)}) {
         if (baseBlock == &commonBlock) {
           context_.Say(errorSite,
@@ -287,19 +292,22 @@
   return result;
 }
 
-void ComputeOffsetsHelper::DoSymbol(Symbol &symbol) {
+std::size_t ComputeOffsetsHelper::DoSymbol(Symbol &symbol) {
   if (!symbol.has<ObjectEntityDetails>() && !symbol.has<ProcEntityDetails>()) {
-    return;
+    return 0;
   }
   SizeAndAlignment s{GetSizeAndAlignment(symbol, true)};
   if (s.size == 0) {
-    return;
+    return 0;
   }
+  std::size_t previousOffset{offset_};
   offset_ = Align(offset_, s.alignment);
+  std::size_t padding{offset_ - previousOffset};
   symbol.set_size(s.size);
   symbol.set_offset(offset_);
   offset_ += s.size;
   alignment_ = std::max(alignment_, s.alignment);
+  return padding;
 }
 
 auto ComputeOffsetsHelper::GetSizeAndAlignment(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123706.422682.patch
Type: text/x-patch
Size: 2321 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220413/d951afff/attachment.bin>


More information about the flang-commits mailing list