Skip to content

Commit b6bcf72

Browse files
committed
[OPENMP50]Mark expression in detach clause as firstprivate.
According to the standard, The event-handle will be considered as if it was specified on a firstprivate clause.
1 parent 9836917 commit b6bcf72

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4729,6 +4729,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
47294729
if (E)
47304730
ImplicitFirstprivates.emplace_back(E);
47314731
}
4732+
// OpenMP 5.0, 2.10.1 task Construct
4733+
// [detach clause]... The event-handle will be considered as if it was
4734+
// specified on a firstprivate clause.
4735+
if (auto *DC = dyn_cast<OMPDetachClause>(C))
4736+
ImplicitFirstprivates.push_back(DC->getEventHandler());
47324737
}
47334738
if (!ImplicitFirstprivates.empty()) {
47344739
if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause(
@@ -13432,7 +13437,8 @@ OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
1343213437
ExprCaptures.push_back(Ref->getDecl());
1343313438
}
1343413439
}
13435-
DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref);
13440+
if (!IsImplicitClause)
13441+
DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref);
1343613442
Vars.push_back((VD || CurContext->isDependentContext())
1343713443
? RefExpr->IgnoreParens()
1343813444
: Ref);
@@ -17354,6 +17360,18 @@ OMPClause *Sema::ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc,
1735417360
<< 1 << VD->getType() << Evt->getSourceRange();
1735517361
return nullptr;
1735617362
}
17363+
// OpenMP 5.0, 2.10.1 task Construct
17364+
// [detach clause]... The event-handle will be considered as if it was
17365+
// specified on a firstprivate clause.
17366+
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, /*FromParent=*/false);
17367+
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate &&
17368+
DVar.RefExpr) {
17369+
Diag(Evt->getExprLoc(), diag::err_omp_wrong_dsa)
17370+
<< getOpenMPClauseName(DVar.CKind)
17371+
<< getOpenMPClauseName(OMPC_firstprivate);
17372+
reportOriginalDsa(*this, DSAStack, VD, DVar);
17373+
return nullptr;
17374+
}
1735717375
}
1735817376

1735917377
return new (Context) OMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);

clang/test/AST/ast-dump-openmp-task.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -ast-dump %s | FileCheck --match-full-lines -implicit-check-not=openmp_structured_block %s
1+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=50 -ast-dump %s | FileCheck --match-full-lines -implicit-check-not=openmp_structured_block %s
22

3+
typedef unsigned long omp_event_handle_t;
34
void test() {
4-
#pragma omp task
5+
omp_event_handle_t evt;
6+
#pragma omp task detach(evt)
57
;
68
}
79

810
// CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc>
9-
// CHECK: `-FunctionDecl {{.*}} <{{.*}}ast-dump-openmp-task.c:3:1, line:6:1> line:3:6 test 'void ()'
10-
// CHECK-NEXT: `-CompoundStmt {{.*}} <col:13, line:6:1>
11-
// CHECK-NEXT: `-OMPTaskDirective {{.*}} <line:4:1, col:17>
12-
// CHECK-NEXT: `-CapturedStmt {{.*}} <line:5:3>
11+
// CHECK: `-FunctionDecl {{.*}} <line:4:1, line:8:1> line:4:6 test 'void ()'
12+
// CHECK-NEXT: `-CompoundStmt {{.*}} <col:13, line:8:1>
13+
// CHECK: `-OMPTaskDirective {{.*}} <line:6:1, col:29>
14+
// CHECK-NEXT: |-OMPDetachClause {{.+}} <col:18, col:28>
15+
// CHECK-NEXT: | `-DeclRefExpr {{.+}} <col:25> 'omp_event_handle_t':'unsigned long' lvalue Var {{.+}} 'evt' 'omp_event_handle_t':'unsigned long'
16+
// CHECK-NEXT: |-OMPFirstprivateClause {{.+}} <<invalid sloc>> <implicit>
17+
// CHECK-NEXT: | `-DeclRefExpr {{.+}} <col:25> 'omp_event_handle_t':'unsigned long' lvalue Var {{.+}} 'evt' 'omp_event_handle_t':'unsigned long'
18+
// CHECK-NEXT: `-CapturedStmt {{.*}} <line:7:3>
1319
// CHECK-NEXT: `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
1420
// CHECK-NEXT: |-NullStmt {{.*}} <col:3>
1521
// CHECK-NEXT: |-AlwaysInlineAttr {{.*}} <<invalid sloc>> Implicit __forceinline
16-
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int'
22+
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:6:1> col:1 implicit .global_tid. 'const int'
1723
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .part_id. 'const int *const restrict'
1824
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .privates. 'void *const restrict'
1925
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .copy_fn. 'void (*const restrict)(void *const restrict, ...)'
2026
// CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .task_t. 'void *const'
21-
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-task.c:4:1) *const restrict'
27+
// CHECK-NEXT: `-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-task.c:6:1) *const restrict'

clang/test/OpenMP/task_messages.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
2-
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
1+
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized
2+
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized
33

4-
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
5-
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
4+
// RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized
5+
// RUN: %clang_cc1 -verify=expected,omp50 -fopenmp-version=50 -fopenmp-simd -ferror-limit 200 -std=c++11 -o - %s -Wuninitialized
66

77
void xxx(int argc) {
88
int x; // expected-note {{initialize the variable 'x' to silence this warning}}
@@ -147,6 +147,9 @@ int foo() {
147147
#pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'mergeable' clause is specified here}}
148148
#pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type}}
149149
;
150+
#pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}
151+
#pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}
152+
;
150153
return a + b;
151154
}
152155

@@ -327,6 +330,9 @@ int main(int argc, char **argv) {
327330
#pragma omp task mergeable detach(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{'detach' and 'mergeable' clause are mutually exclusive and may not appear on the same directive}} omp50-note {{'mergeable' clause is specified here}}
328331
#pragma omp task detach(-evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}} omp50-error {{expected variable of the 'omp_event_handle_t' type}}
329332
;
333+
#pragma omp task detach(evt) shared(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}
334+
#pragma omp task detach(evt) firstprivate(evt) // omp45-error {{unexpected OpenMP clause 'detach' in directive '#pragma omp task'}}
335+
;
330336
// expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
331337
// expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
332338
return foo<int>() + foo<S>();

0 commit comments

Comments
 (0)