Skip to content

Commit a4e47cd

Browse files
sameeran joshiSameeranjoshi
authored andcommitted
[Flang][openmp]Fix crash in OpenMP semantic check( bug 48308)
Fixes the bug reported in https://bugs.llvm.org/show_bug.cgi?id=48308 Reviewed By: kiranchandramohan, clementval Differential Revision: https://reviews.llvm.org/D92638
1 parent db41c0b commit a4e47cd

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,17 +875,24 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
875875
}
876876
}
877877

878-
// 2.15.1.1 Data-sharing Attribute Rules - Predetermined
878+
// [OMP-4.5]2.15.1.1 Data-sharing Attribute Rules - Predetermined
879879
// - A loop iteration variable for a sequential loop in a parallel
880880
// or task generating construct is private in the innermost such
881881
// construct that encloses the loop
882+
// Loop iteration variables are not well defined for DO WHILE loop.
883+
// Use of DO CONCURRENT inside OpenMP construct is unspecified behavior
884+
// till OpenMP-5.0 standard.
885+
// In above both cases we skip the privatization of iteration variables.
882886
bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
883-
if (!dirContext_.empty() && GetContext().withinConstruct) {
884-
if (const auto &iv{GetLoopIndex(x)}; iv.symbol) {
885-
if (!iv.symbol->test(Symbol::Flag::OmpPreDetermined)) {
886-
ResolveSeqLoopIndexInParallelOrTaskConstruct(iv);
887-
} else {
888-
// TODO: conflict checks with explicitly determined DSA
887+
// TODO:[OpenMP 5.1] DO CONCURRENT indices are private
888+
if (x.IsDoNormal()) {
889+
if (!dirContext_.empty() && GetContext().withinConstruct) {
890+
if (const auto &iv{GetLoopIndex(x)}; iv.symbol) {
891+
if (!iv.symbol->test(Symbol::Flag::OmpPreDetermined)) {
892+
ResolveSeqLoopIndexInParallelOrTaskConstruct(iv);
893+
} else {
894+
// TODO: conflict checks with explicitly determined DSA
895+
}
889896
}
890897
}
891898
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
2+
3+
subroutine bug48308(x,i)
4+
real :: x(:)
5+
integer :: i
6+
!$omp parallel firstprivate(i)
7+
do while (i>0)
8+
x(i) = i
9+
i = i - 1
10+
end do
11+
!$omp end parallel
12+
end subroutine
13+
14+
subroutine s1(x,i)
15+
real :: x(:)
16+
integer :: i
17+
!$omp parallel firstprivate(i)
18+
do i = 10, 1, -1
19+
x(i) = i
20+
end do
21+
!$omp end parallel
22+
23+
!$omp parallel firstprivate(i)
24+
do concurrent (i = 1:10:1)
25+
x(i) = i
26+
end do
27+
!$omp end parallel
28+
end subroutine

0 commit comments

Comments
 (0)