[OpenMP 60] Update parsing and semantic support for nowait clause to accept optional argument by mdfazlay · Pull Request #159628 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-flang-openmp

Author: Fazlay Rabbi (mdfazlay)

Changes

This PR enhances the OpenMP nowait clause implementation by adding support for optional argument in both parsing and semantic analysis phases.

Reference:

  1. OpenMP 6.0 Specification, page 481

Patch is 39.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/159628.diff

26 Files Affected:

diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index b2a6d4b9182b0..fd90988971d8d 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2217,18 +2217,62 @@ class OMPOrderedClause final /// This represents 'nowait' clause in the '#pragma omp ...' directive. /// /// \code -/// #pragma omp for nowait +/// #pragma omp for nowait (cond) /// \endcode -/// In this example directive '#pragma omp for' has 'nowait' clause. -class OMPNowaitClause final : public OMPNoChildClausellvm::omp::OMPC_nowait { +/// In this example directive '#pragma omp for' has simple 'nowait' clause with +/// condition 'cond'. +class OMPNowaitClause final : public OMPClause {

/// This represents 'untied' clause in the '#pragma omp ...' directive. diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index c1944487716de..8f1500993dcc8 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3576,7 +3576,8 @@ bool RecursiveASTVisitor::VisitOMPOrderedClause(OMPOrderedClause *C) { }

template -bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *) { +bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *C) {

diff --git a/clang/include/clang/Sema/SemaOpenMP.h b/clang/include/clang/Sema/SemaOpenMP.h index 23827051ed724..511aab39ec93d 100644 --- a/clang/include/clang/Sema/SemaOpenMP.h +++ b/clang/include/clang/Sema/SemaOpenMP.h @@ -1002,8 +1002,10 @@ class SemaOpenMP : public SemaBase { OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, SourceLocation EndLoc); /// Called on well-formed 'nowait' clause.

diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index 69d33019c0952..c7876cc9cd1db 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -306,6 +306,13 @@ OMPClause::child_range OMPIfClause::used_children() { return child_range(&Condition, &Condition + 1); }

+OMPClause::child_range OMPNowaitClause::used_children() {

@@ -2004,8 +2011,13 @@ void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *Node) { } }

-void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { +void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *Node) { OS << "nowait";

void OMPClausePrinter::VisitOMPUntiedClause(OMPUntiedClause *) { diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 37c4d43ec0b2f..65a03cd7f91b3 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -578,7 +578,10 @@ void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) { Profiler->VisitStmt(Num); }

-void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {} +void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *C) {

+}

void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 7dceb2d208352..c17f499a7710f 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -3025,6 +3025,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_simdlen: case OMPC_collapse: case OMPC_ordered:

case OMPC_priority: Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); break; @@ -15701,7 +15704,6 @@ OMPClause *SemaOpenMP::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, case OMPC_aligned: case OMPC_copyin: case OMPC_copyprivate:

OMPClause *SemaOpenMP::ActOnOpenMPNowaitClause(SourceLocation StartLoc,

}

OMPClause *SemaOpenMP::ActOnOpenMPUntiedClause(SourceLocation StartLoc, diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 242ffb09af006..a748219051304 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1857,6 +1857,17 @@ class TreeTransform { LParenLoc, Num); }

}

template diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 9ee8a0fb0f060..8f9fda88bd661 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -11673,7 +11673,10 @@ void OMPClauseReader::VisitOMPDetachClause(OMPDetachClause *C) { C->setLParenLoc(Record.readSourceLocation()); }

-void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {} +void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *C) {

void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}

diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 3293a54a0a093..fac91d86858e7 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -7926,7 +7926,10 @@ void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) { Record.AddSourceLocation(C->getLParenLoc()); }

-void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} +void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *C) {

void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}

diff --git a/clang/test/OpenMP/nowait_ast_print.cpp b/clang/test/OpenMP/nowait_ast_print.cpp new file mode 100644 index 0000000000000..4151a397beb9c --- /dev/null +++ b/clang/test/OpenMP/nowait_ast_print.cpp @@ -0,0 +1,56 @@ +// Check no warnings/errors +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s +// expected-no-diagnostics + +// Check AST and unparsing +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-dump %s | FileCheck %s --check-prefix=DUMP +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix=PRINT + +// Check same results after serialization round-trip +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -emit-pch -o %t %s +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT + +#ifndef HEADER +#define HEADER + +void nowait() {

\ No newline at end of file diff --git a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp index ba5eaf1d2214a..0b892325a1c69 100644 --- a/clang/test/OpenMP/target_enter_data_nowait_messages.cpp +++ b/clang/test/OpenMP/target_enter_data_nowait_messages.cpp @@ -13,15 +13,23 @@ int main(int argc, char **argv) { {} #pragma omp target enter nowait data map(to: i) // expected-error {{expected an OpenMP directive}} {}

int main(int argc, char **argv) {

[truncated]