[clang] WIP: Metadirective uses default for non-const user condition (PR #86457)
Robin Caloudis via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 24 14:15:53 PDT 2024
https://github.com/robincaloudis created https://github.com/llvm/llvm-project/pull/86457
As reported in https://github.com/llvm/llvm-project/issues/82754, Metadirectives uses default for non-const user condition. This is unexpected as the OpenMP specification 5.1 allows dynamic `condition` selector within Metadirectives. In contrast static `condition` selector work.
### Example:
```c++
int non_const_val = 1; // A non const value makes the `condition` selector dynamic; a const value makes it static
#pragma omp metadirective \
when( user= {condition(non_const_val > 0)} : parallel num_threads( num_threads ) ) \
default()
{
#pragma omp single
assert( num_threads == omp_get_num_threads() );
}
```
where as `user` is called _selector set_ and `condition` is called _selector_ (must evaluate to true for the selector to be true).
## Background informations
### As of OpenMP 5.1, dynamic `condition` selectors seem to be allowed
"[...] Any non-constant expression that is evaluated to determine the suitability of a variant is evaluated according to the data state trait in the dynamic trait set of the OpenMP context. The user selector set is dynamic if the _condition selector_ is present and the expression in the condition selector is not a constant expression; otherwise, it is static. [...]"
### Assembled grammar (copied from OpenMP 5.1. specification on [Metadirectives](https://www.openmp.org/spec-html/5.1/openmpsu28.html#x45-440002.3.4) and [Context Selectors](https://www.openmp.org/spec-html/5.1/openmpsu26.html#x43-420002.3.2)):
There is a change that wrong semantics (meaning) are attached against the `trait-selector` when it is a dynamic condition selector
```c++
#pragma omp metadirective [clause[ [,] clause] ... ] new-line
// where clause is one of the following:
when(context-selector-specification: [directive-variant])
default([directive-variant])
// where context-selector-specification is
context-selector-specification:
trait-set-selector[,trait-set-selector[,...]]
// where trait-set-selector is
trait-set-selector:
trait-set-selector-name={trait-selector[, trait-selector[, ...]]}
```
Specification of [Metadirectives](https://www.openmp.org/spec-html/5.1/openmpsu26.html#x43-420002.3.2) in OpenMP 5.1
Issue: https://github.com/llvm/llvm-project/issues/82754
>From bc962815d5587ffb16a178b4b766ffe36ee1c8a0 Mon Sep 17 00:00:00 2001
From: Robin Caloudis <robin.caloudis at gmx.de>
Date: Sun, 24 Mar 2024 21:37:33 +0100
Subject: [PATCH] Reproduce reported issue
---
clang/test/OpenMP/metadirective_ast_print.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/test/OpenMP/metadirective_ast_print.c b/clang/test/OpenMP/metadirective_ast_print.c
index d9ff7e76452160..afc150610f197b 100644
--- a/clang/test/OpenMP/metadirective_ast_print.c
+++ b/clang/test/OpenMP/metadirective_ast_print.c
@@ -77,6 +77,11 @@ void foo(void) {
: parallel) default(nothing)
for (int i = 0; i < 16; i++)
;
+
+ int non_const_val = 1;
+#pragma omp metadirective when(user = {condition(non_const_val > 0)} \
+ : parallel) default(nothing)
+ bar();
}
// CHECK: void bar(void);
@@ -107,5 +112,8 @@ void foo(void) {
// CHECK-AMDGCN-NEXT: for (int i = 0; i < 100; i++)
// CHECK: for (int i = 0; i < 16; i++)
// CHECK: for (int i = 0; i < 16; i++)
+// CHECK: int non_const_val = 1;
+// CHECK-NEXT: #pragma omp parallel
+// CHECK-NEXT: bar()
#endif
More information about the cfe-commits
mailing list