mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 06:46:36 +00:00

Refine handling of NULL(...) in semantics to properly distinguish NULL(), NULL(objectPointer), NULL(procPointer), and NULL(allocatable) from each other in relevant contexts. Add IsNullAllocatable() and IsNullPointerOrAllocatable() utility functions. IsNullAllocatable() is true only for NULL(allocatable); it is false for a bare NULL(), which can be detected independently with IsBareNullPointer(). IsNullPointer() now returns false for NULL(allocatable). ALLOCATED(NULL(allocatable)) now works, and folds to .FALSE. These utilities were modified to accept const pointer arguments rather than const references; I usually prefer this style when the result should clearly be false for a null argument (in the C sense), and it helped me find all of their use sites in the code.
33 lines
1.3 KiB
Fortran
33 lines
1.3 KiB
Fortran
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
|
|
! Catch NULL() actual argument association with allocatable dummy argument
|
|
program test
|
|
real, allocatable :: a
|
|
!ERROR: NULL() actual argument 'NULL()' may not be associated with allocatable dummy argument dummy argument 'a=' that is INTENT(OUT) or INTENT(IN OUT)
|
|
call foo0(null())
|
|
!WARNING: NULL() actual argument 'NULL()' should not be associated with allocatable dummy argument dummy argument 'a=' without INTENT(IN)
|
|
call foo1(null())
|
|
!PORTABILITY: Allocatable dummy argument 'a=' is associated with NULL()
|
|
call foo2(null())
|
|
call foo3(null()) ! ok
|
|
!ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'a=' is not definable
|
|
!BECAUSE: 'null(mold=a)' is a null pointer
|
|
call foo0(null(mold=a))
|
|
!WARNING: A null allocatable should not be associated with allocatable dummy argument 'a=' without INTENT(IN)
|
|
call foo1(null(mold=a))
|
|
call foo2(null(mold=a)) ! ok
|
|
call foo3(null(mold=a)) ! ok
|
|
contains
|
|
subroutine foo0(a)
|
|
real, allocatable, intent(in out) :: a
|
|
end subroutine
|
|
subroutine foo1(a)
|
|
real, allocatable :: a
|
|
end subroutine
|
|
subroutine foo2(a)
|
|
real, allocatable, intent(in) :: a
|
|
end subroutine
|
|
subroutine foo3(a)
|
|
real, allocatable, optional :: a
|
|
end subroutine
|
|
end
|