| Issue |
239227
|
| Summary |
[flang] -funsigned: SELECT CASE reports a false conflict when a case value exceeds the signed maximum
|
| Labels |
flang:semantics
|
| Assignees |
|
| Reporter |
eugeneepshteyn
|
With `-funsigned`, `SELECT CASE` on an UNSIGNED selector reports a conflict between disjoint case ranges when one of the values is above the signed maximum of the kind:
```fortran
subroutine s(u)
unsigned(1), intent(in) :: u
select case (u)
case (0u_1:99u_1)
print *, 'low'
case (200u_1:)
print *, 'high'
end select
end subroutine
```
```console
$ flang -funsigned -c t.f90
error: Semantic errors in t.f90
t.f90:6:3: error: CASE (200U_1:) conflicts with previous cases
case (200u_1:)
^^^^^^^^^^^^^^
t.f90:4:3: Conflicting CASE (0U_1:99U_1)
case (0u_1:99u_1)
^^^^^^^^^^^^^^^^^
```
The ranges 0..99 and 200..255 do not overlap, so the subroutine should compile. Every UNSIGNED kind is affected: with `unsigned :: u`, `case (0u:99u)` and `case (3000000000u:)` are reported the same way.
The check in `flang/lib/Semantics/check-case.cpp` sorts the cases with `*x.upper < *y.lower`, and `evaluate::Integer::operator<` compares as signed (`CompareSigned`), so `200u_1` orders as -56 and the ranges look like they overlap. Lowering is not affected: when only `case (200u_1:)` is present, a selector value of `50u_1` correctly goes to `case default`.
Reproduced on x86_64 Linux with main at 1087db09497370a892a0586ffa1e5827ab9b1c4f and with flang 21.1.5.
(This issue was filed with the help of AI)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs