[flang-commits] [PATCH] D124622: [flang] Handle common block with different sizes in same file

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Apr 28 08:47:58 PDT 2022


jeanPerier created this revision.
jeanPerier added reviewers: klausler, schweitz, PeteSteinfeld, vdonaldson.
jeanPerier added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
jeanPerier requested review of this revision.

Semantics is not preventing a named common block to appear with
different size in a same file (named common block should always have
the same storage size (see Fortran 2018 8.10.2.5), but it is a common
extension to accept different sizes).

Lowering was not coping with this well, since it just use the first
common block appearance, starting with BLOCK DATAs to define common
blocks (this also was an issue with the blank common block, which can
legally appear with different size in different scoping units).

Semantics is also not preventing named common from being initialized
outside of a BLOCK DATA, and lowering was dealing badly with this,
since it only gave an initial value to common blocks Globals if the
first common block appearance, starting with BLOCK DATAs had an initial
value.

Semantics is also allowing blank common to be initialized, while
lowering was assuming this would never happen, and was never creating
an initial value for it.

Lastly, semantics was not complaining if a COMMON block was initialized
in several scoping unit in a same file, while lowering can only generate
one of these initial value.

To fix this, add a structure to keep track of COMMON block properties
(biggest size, and initial value if any) at the Program level. Once the
size of a common block appearance is know, the common block appearance
is checked against this information. It allows semantics to emit an error
in case of multiple initialization in different scopes of a same common
block, and to warn in case named common blocks appears with different
sizes. Lastly, this allows lowering to use the Program level info about
common blocks to emit the right GlobalOp for a Common Block, regardless
of the COMMON Block appearances order: It emits a GlobalOp with the
biggest size, whose lowest bytes are initialized with the initial value
if any is given in a scope where the common block appears.

Lowering is updated to go emit the common blocks before anything else so
that the related GlobalOps are available when lowering the scopes where
common block appear. It is also updated to not assume that blank common
are never initialized.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124622

Files:
  flang/include/flang/Lower/ConvertVariable.h
  flang/include/flang/Lower/PFTBuilder.h
  flang/include/flang/Semantics/semantics.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/ConvertVariable.cpp
  flang/lib/Lower/PFTBuilder.cpp
  flang/lib/Semantics/compute-offsets.cpp
  flang/lib/Semantics/semantics.cpp
  flang/test/Lower/common-block-2.f90
  flang/test/Lower/common-block.f90
  flang/test/Lower/module_definition.f90
  flang/test/Lower/module_use.f90
  flang/test/Lower/pointer-initial-target-2.f90
  flang/test/Semantics/common-blocks-warn.f90
  flang/test/Semantics/common-blocks.f90
  flang/test/Semantics/resolve42.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124622.425804.patch
Type: text/x-patch
Size: 35165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220428/e00e6640/attachment-0001.bin>


More information about the flang-commits mailing list