IR: de-duplicate two CmpInst routines (NFC) (#116866)
[llvm-project.git] / flang / test / Lower / goto-statement.f90
blobf69ed6ba656a2058111bca8147f62623d2aff266
1 ! RUN: bbc %s -emit-fir -hlfir=false -o - | FileCheck %s
3 ! Test trivial goto statement
4 subroutine sub1()
5 goto 1
6 1 stop
7 end subroutine
8 ! CHECK-LABEL: sub1
9 ! CHECK: cf.br ^[[BB1:.*]]
10 ! CHECK: ^[[BB1]]:
11 ! CHECK: {{.*}} fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) {{.*}}: (i32, i1, i1) -> none
12 ! CHECK: }
14 ! Test multiple goto statements
15 subroutine sub2()
16 goto 1
17 1 goto 2
18 2 goto 3
19 3 stop
20 end subroutine
21 ! CHECK-LABEL: sub2
22 ! CHECK: cf.br ^[[BB1:.*]]
23 ! CHECK: ^[[BB1]]:
24 ! CHECK: cf.br ^[[BB2:.*]]
25 ! CHECK: ^[[BB2]]:
26 ! CHECK: cf.br ^[[BB3:.*]]
27 ! CHECK: ^[[BB3]]:
28 ! CHECK: {{.*}} fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) {{.*}}: (i32, i1, i1) -> none
29 ! CHECK: }
31 ! Test goto which branches to a previous label
32 subroutine sub3()
33 pause
34 1 goto 3
35 2 stop
36 3 goto 2
37 end subroutine
38 ! CHECK: sub3
39 ! CHECK: {{.*}} fir.call @_FortranAPauseStatement() {{.*}}: () -> none
40 ! CHECK: cf.br ^[[BB2:.*]]
41 ! CHECK: ^[[BB1:.*]]: //
42 ! CHECK: {{.*}} fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) {{.*}}: (i32, i1, i1) -> none
43 ! CHECK: ^[[BB2]]:
44 ! CHECK: cf.br ^[[BB1]]
45 ! CHECK: }
47 ! Test removal of blocks (pauses) which are not reachable
48 subroutine sub4()
49 pause
50 1 goto 2
51 pause
52 2 goto 3
53 pause
54 3 goto 1
55 pause
56 end subroutine
57 ! CHECK-LABEL: sub4
58 ! CHECK: {{.*}} fir.call @_FortranAPauseStatement() {{.*}}: () -> none
59 ! CHECK-NEXT: cf.br ^[[BB1:.*]]
60 ! CHECK-NEXT: ^[[BB1]]:
61 ! CHECK-NEXT: cf.br ^[[BB2:.*]]
62 ! CHECK-NEXT: ^[[BB2]]:
63 ! CHECK-NEXT: cf.br ^[[BB3:.*]]
64 ! CHECK-NEXT: ^[[BB3]]:
65 ! CHECK-NEXT: cf.br ^[[BB1]]
66 ! CHECK-NEXT: }