[flang-commits] [flang] b2c96d7 - [flang] Don't emit faulty warnings for illegal COMMON blocks

Emil Kieri via flang-commits flang-commits at lists.llvm.org
Sat Aug 27 09:19:48 PDT 2022


Author: Emil Kieri
Date: 2022-08-27T18:18:46+02:00
New Revision: b2c96d7855b8d5f4123ea0e19126bafbdc1bbcea

URL: https://github.com/llvm/llvm-project/commit/b2c96d7855b8d5f4123ea0e19126bafbdc1bbcea
DIFF: https://github.com/llvm/llvm-project/commit/b2c96d7855b8d5f4123ea0e19126bafbdc1bbcea.diff

LOG: [flang] Don't emit faulty warnings for illegal COMMON blocks

SAVE statements referencing COMMON block names are not allowed in BLOCK
constructs. If they occur, an error is correctly emitted, but then flang
gets confused by the illegal SAVE and produces a faulty warning. This
patch removes that warning.

Consider this piece of Fortran (from the test blockconstruct02.f90):

program  main
  real r, s, t
  common /argmnt2/ r, s, t
  block
    save /argmnt2/
  end block
end program

Here flang (in addition to the error about the illegal SAVE) emits a
portability warning saying that the two definitions of argmnt2 have
different size, which does not make much sense.

This patch is a prerequisite for D125804, which in turn will make
blockconstruct02.f90 test this patch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D132403

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp
index c789fcecbbba..23232d6ef38b 100644
--- a/flang/lib/Semantics/compute-offsets.cpp
+++ b/flang/lib/Semantics/compute-offsets.cpp
@@ -118,9 +118,12 @@ void ComputeOffsetsHelper::Compute(Scope &scope) {
   }
   scope.set_size(offset_);
   scope.SetAlignment(alignment_);
-  // Assign offsets in COMMON blocks.
-  for (auto &pair : scope.commonBlocks()) {
-    DoCommonBlock(*pair.second);
+  // Assign offsets in COMMON blocks, unless this scope is a BLOCK construct,
+  // where COMMON blocks are illegal (C1107 and C1108).
+  if (scope.kind() != Scope::Kind::BlockConstruct) {
+    for (auto &pair : scope.commonBlocks()) {
+      DoCommonBlock(*pair.second);
+    }
   }
   for (auto &[symbol, dep] : dependents_) {
     symbol->set_offset(dep.symbol->offset() + dep.offset);


        


More information about the flang-commits mailing list