<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118238>118238</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] No error checking of out-of-bounds access
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang : 20.0.0(590f451b60d434b26c634a07125fb05baf461fa0)/AArch64
```
An error is detected for `test program 1 (iqui01.f90)` with out-of-bounds access such as the attached.
However, any errors are not detected for `test program 2 (iqui01_2.f90)` with `test program 1` modified.
The change is as follows.
Before:
```
i1(5) = 1
```
After:
```
! i1(5) = 1
n = 5
i1(n)=1
```
Should flang also detect errors for `test program 2`?
When the compilation option (`-check all`) is specified, ifx outputs error for both `test program 1` and `test program2`.
Without the option, both `test program 1` and `test program 2` are compiled and executed normally.
The following are the test program, Flang, Gfortran and ifx compilation/execution result.
iqui01.f90:
```fortran
module mod2
integer*1 i1(1)
integer*4 i4(10)
equivalence (i1,i4)
end module mod2
program main
use mod2
i1(5) = 1
if (i4(2) .ne. 1) stop
write(6,*) "pass"
end program main
```
```
$ flang iqui01.f90
error: Semantic errors in iqui01.f90
./iqui01.f90:9:3: error: Subscript 5 is greater than upper bound 1 for dimension 1 of array
i1(5) = 1
^^^^^
./iqui01.f90:8:7: 'i1' is USE-associated with 'i1' in module 'mod2'
use mod2
^^^^
$
```
```
$ gfortran iqui01.f90; ./a.out
iqui01.f90:9:5:
9 | i1(5) = 1
| 1
Warning: Array reference at (1) is out of bounds (5 > 1) in dimension 1
pass
$
```
```
$ ifx iqui01.f90; ./a.out
pass
$
```
```
$ ifx -check all iqui01.f90
iqui01.f90(9): error #5560: Subscript #1 of the array I1 has value 5 which is greater than the upper bound of 1
i1(5) = 1
--^
compilation aborted for iqui01.f90 (code 1)
$
```
iqui01_2.f90:
```fortran
module mod2
integer*1 i1(1)
integer*4 i4(10)
equivalence (i1,i4)
end module mod2
program main
use mod2
! i1(5) = 1
n = 5
i1(n)=1
if (i4(2) .ne. 1) stop
write(6,*) "pass"
end program main
```
```
$ flang iqui01_2.f90; ./a.out
pass
$
```
```
$ gfortran iqui01_2.f90; ./a.out
pass
$
```
```
$ ifx iqui01_2.f90; ./a.out
pass
$
```
```
$ ifx -check all iqui01_2.f90; ./a.out
forrtl: severe (408): fort: (2): Subscript #1 of the array I1 has value 5 which is greater than the upper bound of 1
Image PC Routine Line Source
a.out 0000000000499842 Unknown Unknown Unknown
a.out 000000000040C079 Unknown Unknown Unknown
libc.so.6 00007F5E008F1590 Unknown Unknown Unknown
libc.so.6 00007F5E008F1640 __libc_start_main Unknown Unknown
a.out 000000000040BF45 Unknown Unknown Unknown
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V01v2zgQ_TX0ZWCBor4PPigf3i2wWCw22-0xoCTSYiuTLkklzb9fDCUnsuO2G7QVjEjIcGbePL4ZStw5tdNCbEh2RbKbFR99b-zG9Nqs5cdVY7qnDcnp_KP1v8I6ZTQYCXLgegckqYHRiEaUsDKrqEyzuMlplyZpw_I2T1JOi5hlsqFZw2Wax5JTwirCtnVt2z5PCa2XGQitaw3CWmNBOeiEF60XHUhjgeTUC-fhYM3O8j3EQFipPo-KxpGsQticwqPyPZjRr41cN2bUnQPetsI5cGPbA3fgewHce972oosACK1_N4_iQVjCroHrpym9A24FaOO_DYK9gLhn5zBeIUbL3nRKqmPqf3oBbc_1TmC93IE0w2AeXYTGKyGNFSSpz1gCUDESTlgFJLmB-MxeSy_sazfC4guOADo8Z_gczBprSG7OoxJa3_VmHLp58_ngzEzOkbKLDKF3sg3VfuiFDvy3Zn9QA_dBTYdwI6wkOV23vWg_AR8GdGMVsuIOog2U4QYp-QW39zB6N-sEkzbma3Rz3Z0bENHE_gflezP6AGmCgSneFCzUF7Qy1SS6sEp8Ee2IotHG7vkwPEUTg7jf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