peter klausler d60a02201d [flang] Include default component initialization in static initializers
The combined initializers constructed from DATA statements and explicit
static initialization in declarations needs to include derived type
component default initializations, overriding those default values
without complaint with values from explicit DATA statement or declaration
initializations when they overlap.  This also has to work for objects
with storage association due to EQUIVALENCE.  When storage association causes
default component initializations to overlap, emit errors if and only
if the values differ (See Fortran 2018 subclause 19.5.3, esp. paragraph
10).

The f18 front-end has a module that analyzes and converts DATA statements
into equivalent static initializers for objects.  For storage-associated
objects, compiler-generated objects are created that overlay the entire
association and fill it with a combined initializer.  This "data-to-inits"
module already exists, and this patch is essentially extension and
clean-up of its machinery to complete the job.

Also: emit EQUIVALENCE to module files; mark compiler-created symbols
and *don't* emit those to module files; check non-static EQUIVALENCE
sets for conflicting default component initializations, so lowering
doesn't have to check them or emit diagnostics.

Differential Revision: https://reviews.llvm.org/D109022
2021-09-01 09:40:37 -07:00

36 lines
1004 B
Fortran

! RUN: %S/test_errors.sh %s %t %flang_fc1
! REQUIRES: shell
type :: t1
sequence
integer :: m = 123
integer :: pad
end type
type :: t2
sequence
integer :: n = 123
integer :: pad
end type
type :: t3
sequence
integer :: k = 234
integer :: pad
end type
!ERROR: Distinct default component initializations of equivalenced objects affect 'x1a%m' more than once
type(t1) :: x1a
!ERROR: Distinct default component initializations of equivalenced objects affect 'x2a%n' more than once
type(t2) :: x2a
!ERROR: Distinct default component initializations of equivalenced objects affect 'x3%k' more than once
type(t3), save :: x3
!ERROR: Explicit initializations of equivalenced objects affect 'ja(2_8)' more than once
!ERROR: Explicit initializations of equivalenced objects affect 'ka(1_8)' more than once
integer :: ja(2), ka(2)
data ja/345, 456/
data ka/456, 567/
equivalence(x1a, x2a, x3)
! Same value: no error
type(t1) :: x1b
type(t2) :: x2b
equivalence(x1b, x2b)
equivalence(ja(2),ka(1))
end