llvm-project/flang/test/Semantics/symbol21.f90
Peter Klausler b7f8314270 [flang] Avoid crash from forward referenced derived type
Fortran permits forward references to derived types in contexts that don't
require knowledge of the derived type definition for semantic analysis,
such as in the declaration of a pointer or allocatable variable or component.
But when the forward-referenced derived type is used later for a component
reference, it is possible for the DerivedTypeSpec in he base variable or component
declaration to still have a null scope pointer even if the type has been defined,
since DerivedTypeSpec and TypeSpec objects are created in scopes of use
rather than in scopes of definition.  The fix is to call
DerivedTypeSpec::Instantiate() in the name resolution of each component
name so that the scope gets filled in if it is still null.

Differential Revision: https://reviews.llvm.org/D129681
2022-07-13 16:58:26 -07:00

31 lines
893 B
Fortran

! RUN: %python %S/test_symbols.py %s %flang_fc1
! Derived type forward reference regression case
!DEF: /MainProgram1/t2 DerivedType
type :: t2
!DEF: /MainProgram1/t1 DerivedType
!DEF: /MainProgram1/t2/ptr POINTER ObjectEntity TYPE(t1)
type(t1), pointer :: ptr
end type
!REF: /MainProgram1/t1
type :: t1
!DEF: /MainProgram1/t1/a ObjectEntity REAL(4)
real :: a
!REF: /MainProgram1/t2
!DEF: /MainProgram1/t1/p2 POINTER ObjectEntity TYPE(t2)
type(t2), pointer :: p2
!REF: /MainProgram1/t1
!DEF: /MainProgram1/t1/p1 POINTER ObjectEntity TYPE(t1)
type(t1), pointer :: p1
end type
!REF: /MainProgram1/t1
!DEF: /MainProgram1/x1 POINTER ObjectEntity TYPE(t1)
!DEF: /MainProgram1/x2 POINTER ObjectEntity TYPE(t1)
type(t1), pointer :: x1, x2
!REF: /MainProgram1/x2
!REF: /MainProgram1/t1/p1
!REF: /MainProgram1/t1/a
!REF: /MainProgram1/x1
x2%p1%a = x1%a
end program