Skip to content

Commit 8e8113f

Browse files
blazie2004Jay Satish Kumar Patel
andauthored
[Flang][OpenMP] Allow Fortran BLOCK construct inside WORKSHARE region (#193352)
**Problem** Flang incorrectly rejects Fortran BLOCK constructs inside OpenMP WORKSHARE regions. This fixes the semantic check to recursively validate the contents of BLOCK constructs instead of rejecting them. The Fortran BLOCK construct (F2008) is a transparent scoping wrapper that does not affect execution semantics. When a BLOCK appears inside a WORKSHARE region, the restriction on allowed statements should apply to the contents of the BLOCK, not the BLOCK construct itself. **Fix** The function CheckWorkshareBlockStmts (check-omp-structure.cpp) loops through each statement inside a WORKSHARE region and checks if it's allowed. Before this fix, it only recognized: ``` Assignments, FORALL, WHERE statements OpenMP constructs (ATOMIC, CRITICAL, PARALLEL) When it saw a Fortran BLOCK, it didn't recognize it and threw an error. ``` When we see a BLOCK construct, instead of rejecting it, we "look inside" and check if the statements inside the BLOCK are valid. This is done by calling the same function recursively on the BLOCK's contents. Issue : [192930](#192930) --------- Co-authored-by: Jay Satish Kumar Patel <kumarpat@pe31.hpc.amslabs.hpecorp.net>
1 parent f5bb397 commit 8e8113f

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5590,6 +5590,12 @@ void OmpStructureChecker::CheckWorkshareBlockStmts(
55905590
parser::Unwrap<parser::WhereStmt>(*it) ||
55915591
parser::Unwrap<parser::WhereConstruct>(*it)) {
55925592
parser::Walk(*it, ompWorkshareBlockChecker);
5593+
} else if (const auto *blockConstruct{
5594+
parser::Unwrap<parser::BlockConstruct>(*it)}) {
5595+
// Fortran BLOCK construct is a transparent scoping wrapper.
5596+
// Recursively check the statements inside it.
5597+
const auto &nestedBlock{std::get<parser::Block>(blockConstruct->t)};
5598+
CheckWorkshareBlockStmts(nestedBlock, source);
55935599
} else if (const auto *ompConstruct{
55945600
parser::Unwrap<parser::OpenMPConstruct>(*it)}) {
55955601
if (const auto *ompAtomicConstruct{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
! Test that Fortran BLOCK constructs are allowed inside WORKSHARE
3+
! when they contain only WORKSHARE-valid statements.
4+
5+
subroutine test(a, b)
6+
real :: a, b
7+
!$omp workshare
8+
block
9+
a = b
10+
end block
11+
!$omp end workshare
12+
end subroutine

0 commit comments

Comments
 (0)