<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109983>109983</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Inconsistent compilation results for programs with almost the same error
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following three programs. These are all invalid.
test1.f90
```f90
character(len=5) :: s
s = "flang"
print*, "s:", s(-1111111111111111111:4)
end
```
test2.f90
```f90
character(len=5) :: s
s = "flang"
print*, "s:", s(-11111111111111111111:4)
end
```
test3.f90
```f90
character(len=5) :: s
s = "flang"
print*, "s:", s(-111111111111111111111:4)
end
```
Gfortran rejects the above three programs with the same message.
```console
$ gfortran test1.f90
test1.f90:3:16:
3 | print*, "s:", s(-1111111111111111111:4)
| 1
Error: Syntax error in PRINT statement at (1)
$ gfortran test2.f90
test2.f90:3:16:
3 | print*, "s:", s(-11111111111111111111:4)
| 1
Error: Syntax error in PRINT statement at (1)
$ gfortran test3.f90
test3.f90:3:16:
3 | print*, "s:", s(-111111111111111111111:4)
| 1
Error: Syntax error in PRINT statement at (1)
```
With flang-new, I got the following results.
```console
$ flang-new test1.f90
error: Semantic errors in test1.f90
./test1.f90:3:15: error: Substring must begin at 1 or later, not -1111111111111111111
print*, "s:", s(-1111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^
$ flang-new test2.f90
./test2.f90:3:15: warning: INTEGER(16) to INTEGER(8) conversion overflowed
print*, "s:", s(-11111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^^
$ ./a.out
s:
$ flang-new test3.f90
error: Semantic errors in test3.f90
./test3.f90:3:15: warning: INTEGER(16) to INTEGER(8) conversion overflowed
print*, "s:", s(-111111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
./test3.f90:3:15: error: Substring must begin at 1 or later, not -430646668853801415
print*, "s:", s(-111111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
./test3.f90:3:15: warning: INTEGER(16) to INTEGER(8) conversion overflowed
print*, "s:", s(-111111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
./test3.f90:3:15: error: Substring must begin at 1 or later, not -430646668853801415
print*, "s:", s(-111111111111111111111:4)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
It seems more consistent for `test2.f90` and `test3.f90` to be rejected with the same error message as `test1.f90`. Also, the error message for `test3.f90` is incorrect because the number `-430646668853801415` does not exist in `test3.f90`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV9Fzo7YT_mvkl50wIAHGDzz4F8c3ebn5zTUzfRawxmqFlNEK--6_7wiI7eCk7aW5TtqpzNhm0S7f9-2uEJJItQaxZNn_WLZZyN7vrSt_vZHO2SMtKtt8K2-tIdWgA79H2Fmt7VGZFvzeIcKjs62THUXwsEdCkA5Bag3KHKRWTcTiDYvX47dH8km0W8WTMY_H42Sp99LJ2qNjvNBomNhkjK-AiTUTa6BxEgETG2Cc77Q0LeN8ND86ZTzja8Zvw0UKTpyHM2K8uEmuBxPrlPHV6I6mmaGaI-cfB_n3QhcfCPr3YP-0s847acDhL1h7GipQVvaAs-qDo_L74SrJDqFDItliNAtdW0NW42TlKbRP8WeVeT4Va8HEOskDsQtgAAAC2PIW_mLZwTBCoNlIxut3zlkX8vDTN-PlV8BwDsrA_7_cf34A8tJjh8aD9MB4kZwCX9Hjz-nx36X3Vm6vkXt3NuI5G_GjkvW3peul8v85FPXQcDcGjwHmPbTWz9Zhh9RrT39Y7KdA82rHE2jspPGqHmFTwD2bGjG-vWqOLPieg_QVeReAdT15qLBVJtBNwDrQclhnbsFYDy82xyTzu7TVebDs7t2OVwTl1yrxK5WO0hll2vD3_vPD3ae7L6EK8rDeenthKoKltuaAjpQ1YA_odtoesXm7QDOF3lOSS1UCeRnZ3k_3oXM3X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