1! { dg-do run }
2! PR 51858 - this used to generate wrong code.
3! Original test case by Don Simons.
4
5program main
6  implicit none
7  logical :: test1_ok
8  logical :: test2_ok
9  logical :: test3_ok
10  character(len=1):: charq
11
12  charq = 'c'
13
14  test1_ok = .true.
15  test2_ok = .false.
16  if (charq .eq. ' ') then
17     test1_ok = .false.
18  else if ((my_ichar(charq).ge.97 .and. my_ichar(charq).le.103)) then
19     test2_OK = .true.
20  end if
21  if ((.not. test1_ok) .or. (.not. test2_ok)) call abort
22
23  test1_ok = .true.
24  test2_ok = .true.
25  test3_ok = .false.
26
27  if (charq .eq. ' ') then
28     test1_ok = .false.
29  else if ((my_ichar(charq).lt.97 .or. my_ichar(charq).gt.103)) then
30     test2_ok = .false.
31  else if ((my_ichar(charq).ge.97 .and. my_ichar(charq).le.103)) then
32     test3_ok = .true.
33  end if
34  if ((.not. test1_ok) .or. (.not. test2_ok) .or. (.not. test3_ok)) call abort
35
36  test1_ok = .true.
37  test2_ok = .true.
38  test3_ok = .false.
39
40  if (charq .eq. ' ') then
41     test1_ok = .false.
42  else if ((my_ichar(charq).lt.97 .or. my_ichar(charq).gt.103)) then
43     test2_ok = .false.
44  else
45     test3_ok = .true.
46  end if
47
48  if ((.not. test1_ok) .or. (.not. test2_ok) .or. (.not. test3_ok)) call abort
49
50contains
51  pure function my_ichar(c)
52    integer :: my_ichar
53    character(len=1), intent(in) :: c
54    my_ichar = ichar(c)
55  end function my_ichar
56end program main
57
58