llvm/flang/docs
Jean Perier 2c8cb9acb5 [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
2022-04-29 14:52:47 +02:00
..
_static
_templates
_themes/llvm-theme
ArrayComposition.md
BijectiveInternalNameUniquing.md
C++17.md
C++style.md
Calls.md
Character.md
CMakeLists.txt
compiler_driver.png
conf.py
ControlFlowGraph.md
Directives.md
DoConcurrent.md
doxygen-mainpage.dox
doxygen.cfg.in
Extensions.md [flang] Handle common block with different sizes in same file 2022-04-29 14:52:47 +02:00
f2018-grammar.md
FIRArrayOperations.md
flang-c-style.el
FlangDriver.md [flang] Make the plugin API independent of the driver internals 2022-04-22 09:18:04 +00:00
FortranFeatureHistory.md
FortranForCProgrammers.md
FortranIR.md
FortranLLVMTestSuite.md
frontend_driver.png
GettingInvolved.md Replace links to archived mailing lists by links to Discourse forums 2022-03-23 10:10:20 -04:00
ImplementingASemanticCheck.md
index.md
Intrinsics.md
IORuntimeInternals.md
LabelResolution.md
ModFiles.md
OpenMP-4.5-grammar.md
OpenMP-semantics.md
OptionComparison.md
Overview.md
ParserCombinators.md
Parsing.md [flang] Add nonfatal message classes 2022-03-08 11:40:45 -08:00
Preprocessing.md
PullRequestChecklist.md
ReleaseNotes.md
RuntimeDescriptor.md
RuntimeTypeInfo.md
Semantics.md