File: infinite_loop.f90

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (130 lines) | stat: -rw-r--r-- 4,377 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
! RUN: bbc -emit-fir -o - %s | FileCheck %s
! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s

! Tests for infinite loop.

subroutine empty_infinite()
  do
  end do
end subroutine
! CHECK-LABEL: empty_infinite
! CHECK:  cf.br ^[[BODY:.*]]
! CHECK: ^[[BODY]]:
! CHECK:  cf.br ^[[BODY]]

subroutine simple_infinite(i)
  integer :: i
  do
    if (i .gt. 100) exit
  end do
end subroutine
! CHECK-LABEL: simple_infinite
! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
! CHECK:  cf.br ^[[BODY1:.*]]
! CHECK: ^[[BODY1]]:
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[C100:.*]] = arith.constant 100 : i32
! CHECK:  %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
! CHECK:  cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY1:.*]]
! CHECK: ^[[EXIT]]:
! CHECK:  cf.br ^[[RETURN:.*]]
! CHECK: ^[[RETURN]]:
! CHECK:   return
! CHECK: }

subroutine infinite_with_two_body_blocks(i)
  integer :: i
  do
    i = i + 1
    if (i .gt. 100) exit
    i = i * 2
  end do
end subroutine
! CHECK-LABEL: infinite_with_two_body_blocks
! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
! CHECK:  cf.br ^[[BODY1:.*]]
! CHECK: ^[[BODY1]]:
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[C1:.*]] = arith.constant 1 : i32
! CHECK:  %[[I_NEXT:.*]] = arith.addi %[[I]], %[[C1]] : i32
! CHECK:  fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[C100:.*]] = arith.constant 100 : i32
! CHECK:  %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
! CHECK:  cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
! CHECK: ^[[EXIT]]:
! CHECK:  cf.br ^[[RETURN:.*]]
! CHECK: ^[[BODY2]]:
! CHECK:  %[[C2:.*]] = arith.constant 2 : i32
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[I_NEXT:.*]] = arith.muli %[[C2]], %[[I]] : i32
! CHECK:  fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
! CHECK:  cf.br ^[[BODY1]]
! CHECK: ^[[RETURN]]:
! CHECK:   return
! CHECK: }

subroutine structured_loop_in_infinite(i)
  integer :: i
  integer :: j
  do
    if (i .gt. 100) exit
    do j=1,10
    end do
  end do
end subroutine
! CHECK-LABEL: structured_loop_in_infinite
! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
! CHECK:  %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFstructured_loop_in_infiniteEj"}
! CHECK:  cf.br ^[[BODY1:.*]]
! CHECK: ^[[BODY1]]:
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[C100:.*]] = arith.constant 100 : i32
! CHECK:  %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
! CHECK:  cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
! CHECK: ^[[EXIT]]:
! CHECK:  cf.br ^[[RETURN:.*]]
! CHECK: ^[[BODY2:.*]]:
! CHECK:  %[[C1:.*]] = arith.constant 1 : i32
! CHECK:  %[[C1_INDEX:.*]] = fir.convert %[[C1]] : (i32) -> index
! CHECK:  %[[C10:.*]] = arith.constant 10 : i32
! CHECK:  %[[C10_INDEX:.*]] = fir.convert %[[C10]] : (i32) -> index
! CHECK:  %[[C1_1:.*]] = arith.constant 1 : index
! CHECK:  %[[J_LB:.*]] = fir.convert %[[C1_INDEX]] : (index) -> i32
! CHECK:  %[[J_FINAL:.*]]:2 = fir.do_loop %[[J:[^ ]*]] =
! CHECK-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
! CHECK-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
! CHECK:    fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
! CHECK:    %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
! CHECK:    %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
! CHECK:    %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
! CHECK:    %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
! CHECK:    fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
! CHECK:  }
! CHECK:  fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
! CHECK:  cf.br ^[[BODY1]]
! CHECK: ^[[RETURN]]:
! CHECK:   return

subroutine empty_infinite_in_while(i)
  integer :: i
  do while (i .gt. 50)
    do
    end do
  end do
end subroutine

! CHECK-LABEL: empty_infinite_in_while
! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
! CHECK:  cf.br ^bb1
! CHECK: ^bb1:
! CHECK:  %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
! CHECK:  %[[C50:.*]] = arith.constant 50 : i32
! CHECK:  %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C50]] : i32
! CHECK:  cf.cond_br %[[COND]], ^[[INF_HEADER:.*]], ^[[EXIT:.*]]
! CHECK: ^[[INF_HEADER]]:
! CHECK:   cf.br ^[[INF_BODY:.*]]
! CHECK: ^[[INF_BODY]]:
! CHECK:   cf.br ^[[INF_HEADER]]
! CHECK: ^[[EXIT]]:
! CHECK:  return