Skip to content

Commit d4717b9

Browse files
NimishMishranimishra
authored andcommitted
[flang][OpenMP] Added test case for OpenMP 5.0 specification based semantic checks for parallel sections construct
Parallel sections directive borrows the semantic checks from both sections directive and parallel directive. Semantic checks for both are merged in main branch; this test case is added to make sure correct semantic checks upon merging the two. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D111438
1 parent c6390f1 commit d4717b9

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
! RUN: %python %S/test_errors.py %s %flang -fopenmp
2+
! OpenMP version 5.0.0
3+
! 2.13.3 parallel sections Construct
4+
! The restrictions for the parallel construct and the sections construct apply
5+
program OmpConstructSections01
6+
use omp_lib
7+
integer :: section_count = 0
8+
integer, parameter :: NT = 4
9+
integer :: i, array(10)
10+
type my_type
11+
integer :: array(10)
12+
end type my_type
13+
type(my_type) :: my_var
14+
print *, 'section_count', section_count
15+
do i = 1, 10
16+
array(i) = i
17+
end do
18+
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
19+
!$omp parallel sections shared(array(i))
20+
!$omp end parallel sections
21+
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
22+
!$omp parallel sections shared(my_var%array)
23+
!$omp end parallel sections
24+
25+
!ERROR: invalid branch into an OpenMP structured block
26+
!ERROR: invalid branch into an OpenMP structured block
27+
!ERROR: invalid branch into an OpenMP structured block
28+
if (NT) 20, 30, 40
29+
!ERROR: invalid branch into an OpenMP structured block
30+
goto 20
31+
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
32+
!$omp parallel sections private(my_var%array)
33+
!$omp section
34+
print *, "This is a single statement structured block"
35+
!$omp section
36+
open (10, file="random-file-name.txt", err=30)
37+
!ERROR: invalid branch into an OpenMP structured block
38+
!ERROR: invalid branch leaving an OpenMP structured block
39+
open (10, file="random-file-name.txt", err=40)
40+
!$omp section
41+
section_count = section_count + 1
42+
20 print *, 'Entering into section'
43+
call calledFromWithinSection()
44+
print *, 'section_count', section_count
45+
!$omp section
46+
section_count = section_count + 1
47+
print *, 'section_count', section_count
48+
!ERROR: invalid branch leaving an OpenMP structured block
49+
goto 10
50+
!$omp section
51+
30 print *, "Error in opening file"
52+
!$omp end parallel sections
53+
10 print *, 'Jump from section'
54+
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
55+
!$omp parallel sections private(array(i))
56+
!$omp section
57+
40 print *, 'Error in opening file'
58+
!$omp end parallel sections
59+
end program OmpConstructSections01
60+
61+
function returnFromSections()
62+
!$omp parallel sections
63+
!$omp section
64+
!ERROR: RETURN statement is not allowed in a PARALLEL SECTIONS construct
65+
RETURN
66+
!$omp end parallel sections
67+
end function
68+
69+
subroutine calledFromWithinSection()
70+
print *, "I am called from within a 'section' structured block"
71+
return
72+
end subroutine calledFromWithinSection
73+
74+
subroutine continueWithinSections()
75+
integer i
76+
do i = 1, 10
77+
print *, "Statement within loop but outside section construct"
78+
!$omp parallel sections
79+
!$omp section
80+
IF (i .EQ. 5) THEN
81+
!ERROR: CYCLE to construct outside of PARALLEL SECTIONS construct is not allowed
82+
CYCLE
83+
END IF
84+
!$omp end parallel sections
85+
print *, "Statement within loop but outside section contruct"
86+
end do
87+
88+
!$omp parallel sections
89+
!$omp section
90+
do i = 1, 10
91+
CYCLE
92+
end do
93+
!$omp end parallel sections
94+
95+
!$omp parallel sections
96+
!$omp section
97+
loop_1: do i = 1, 10
98+
IF (i .EQ. 5) THEN
99+
CYCLE loop_1
100+
END IF
101+
end do loop_1
102+
!$omp end parallel sections
103+
104+
loop_2: do i = 1, 10
105+
!$omp parallel sections
106+
!$omp section
107+
IF (i .EQ. 5) THEN
108+
!ERROR: CYCLE to construct 'loop_2' outside of PARALLEL SECTIONS construct is not allowed
109+
CYCLE loop_2
110+
END IF
111+
!$omp end parallel sections
112+
end do loop_2
113+
end subroutine continueWithinSections
114+
115+
subroutine breakWithinSections()
116+
loop_3: do i = 1, 10
117+
!$omp parallel sections
118+
!$omp section
119+
IF (i .EQ. 5) THEN
120+
!ERROR: EXIT to construct 'loop_3' outside of PARALLEL SECTIONS construct is not allowed
121+
EXIT loop_3
122+
END IF
123+
!$omp end parallel sections
124+
end do loop_3
125+
126+
loop_4: do i = 1, 10
127+
!$omp parallel sections
128+
!$omp section
129+
IF (i .EQ. 5) THEN
130+
!ERROR: EXIT to construct outside of PARALLEL SECTIONS construct is not allowed
131+
EXIT
132+
END IF
133+
!$omp end parallel sections
134+
end do loop_4
135+
136+
!$omp parallel sections
137+
!$omp section
138+
do i = 1, 10
139+
IF (i .EQ. 5) THEN
140+
EXIT
141+
END IF
142+
end do
143+
!$omp end parallel sections
144+
145+
!$omp parallel sections
146+
!$omp section
147+
loop_5: do i = 1, 10
148+
IF (i .EQ. 5) THEN
149+
EXIT loop_5
150+
END IF
151+
end do loop_5
152+
!$omp end parallel sections
153+
end subroutine breakWithinSections

0 commit comments

Comments
 (0)