summaryrefslogtreecommitdiff
path: root/flang/test/Semantics/OpenMP/invalid-branch.f90
blob: ed9e4d268f65a8c49f426723dae6914a7960e4fc (plain)
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
! RUN: not %flang -fsyntax-only -fopenmp %s 2>&1 | FileCheck %s
! REQUIRES: shell
! OpenMP Version 4.5
! Check invalid branches into or out of OpenMP structured blocks.

subroutine omp_err_end_eor(a, b, x)
  integer x

  !$omp parallel
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into

  !CHECK: invalid branch leaving an OpenMP structured block
  !CHECK: Outside the enclosing PARALLEL directive
  open (10, file="myfile.dat", err=100)
  !CHECK: invalid branch leaving an OpenMP structured block
  !CHECK: Outside the enclosing PARALLEL directive

  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into

  !CHECK: invalid branch leaving an OpenMP structured block
  !CHECK: Outside the enclosing PARALLEL directive
  read (10, 20, end=200, size=x, advance='no', eor=300) a
  !$omp end parallel

  goto 99
  99 close (10)
  goto 40
  !$omp parallel
  100 print *, "error opening"
  !$omp end parallel
  101 return
  200 print *, "end of file"
  202 return

  !$omp parallel
  300 print *, "end of record"
  !$omp end parallel

  303 return
  20 format (1x,F5.1)
  30 format (2x,F6.2)
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into
  40 open (11, file="myfile2.dat", err=100)
  goto 50
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into
  50 write (11, 30, err=100) b
  close (11)
end subroutine

subroutine omp_alt_return_spec(n, *, *)
  if (n .eq. 0) return
  if (n .eq. 1) return 1
  return 2
end subroutine

program omp_invalid_branch
  integer :: n = 0, a = 3, b

  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into

  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into
  goto (1, 2, 3) a

  assign 2 to b
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing PARALLEL directive branched into
  goto b (1, 2)

  !$omp parallel
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing SINGLE directive branched into

  !CHECK: invalid branch leaving an OpenMP structured block
  !CHECK: Outside the enclosing PARALLEL directive
  3 if(n) 4, 5, 6

  6 print *, 6
  2 print *, 2

  !$omp single
  4 print *, 4
  !$omp end single
  !$omp end parallel

  1 print *, 1
  5 print *, 5

  !$omp parallel
  !CHECK: invalid branch into an OpenMP structured block
  !CHECK: In the enclosing SINGLE directive branched into

  !CHECK: invalid branch leaving an OpenMP structured block
  !CHECK: Outside the enclosing PARALLEL directive
  call omp_alt_return_spec(n, *8, *9)
  print *, "Normal Return"
  !$omp single
  8 print *, "1st alternate return"
  !$omp end single
  !$omp end parallel
  9 print *, "2nd alternate return"

end program