2020-02-26 07:22:14 +08:00
|
|
|
! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
|
2019-02-16 08:08:32 +08:00
|
|
|
! Error tests for recursive use of derived types.
|
[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
|
|
|
! C744 If neither the POINTER nor the ALLOCATABLE attribute is specified, the
|
|
|
|
! declaration-type-spec in the component-def-stmt shall specify an intrinsic
|
|
|
|
! type or a previously defined derived type.
|
2019-02-16 08:08:32 +08:00
|
|
|
|
|
|
|
program main
|
|
|
|
type :: recursive1
|
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2019-02-16 08:21:43 +08:00
|
|
|
type(recursive1) :: bad1
|
2019-02-16 08:08:32 +08:00
|
|
|
type(recursive1), pointer :: ok1
|
|
|
|
type(recursive1), allocatable :: ok2
|
2019-02-16 08:21:43 +08:00
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2020-02-12 04:14:04 +08:00
|
|
|
!ERROR: CLASS entity 'bad2' must be a dummy argument or have ALLOCATABLE or POINTER attribute
|
2019-02-16 08:21:43 +08:00
|
|
|
class(recursive1) :: bad2
|
|
|
|
class(recursive1), pointer :: ok3
|
|
|
|
class(recursive1), allocatable :: ok4
|
2019-02-16 08:08:32 +08:00
|
|
|
end type recursive1
|
|
|
|
type :: recursive2(kind,len)
|
|
|
|
integer, kind :: kind
|
|
|
|
integer, len :: len
|
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2019-02-16 08:21:43 +08:00
|
|
|
type(recursive2(kind,len)) :: bad1
|
2019-02-16 08:08:32 +08:00
|
|
|
type(recursive2(kind,len)), pointer :: ok1
|
|
|
|
type(recursive2(kind,len)), allocatable :: ok2
|
2019-02-16 08:21:43 +08:00
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2020-02-12 04:14:04 +08:00
|
|
|
!ERROR: CLASS entity 'bad2' must be a dummy argument or have ALLOCATABLE or POINTER attribute
|
2019-02-16 08:21:43 +08:00
|
|
|
class(recursive2(kind,len)) :: bad2
|
|
|
|
class(recursive2(kind,len)), pointer :: ok3
|
|
|
|
class(recursive2(kind,len)), allocatable :: ok4
|
2019-02-16 08:08:32 +08:00
|
|
|
end type recursive2
|
|
|
|
type :: recursive3(kind,len)
|
|
|
|
integer, kind :: kind = 1
|
|
|
|
integer, len :: len = 2
|
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2019-02-16 08:21:43 +08:00
|
|
|
type(recursive3) :: bad1
|
2019-02-16 08:08:32 +08:00
|
|
|
type(recursive3), pointer :: ok1
|
|
|
|
type(recursive3), allocatable :: ok2
|
2019-02-16 08:21:43 +08:00
|
|
|
!ERROR: Recursive use of the derived type requires POINTER or ALLOCATABLE
|
2020-02-12 04:14:04 +08:00
|
|
|
!ERROR: CLASS entity 'bad2' must be a dummy argument or have ALLOCATABLE or POINTER attribute
|
2019-02-16 08:21:43 +08:00
|
|
|
class(recursive3) :: bad2
|
|
|
|
class(recursive3), pointer :: ok3
|
|
|
|
class(recursive3), allocatable :: ok4
|
2019-02-16 08:08:32 +08:00
|
|
|
end type recursive3
|
2019-02-20 02:08:10 +08:00
|
|
|
!ERROR: Derived type 'recursive4' cannot extend itself
|
2019-02-16 08:21:43 +08:00
|
|
|
type, extends(recursive4) :: recursive4
|
|
|
|
end type recursive4
|
2019-02-16 08:08:32 +08:00
|
|
|
end program main
|