| Issue |
170783
|
| Summary |
[Flang] Spurious warning on a reference of the intrinsic function NULL as an actual argument when the dummy argument has ALLOCATABLE attribute and INTENT(IN) is not present
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
boo-aboutme
|
```
Version of flang : 22.0.0(7761a89e1230d8ccbb8e6ee15dc14ea74792a53c)/AArch64
```
A spurious warning is issued on a reference of the intrinsic function
NULL as an actual argument when the dummy argument has ALLOCATABLE
attribute and INTENT(IN) is not present, for instance, the sample program shown below;
``` fortran
integer,allocatable::x
call sub(NULL(x))
call sub(NULL())
print*,"pass"
contains
subroutine sub(dmy)
integer,allocatable:: dmy
if (allocated(dmy)) print *,101
end subroutine
end
```
``` shell
$ flang --version
flang version 22.0.0git (https://github.com/llvm/llvm-project.git c543615744d61e0967b956c402e310946d741570)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20251124-c543615744d6/bin
Build config: +assertions
$ flang sample.f90
./sample.f90:2:10: warning: A null allocatable should not be associated with allocatable dummy argument 'dmy=' without INTENT(IN)
call sub(NULL(x))
^^^^^^^
./sample.f90:3:10: warning: NULL() actual argument 'NULL()' should not be associated with allocatable dummy argument dummy argument 'dmy=' without INTENT(IN) [-Wnull-actual-for-default-intent-allocatable]
call sub(NULL())
^^^^^^
```
Fortran 2023 Standard says that an actual argument shall be allocatable
if the corresponding dummy argument is allocatable.
``` text
15.5.2.7 Allocatable dummy variables
The requirements in this subclause apply to actual arguments that correspond to allocatable dummy data objects.
The actual argument shall be allocatable. It is permissible for the actual argument to have an allocation status
of unallocated.
```
It also says the result of NULL(MOLD) shall be allocatable if MOLD is allocatable,
and the result of NULL() shall be allocatable if the reference of NULL() appears as an
actual argument of a function and the corresponding dummy argument is allocatable,
regardless of the existence of INTENT(IN).
``` text
16.9.155 NULL ([MOLD])
Description. Disassociated pointer or unallocated allocatable entity.
Result Characteristics. If MOLD is present, the characteristics are the same as MOLD. If MOLD has deferred
type parameters, those type parameters of the result are deferred.
If MOLD is absent, the characteristics of the result are determined by the entity with which the reference is
associated. See Table 16.5. MOLD shall not be absent in any other context.
:
Table 16.5: Characteristics of the result of NULL ( )
Appearance of NULL ( ) Type | type parameters, and rank of result:
-----------------------------------------------------------------
:
as an actual argument | the corresponding dummy argument
```
Therefore, the two warnings are spurious.
FYI, in Fortran 2023 Standard, the result of referencing a function
whose result variable has the ALLOCATABLE attribute does not itself
have the ALLOCATABLE attribute, which is not applicable to this
case. Specifically, the characteristics of NULL() and NULL(MOLD) are
explicitly defined in 16.9.155, which allows them to be allocatable
when associated with an allocatable entity.
``` text
8.5.3 ALLOCATABLE attribute
A variable with the ALLOCATABLE attribute is a variable for which space is allocated during execution.
NOTE
Only variables and components can have the ALLOCATABLE attribute. The result of referencing a function
whose result variable has the ALLOCATABLE attribute is a value that does not itself have the ALLOCATABLE
attribute.
```
There is another problem when the dummy argument has the INTENT(IN) attribute: cf. #170780
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs