llvm / llvm/llvm-project

[Flang] IS_CONTIGUOUS results for constant-shaped array sections are not treated as constants

Open
#199,879 2 comments 0 reactions 1 assignee Claimed by @eugeneepshteyn View on GitHub
flang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

The results of the IS_CONTIGUOUS intrinsic for array sections with constant shapes are not being treated as compile-time constants. This derives from #115675, which has already been fixed. It appears that some cases are missed.

### Reproducer

* test.f90

```fortran
character(5) :: array(3,2,4)
logical,parameter::a03=is_contiguous(array(:,:,:)(1:4)) ! from #115675
logical,parameter::a07=is_contiguous(array(2:,:,:))
logical,parameter::a08=is_contiguous(array(2:,:,:)(:))
logical,parameter::a12=is_contiguous(array(:2,:,:))
logical,parameter::a13=is_contiguous(array(:2,:,:)(:))
logical,parameter::a17=is_contiguous(array(2:3,:,:))
logical,parameter::a18=is_contiguous(array(2:3,:,:)(:))
logical,parameter::a20=is_contiguous(array(2:3,:,:)(:5))

if (a03) print *,2003
if (a07) print *,2007
if (a08) print *,2008
if (a12) print *,2012
if (a13) print *,2013
if (a17) print *,2017
if (a18) print *,2018
if (a20) print *,2020
print *,'pass'
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git f95ccbae8bd70e56e31fc04d6307d317212b7fbc)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 && ./a.out
error: Semantic errors in test.f90
test.f90:3:24: error: Must be a constant value
logical,parameter::a07=is_contiguous(array(2:,:,:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:4:24: error: Must be a constant value
logical,parameter::a08=is_contiguous(array(2:,:,:)(:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:5:24: error: Must be a constant value
logical,parameter::a12=is_contiguous(array(:2,:,:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:6:24: error: Must be a constant value
logical,parameter::a13=is_contiguous(array(:2,:,:)(:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:7:24: error: Must be a constant value
logical,parameter::a17=is_contiguous(array(2:3,:,:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:8:24: error: Must be a constant value
logical,parameter::a18=is_contiguous(array(2:3,:,:)(:))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.f90:9:24: error: Must be a constant value
logical,parameter::a20=is_contiguous(array(2:3,:,:)(:5))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Replacing IS_CONTIGUOUS with other intrinsics (e.g., SIZE):
```fortran
character(5) :: array(3,2,4)
integer,parameter::a03=size(array(:,:,:)(1:4))
integer,parameter::a07=size(array(2:,:,:))
integer,parameter::a08=size(array(2:,:,:)(:))
integer,parameter::a12=size(array(:2,:,:))
integer,parameter::a13=size(array(:2,:,:)(:))
integer,parameter::a17=size(array(2:3,:,:))
integer,parameter::a18=size(array(2:3,:,:)(:))
integer,parameter::a20=size(array(2:3,:,:)(:5))

if (a03 /= 24) print *,2003
if (a07 /= 16) print *,2007
if (a08 /= 16) print *,2008
if (a12 /= 16) print *,2012
if (a13 /= 16) print *,2013
if (a17 /= 16) print *,2017
if (a18 /= 16) print *,2018
if (a20 /= 16) print *,2020
print *,'pass'
end
```

## Other Compilers

* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gfortran test.f90 && ./a.out
pass
```

* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.

$ ifx -O0 test.f90 && ./a.out
pass
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.