[llvm-branch-commits] [OpenMP] Add tests for 'replayable' clause (PR #194054)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 24 13:55:42 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Julian Brown (jtb20)

<details>
<summary>Changes</summary>

These are parsing and diagnostics tests for the replayable clause added
by the previous patch.

Assisted-By: Codex with gpt-5.3

commit-id:6a552a7c


---
Full diff: https://github.com/llvm/llvm-project/pull/194054.diff


2 Files Affected:

- (added) clang/test/OpenMP/replayable_ast_print.cpp (+233) 
- (added) clang/test/OpenMP/replayable_messages.cpp (+51) 


``````````diff
diff --git a/clang/test/OpenMP/replayable_ast_print.cpp b/clang/test/OpenMP/replayable_ast_print.cpp
new file mode 100644
index 0000000000000..cea97b8b1cd73
--- /dev/null
+++ b/clang/test/OpenMP/replayable_ast_print.cpp
@@ -0,0 +1,233 @@
+// 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 replayable_clauses() {
+  int A = 1;
+  int B[10];
+
+  // --- omp task ---
+
+  // DUMP: OMPTaskDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // PRINT: #pragma omp task replayable
+  #pragma omp task replayable
+  {}
+
+  // DUMP: OMPTaskDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp task replayable(false)
+  #pragma omp task replayable(false)
+  {}
+
+  // DUMP: OMPTaskDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp task replayable(true)
+  #pragma omp task replayable(true)
+  {}
+
+  // DUMP: OMPTaskDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp task replayable(A > 5)
+  #pragma omp task replayable(A > 5)
+  {}
+
+  // --- omp taskloop ---
+
+  // DUMP: OMPTaskLoopDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // PRINT: #pragma omp taskloop replayable
+  #pragma omp taskloop replayable
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  // DUMP: OMPTaskLoopDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp taskloop replayable(false)
+  #pragma omp taskloop replayable(false)
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  // DUMP: OMPTaskLoopDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp taskloop replayable(true)
+  #pragma omp taskloop replayable(true)
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  // DUMP: OMPTaskLoopDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp taskloop replayable(A > 5)
+  #pragma omp taskloop replayable(A > 5)
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  // --- omp taskwait ---
+
+  // DUMP: OMPTaskwaitDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // PRINT: #pragma omp taskwait replayable
+  #pragma omp taskwait replayable
+
+  // DUMP: OMPTaskwaitDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp taskwait replayable(false)
+  #pragma omp taskwait replayable(false)
+
+  // DUMP: OMPTaskwaitDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp taskwait replayable(true)
+  #pragma omp taskwait replayable(true)
+
+  // DUMP: OMPTaskwaitDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp taskwait replayable(A > 5)
+  #pragma omp taskwait replayable(A > 5)
+
+  // --- omp target ---
+
+  // DUMP: OMPTargetDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // PRINT: #pragma omp target replayable
+  #pragma omp target replayable
+  {}
+
+  // DUMP: OMPTargetDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp target replayable(false)
+  #pragma omp target replayable(false)
+  {}
+
+  // DUMP: OMPTargetDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp target replayable(true)
+  #pragma omp target replayable(true)
+  {}
+
+  // DUMP: OMPTargetDirective
+  // DUMP-NEXT: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp target replayable(A > 5)
+  #pragma omp target replayable(A > 5)
+  {}
+
+  // --- omp target enter data ---
+
+  // DUMP: OMPTargetEnterDataDirective
+  // DUMP: OMPReplayableClause
+  // PRINT: #pragma omp target enter data map(to: A) replayable
+  #pragma omp target enter data map(to: A) replayable
+
+  // DUMP: OMPTargetEnterDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp target enter data map(to: A) replayable(false)
+  #pragma omp target enter data map(to: A) replayable(false)
+
+  // DUMP: OMPTargetEnterDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp target enter data map(to: A) replayable(true)
+  #pragma omp target enter data map(to: A) replayable(true)
+
+  // DUMP: OMPTargetEnterDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp target enter data map(to: A) replayable(A > 5)
+  #pragma omp target enter data map(to: A) replayable(A > 5)
+
+  // --- omp target exit data ---
+
+  // DUMP: OMPTargetExitDataDirective
+  // DUMP: OMPReplayableClause
+  // PRINT: #pragma omp target exit data map(from: A) replayable
+  #pragma omp target exit data map(from: A) replayable
+
+  // DUMP: OMPTargetExitDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp target exit data map(from: A) replayable(false)
+  #pragma omp target exit data map(from: A) replayable(false)
+
+  // DUMP: OMPTargetExitDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp target exit data map(from: A) replayable(true)
+  #pragma omp target exit data map(from: A) replayable(true)
+
+  // DUMP: OMPTargetExitDataDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp target exit data map(from: A) replayable(A > 5)
+  #pragma omp target exit data map(from: A) replayable(A > 5)
+
+  // --- omp target update ---
+
+  // DUMP: OMPTargetUpdateDirective
+  // DUMP: OMPReplayableClause
+  // PRINT: #pragma omp target update to(A) replayable
+  #pragma omp target update to(A) replayable
+
+  // DUMP: OMPTargetUpdateDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' false
+  // PRINT: #pragma omp target update to(A) replayable(false)
+  #pragma omp target update to(A) replayable(false)
+
+  // DUMP: OMPTargetUpdateDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: XXBoolLiteralExpr {{.*}} 'bool' true
+  // PRINT: #pragma omp target update to(A) replayable(true)
+  #pragma omp target update to(A) replayable(true)
+
+  // DUMP: OMPTargetUpdateDirective
+  // DUMP: OMPReplayableClause
+  // DUMP-NEXT: BinaryOperator {{.*}} 'bool' '>'
+  // DUMP-NEXT: ImplicitCastExpr {{.*}} 'int' <LValueToRValue>
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'A' 'int'
+  // DUMP-NEXT: IntegerLiteral {{.*}} 'int' 5
+  // PRINT: #pragma omp target update to(A) replayable(A > 5)
+  #pragma omp target update to(A) replayable(A > 5)
+}
+#endif
diff --git a/clang/test/OpenMP/replayable_messages.cpp b/clang/test/OpenMP/replayable_messages.cpp
new file mode 100644
index 0000000000000..10172f50162ad
--- /dev/null
+++ b/clang/test/OpenMP/replayable_messages.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=51 -verify=expected,omp51 -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -verify=expected,omp60 -fsyntax-only %s
+
+// Tests that the 'replayable' clause is accepted in OpenMP 6.0 and rejected in
+// prior versions on all seven supported directives. Also tests duplicate-clause
+// and invalid-condition diagnostics.
+
+void foo() {}
+
+void replayable_messages() {
+  int A = 1;
+
+  #pragma omp task replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp task'}}
+  {}
+
+  #pragma omp taskloop replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp taskloop'}}
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  #pragma omp taskwait replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp taskwait'}}
+
+  #pragma omp target replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target'}}
+  {}
+
+  #pragma omp target enter data map(to: A) replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target enter data'}}
+
+  #pragma omp target exit data map(from: A) replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target exit data'}}
+
+  #pragma omp target update to(A) replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target update'}}
+
+  #pragma omp task replayable replayable // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp task'}} omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp task'}} expected-error {{directive '#pragma omp task' cannot contain more than one 'replayable' clause}}
+  {}
+
+  #pragma omp task replayable(foo()) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp task'}} omp60-error {{value of type 'void' is not contextually convertible to 'bool'}}
+  {}
+
+  #pragma omp taskloop replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp taskloop'}}
+  for (int i = 0; i < 10; ++i)
+    {}
+
+  #pragma omp taskwait replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp taskwait'}}
+
+  #pragma omp target replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target'}}
+  {}
+
+  #pragma omp target enter data map(to: A) replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target enter data'}}
+
+  #pragma omp target exit data map(from: A) replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target exit data'}}
+
+  #pragma omp target update to(A) replayable(A > 0) // omp51-error {{unexpected OpenMP clause 'replayable' in directive '#pragma omp target update'}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/194054


More information about the llvm-branch-commits mailing list