Skip to content

Commit

Permalink
[flang][semantics][OpenMP] no privatisation of stmt functions
Browse files Browse the repository at this point in the history
OpenMP prohibits privatisation of variables that appear in expressions
for statement functions.

This is a re-working of an old patch https://reviews.llvm.org/D93213 by
@praveen-g-ctt.

The old patch couldn't be landed because of ordering concerns. Statement
functions are rewritten during parse tree rewriting, but this was done
after resolve-directives and so some array expressions were incorrectly
identified as statement functions. For this reason **I have opted to
re-order the semantics driver so that resolve-directives is run after
parse tree rewriting**.

Closes #54677

Co-authored-by: Praveen <praveen@compilertree.com>
  • Loading branch information
tblah and praveen-g-ctt committed Oct 2, 2024
1 parent 3717048 commit 2c6b70f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
8 changes: 8 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,14 @@ void OmpAttributeVisitor::CheckObjectInNamelistOrAssociate(
"Variable '%s' in ASSOCIATE cannot be in a %s clause"_err_en_US,
name.ToString(), clauseName.str());
}

if (stmtFunctionExprSymbols_.find(ultimateSymbol) !=
stmtFunctionExprSymbols_.end()) {
context_.Say(name.source,
"Variable '%s' in STATEMENT FUNCTION expression cannot be in a "
"%s clause"_err_en_US,
name.ToString(), clauseName.str());
}
}

void OmpAttributeVisitor::CheckSourceLabel(const parser::Label &label) {
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ bool Semantics::Perform() {
CanonicalizeAcc(context_.messages(), program_) &&
CanonicalizeOmp(context_.messages(), program_) &&
CanonicalizeCUDA(program_) &&
CanonicalizeDirectives(context_.messages(), program_) &&
PerformStatementSemantics(context_, program_) &&
CanonicalizeDirectives(context_.messages(), program_) &&
ModFileWriter{context_}
.set_hermeticModuleFileOutput(hermeticModuleFileOutput_)
.WriteAll();
Expand Down
39 changes: 39 additions & 0 deletions flang/test/Semantics/OpenMP/private03.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! OpenMP Version 4.5
! Variables that appear in expressions for statement function definitions
! may not appear in private, firstprivate or lastprivate clauses.

subroutine stmt_function(temp)

integer :: i, p, q, r
real :: c, f, s, v, t(10)
real, intent(in) :: temp

c(temp) = p * (temp - q) / r
f(temp) = q + (temp * r/p)
v(temp) = c(temp) + f(temp)/2 - s

p = 5
q = 32
r = 9

!ERROR: Variable 'p' in STATEMENT FUNCTION expression cannot be in a PRIVATE clause
!$omp parallel private(p)
s = c(temp)
!$omp end parallel

!ERROR: Variable 's' in STATEMENT FUNCTION expression cannot be in a FIRSTPRIVATE clause
!$omp parallel firstprivate(s)
s = s + f(temp)
!$omp end parallel

!ERROR: Variable 's' in STATEMENT FUNCTION expression cannot be in a LASTPRIVATE clause
!$omp parallel do lastprivate(s, t)
do i = 1, 10
t(i) = v(temp) + i - s
end do
!$omp end parallel do

print *, t

end subroutine stmt_function

0 comments on commit 2c6b70f

Please sign in to comment.