543b15bca4
A symbol for a common block has `CommonBlockDetails` which contains a list of the symbols that are in the common block. The name of the symbol for the blank common block is the empty string. That preserves the property that every symbol name is a substring of the cooked source. We use the 0-length substring starting at the COMMON statement so that when symbols are sorted by the location of the start of the name it ends up in the right place. Some of the checks on members of common blocks don't happen until the end of the scope. They can't happen earlier because we don't necessarily know the type and attributes. Enhance `test_errors.sh` so that multiple errors can be expected for a single line. Original-commit: flang-compiler/f18@2c4ca6b5d3 Reviewed-on: https://github.com/flang-compiler/f18/pull/286
119 lines
2.7 KiB
Fortran
119 lines
2.7 KiB
Fortran
! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
|
!
|
|
! Licensed under the Apache License, Version 2.0 (the "License");
|
|
! you may not use this file except in compliance with the License.
|
|
! You may obtain a copy of the License at
|
|
!
|
|
! http://www.apache.org/licenses/LICENSE-2.0
|
|
!
|
|
! Unless required by applicable law or agreed to in writing, software
|
|
! distributed under the License is distributed on an "AS IS" BASIS,
|
|
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
! See the License for the specific language governing permissions and
|
|
! limitations under the License.
|
|
|
|
subroutine s1
|
|
!ERROR: The shape of common block object 'z' must be explicit
|
|
common x, y(4), z(:)
|
|
end
|
|
|
|
subroutine s2
|
|
common /c1/ x, y, z
|
|
!ERROR: 'y' is already in a COMMON block
|
|
common y
|
|
end
|
|
|
|
subroutine s3
|
|
procedure(real) :: x
|
|
!ERROR: 'x' is already declared as a procedure
|
|
common x
|
|
common y
|
|
!ERROR: 'y' is already declared as an object
|
|
procedure(real) :: y
|
|
end
|
|
|
|
subroutine s4
|
|
integer x
|
|
!ERROR: 'x' is already declared in this scoping unit
|
|
common /x/ y
|
|
!ERROR: 's4' is already declared in this scoping unit
|
|
common /s4/ z
|
|
end
|
|
|
|
subroutine s5
|
|
integer x(2)
|
|
!ERROR: The dimensions of 'x' have already been declared
|
|
common x(4), y(4)
|
|
!ERROR: The dimensions of 'y' have already been declared
|
|
real y(2)
|
|
end
|
|
|
|
subroutine s6(x)
|
|
!ERROR: Dummy argument 'x' may not appear in a COMMON block
|
|
!ERROR: ALLOCATABLE object 'y' may not appear in a COMMON block
|
|
common x,y,z
|
|
allocatable y
|
|
end
|
|
|
|
module m7
|
|
!ERROR: Variable 'z' with BIND attribute may not appear in a COMMON block
|
|
common z
|
|
integer, bind(c) :: z
|
|
end
|
|
|
|
module m8
|
|
type t
|
|
end type
|
|
class(*), pointer :: x
|
|
!ERROR: Unlimited polymorphic pointer 'x' may not appear in a COMMON block
|
|
!ERROR: Unlimited polymorphic pointer 'y' may not appear in a COMMON block
|
|
common x, y
|
|
class(*), pointer :: y
|
|
end
|
|
|
|
module m9
|
|
integer x
|
|
end
|
|
subroutine s9
|
|
use m9
|
|
!ERROR: 'x' is use-associated from module 'm9' and cannot be re-declared
|
|
common x
|
|
end
|
|
|
|
module m10
|
|
type t
|
|
end type
|
|
type(t) :: x
|
|
!ERROR: Derived type 'x' in COMMON block must have the BIND or SEQUENCE attribute
|
|
common x
|
|
end
|
|
|
|
module m11
|
|
type t1
|
|
sequence
|
|
integer, allocatable :: a
|
|
end type
|
|
type t2
|
|
sequence
|
|
type(t1) :: b
|
|
integer:: c
|
|
end type
|
|
type(t2) :: x2
|
|
!ERROR: Derived type variable 'x2' may not appear in a COMMON block due to ALLOCATABLE component
|
|
common x2
|
|
end
|
|
|
|
module m12
|
|
type t1
|
|
sequence
|
|
integer :: a = 123
|
|
end type
|
|
type t2
|
|
sequence
|
|
type(t1) :: b
|
|
integer:: c
|
|
end type
|
|
type(t2) :: x2
|
|
!ERROR: Derived type variable 'x2' may not appear in a COMMON block due to component with default initialization
|
|
common x2
|
|
end
|