Skip to content

Commit 7cf35e2

Browse files
committed
Fix error messages.
1 parent d7da0b7 commit 7cf35e2

File tree

6 files changed

+41
-27
lines changed

6 files changed

+41
-27
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class OmpWorkshareBlockChecker {
145145

146146
// 'OmpWorkdistributeBlockChecker' is used to check the validity of the
147147
// assignment statements and the expressions enclosed in an OpenMP
148-
// workdistribute construct
148+
// WORKDISTRIBUTE construct
149149
class OmpWorkdistributeBlockChecker {
150150
public:
151151
OmpWorkdistributeBlockChecker(
@@ -165,34 +165,31 @@ class OmpWorkdistributeBlockChecker {
165165
lhs->GetType(), lhs->Rank(), rhs->GetType(), rhs->Rank())};
166166
if (isDefined == Tristate::Yes) {
167167
context_.Say(expr.source,
168-
"Defined assignment statement is not "
169-
"allowed in a WORKDISTRIBUTE construct"_err_en_US);
168+
"Defined assignment statement is not allowed in a WORKDISTRIBUTE construct"_err_en_US);
170169
}
171170
}
172171
return true;
173172
}
174173

175174
bool Pre(const parser::Expr &expr) {
176175
if (const auto *e{GetExpr(context_, expr)}) {
176+
if (!e)
177+
return false;
177178
for (const Symbol &symbol : evaluate::CollectSymbols(*e)) {
178179
const Symbol &root{GetAssociationRoot(symbol)};
179180
if (IsFunction(root)) {
180-
std::string attrs{""};
181+
std::vector<std::string> attrs;
181182
if (!IsElementalProcedure(root)) {
182-
attrs = " non-ELEMENTAL";
183+
attrs.push_back("non-ELEMENTAL");
183184
}
184185
if (root.attrs().test(Attr::IMPURE)) {
185-
if (attrs != "") {
186-
attrs = "," + attrs;
187-
}
188-
attrs = " IMPURE" + attrs;
189-
}
190-
if (attrs != "") {
191-
context_.Say(expr.source,
192-
"User defined%s function '%s' is not allowed in a "
193-
"WORKDISTRIBUTE construct"_err_en_US,
194-
attrs, root.name());
186+
attrs.push_back("IMPURE");
195187
}
188+
std::string attrsStr =
189+
attrs.empty() ? "" : " " + llvm::join(attrs, ", ");
190+
context_.Say(expr.source,
191+
"User defined%s function '%s' is not allowed in a WORKDISTRIBUTE construct"_err_en_US,
192+
attrsStr, root.name());
196193
}
197194
}
198195
}
@@ -879,8 +876,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
879876
if (GetContext().directive == llvm::omp::Directive::OMPD_workdistribute &&
880877
GetContextParent().directive != llvm::omp::Directive::OMPD_teams) {
881878
context_.Say(x.BeginDir().DirName().source,
882-
"%s region can only be strictly nested within the "
883-
"teams region"_err_en_US,
879+
"%s region can only be strictly nested within TEAMS region"_err_en_US,
884880
ContextDirectiveAsFortran());
885881
}
886882
}
@@ -969,7 +965,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
969965
case llvm::omp::OMPD_workdistribute:
970966
if (!CurrentDirectiveIsNested()) {
971967
context_.Say(beginSpec.source,
972-
"A workdistribute region must be nested inside teams region only."_err_en_US);
968+
"A WORKDISTRIBUTE region must be nested inside TEAMS region only."_err_en_US);
973969
}
974970
CheckWorkdistributeBlockStmts(block, beginSpec.source);
975971
break;
@@ -4627,16 +4623,19 @@ void OmpStructureChecker::CheckWorkshareBlockStmts(
46274623

46284624
void OmpStructureChecker::CheckWorkdistributeBlockStmts(
46294625
const parser::Block &block, parser::CharBlock source) {
4626+
unsigned version{context_.langOptions().OpenMPVersion};
4627+
if (version < 60)
4628+
context_.Say(source,
4629+
"WORKDISTRIBUTE construct is only supported from openMP 6.0"_err_en_US);
4630+
46304631
OmpWorkdistributeBlockChecker ompWorkdistributeBlockChecker{context_, source};
46314632

46324633
for (auto it{block.begin()}; it != block.end(); ++it) {
46334634
if (parser::Unwrap<parser::AssignmentStmt>(*it)) {
46344635
parser::Walk(*it, ompWorkdistributeBlockChecker);
46354636
} else {
46364637
context_.Say(source,
4637-
"The structured block in a WORKDISTRIBUTE construct may consist of "
4638-
"only "
4639-
"SCALAR or ARRAY assignments"_err_en_US);
4638+
"The structured block in a WORKDISTRIBUTE construct may consist of only SCALAR or ARRAY assignments"_err_en_US);
46404639
}
46414640
}
46424641
}

flang/test/Parser/OpenMP/workdistribute.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
!RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2-
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=61 %s | FileCheck --check-prefix="PARSE-TREE" %s
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=60 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=60 %s | FileCheck --check-prefix="PARSE-TREE" %s
33

44
!UNPARSE: SUBROUTINE teams_workdistribute
55
!UNPARSE: USE :: iso_fortran_env

flang/test/Semantics/OpenMP/workdistribute01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
22
! OpenMP Version 6.0
33
! workdistribute Construct
44
! Invalid do construct inside !$omp workdistribute
55

66
subroutine workdistribute()
77
integer n, i
8-
!ERROR: A workdistribute region must be nested inside teams region only.
8+
!ERROR: A WORKDISTRIBUTE region must be nested inside TEAMS region only.
99
!ERROR: The structured block in a WORKDISTRIBUTE construct may consist of only SCALAR or ARRAY assignments
1010
!$omp workdistribute
1111
do i = 1, n

flang/test/Semantics/OpenMP/workdistribute02.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
22
! OpenMP Version 6.0
33
! workdistribute Construct
44
! The !omp workdistribute construct must not contain any user defined

flang/test/Semantics/OpenMP/workdistribute03.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
22
! OpenMP Version 6.0
33
! workdistribute Construct
44
! All array assignments, scalar assignments, and masked array assignments
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50
2+
! OpenMP Version 6.0
3+
! workdistribute Construct
4+
! Invalid do construct inside !$omp workdistribute
5+
6+
subroutine teams_workdistribute()
7+
use iso_fortran_env
8+
real(kind=real32) :: a
9+
real(kind=real32), dimension(10) :: x
10+
real(kind=real32), dimension(10) :: y
11+
!ERROR: WORKDISTRIBUTE construct is only supported from openMP 6.0
12+
!$omp teams workdistribute
13+
y = a * x + y
14+
!$omp end teams workdistribute
15+
end subroutine teams_workdistribute

0 commit comments

Comments
 (0)