[all-commits] [llvm/llvm-project] 2c8cb9: [flang] Handle common block with different sizes i...

jeanPerier via All-commits all-commits at lists.llvm.org
Fri Apr 29 05:53:26 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2c8cb9acb51e2fa74bf9339ddd0884ef9d921dfc
      https://github.com/llvm/llvm-project/commit/2c8cb9acb51e2fa74bf9339ddd0884ef9d921dfc
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2022-04-29 (Fri, 29 Apr 2022)

  Changed paths:
    M flang/docs/Extensions.md
    M flang/include/flang/Lower/ConvertVariable.h
    M flang/include/flang/Lower/PFTBuilder.h
    M flang/include/flang/Semantics/semantics.h
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Lower/ConvertVariable.cpp
    M flang/lib/Lower/PFTBuilder.cpp
    M flang/lib/Semantics/compute-offsets.cpp
    M flang/lib/Semantics/semantics.cpp
    A flang/test/Lower/common-block-2.f90
    M flang/test/Lower/common-block.f90
    M flang/test/Lower/module_definition.f90
    M flang/test/Lower/module_use.f90
    M flang/test/Lower/pointer-initial-target-2.f90
    A flang/test/Semantics/common-blocks-warn.f90
    A flang/test/Semantics/common-blocks.f90
    M flang/test/Semantics/resolve42.f90

  Log Message:
  -----------
  [flang] Handle common block with different sizes in same file

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.

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




More information about the All-commits mailing list