llvm-project/flang/test/Semantics/resolve88.f90

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
3.1 KiB
Fortran
Raw Normal View History

! RUN: %S/test_errors.sh %s %t %f18
[flang] New implementation for checks for constraints C741 through C750 Summary: Most of these checks were already implemented, and I just added references to them to the code and tests. Also, much of this code was already reviewed in the old flang/f18 GitHub repository, but I didn't get to merge it before we switched repositories. I implemented the check for C747 to not allow coarray components in derived types that are of type C_PTR, C_FUNPTR, or type TEAM_TYPE. I implemented the check for C748 that requires a data component whose type has a coarray ultimate component to be a nonpointer, nonallocatable scalar and not be a coarray. I implemented the check for C750 that adds additional restrictions to the bounds expressions of a derived type component that's an array. These bounds expressions are sepcification expressions as defined in 10.1.11. There was already code in lib/Evaluate/check-expression.cpp to check semantics for specification expressions, but it did not check for the extra requirements of C750. C750 prohibits specification functions, the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, and SAME_TYPE_AS. It also requires every specification inquiry reference to be a constant expression, and requires that the value of the bound not depend on the value of a variable. To implement these additional checks, I added code to the intrinsic proc table to get the intrinsic class of a procedure. I also added an enumeration to distinguish between specification expressions for derived type component bounds versus for type parameters. I then changed the code to pass an enumeration value to "CheckSpecificationExpr()" to indicate that the expression was a bounds expression and used this value to determine whether to emit an error message when violations of C750 are found. I changed the implementation of IsPureProcedure() to handle statement functions and changed some references in the code that tested for the PURE attribute to call IsPureProcedure(). I also fixed some unrelated tests that got new errors when I implemented these new checks. Reviewers: tskeith, DavidTruby, sscalpone Subscribers: jfb, llvm-commits Tags: #llvm, #flang Differential Revision: https://reviews.llvm.org/D79263
2020-05-02 04:00:28 +08:00
! C746, C747, and C748
module m
use ISO_FORTRAN_ENV
use ISO_C_BINDING
! C746 If a coarray-spec appears, it shall be a deferred-coshape-spec-list and
! the component shall have the ALLOCATABLE attribute.
type testCoArrayType
real, allocatable, codimension[:] :: allocatableField
!ERROR: Component 'deferredfield' is a coarray and must have the ALLOCATABLE attribute
real, codimension[:] :: deferredField
!ERROR: Component 'pointerfield' is a coarray and must have the ALLOCATABLE attribute
!ERROR: 'pointerfield' may not have the POINTER attribute because it is a coarray
[flang] New implementation for checks for constraints C741 through C750 Summary: Most of these checks were already implemented, and I just added references to them to the code and tests. Also, much of this code was already reviewed in the old flang/f18 GitHub repository, but I didn't get to merge it before we switched repositories. I implemented the check for C747 to not allow coarray components in derived types that are of type C_PTR, C_FUNPTR, or type TEAM_TYPE. I implemented the check for C748 that requires a data component whose type has a coarray ultimate component to be a nonpointer, nonallocatable scalar and not be a coarray. I implemented the check for C750 that adds additional restrictions to the bounds expressions of a derived type component that's an array. These bounds expressions are sepcification expressions as defined in 10.1.11. There was already code in lib/Evaluate/check-expression.cpp to check semantics for specification expressions, but it did not check for the extra requirements of C750. C750 prohibits specification functions, the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, and SAME_TYPE_AS. It also requires every specification inquiry reference to be a constant expression, and requires that the value of the bound not depend on the value of a variable. To implement these additional checks, I added code to the intrinsic proc table to get the intrinsic class of a procedure. I also added an enumeration to distinguish between specification expressions for derived type component bounds versus for type parameters. I then changed the code to pass an enumeration value to "CheckSpecificationExpr()" to indicate that the expression was a bounds expression and used this value to determine whether to emit an error message when violations of C750 are found. I changed the implementation of IsPureProcedure() to handle statement functions and changed some references in the code that tested for the PURE attribute to call IsPureProcedure(). I also fixed some unrelated tests that got new errors when I implemented these new checks. Reviewers: tskeith, DavidTruby, sscalpone Subscribers: jfb, llvm-commits Tags: #llvm, #flang Differential Revision: https://reviews.llvm.org/D79263
2020-05-02 04:00:28 +08:00
real, pointer, codimension[:] :: pointerField
!ERROR: Component 'realfield' is a coarray and must have the ALLOCATABLE attribute and have a deferred coshape
real, codimension[*] :: realField
!ERROR: 'realfield2' is an ALLOCATABLE coarray and must have a deferred coshape
real, allocatable, codimension[*] :: realField2
end type testCoArrayType
! C747 If a coarray-spec appears, the component shall not be of type C_PTR or
! C_FUNPTR from the intrinsic module ISO_C_BINDING (18.2), or of type
! TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2).
type goodCoarrayType
real, allocatable, codimension[:] :: field
end type goodCoarrayType
type goodTeam_typeCoarrayType
type(team_type), allocatable :: field
end type goodTeam_typeCoarrayType
type goodC_ptrCoarrayType
type(c_ptr), allocatable :: field
end type goodC_ptrCoarrayType
type goodC_funptrCoarrayType
type(c_funptr), allocatable :: field
end type goodC_funptrCoarrayType
type team_typeCoarrayType
!ERROR: A coarray component may not be of type TEAM_TYPE from ISO_FORTRAN_ENV
type(team_type), allocatable, codimension[:] :: field
end type team_typeCoarrayType
type c_ptrCoarrayType
!ERROR: A coarray component may not be of type C_PTR or C_FUNPTR from ISO_C_BINDING
type(c_ptr), allocatable, codimension[:] :: field
end type c_ptrCoarrayType
type c_funptrCoarrayType
!ERROR: A coarray component may not be of type C_PTR or C_FUNPTR from ISO_C_BINDING
type(c_funptr), allocatable, codimension[:] :: field
end type c_funptrCoarrayType
! C748 A data component whose type has a coarray ultimate component shall be a
! nonpointer nonallocatable scalar and shall not be a coarray.
type coarrayType
real, allocatable, codimension[:] :: goodCoarrayField
end type coarrayType
type testType
type(coarrayType) :: goodField
!ERROR: A component with a POINTER or ALLOCATABLE attribute may not be of a type with a coarray ultimate component (named 'goodcoarrayfield')
type(coarrayType), pointer :: pointerField
!ERROR: A component with a POINTER or ALLOCATABLE attribute may not be of a type with a coarray ultimate component (named 'goodcoarrayfield')
type(coarrayType), allocatable :: allocatableField
!ERROR: An array or coarray component may not be of a type with a coarray ultimate component (named 'goodcoarrayfield')
type(coarrayType), dimension(3) :: arrayField
end type testType
end module m