llvm / llvm/llvm-project

[Flang] C_SIZEOF on assumed-size array is accepted by Flang

Open
#219,375 0 comments 0 reactions 0 assignees View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Version of flang: 24.0.0git (https://github.com/llvm/llvm-project.git 4639fa213220d55af5d6824924676af02fd03bf8)

## Description

According to the Fortran standard, the ISO/IEC 1539-1:2018 standard, an argument shall be an interoperable data entity that is not an assumed-size array.
However, Flang accepts a call to C_SIZEOF with an assumed-size array argument.
Is this a missing semantic check?


## Reproducer

The following are the test program, Flang, Gfortran and ifx compilation results.

fest.f90:

```fortran
program main
use iso_c_binding
implicit none
integer(c_int),dimension(10) :: a

call sub(a)

contains
subroutine sub(a)
integer(c_int),dimension(*) :: a
print*, c_sizeof(a)
end subroutine

end program
```

```console
$ flang test.f90
$ ./a.out
-4

$ gfortran test.f90
test.f90:11:21:

11 | print*, c_sizeof(a)
| 1
Error: 'x' argument of 'c_sizeof' intrinsic at (1) must be an interoperable data entity: Assumed-size arrays are not interoperable

$ ifx test.f90
test.f90(11): error #8948: This array is not explicit shape. [A]
print*, c_sizeof(a)
---------------------^
compilation aborted for test.f90 (code 1)
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided fest.f90 reproducer with Flang and confirm that C_SIZEOF accepts the assumed-size array. Read the handling of the C_SIZEOF intrinsic and compare the result with the Fortran constraint described in the issue. Done means Flang rejects the call with a diagnostic and regression coverage preserves that behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.