[OPENMP]Fix PR39422: variables are not firstprivatized in task context.
According to the OpenMP standard, In a task generating construct, if no
default clause is present, a variable for which the data-sharing
attribute is not determined by the rules above is firstprivatized.
Compiler tries to implement this, but if the variable is not directly
used in the task context, this variable may not be firstprivatized.
Patch fixes this problem.
llvm-svn: 345277
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 7b4cc9f..92d1514 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2251,8 +2251,31 @@
}
void VisitStmt(Stmt *S) {
for (Stmt *C : S->children()) {
- if (C && !isa<OMPExecutableDirective>(C))
- Visit(C);
+ if (C) {
+ if (auto *OED = dyn_cast<OMPExecutableDirective>(C)) {
+ // Check implicitly captured vriables in the task-based directives to
+ // check if they must be firstprivatized.
+ if (!OED->hasAssociatedStmt())
+ continue;
+ const Stmt *AS = OED->getAssociatedStmt();
+ if (!AS)
+ continue;
+ for (const CapturedStmt::Capture &Cap :
+ cast<CapturedStmt>(AS)->captures()) {
+ if (Cap.capturesVariable()) {
+ DeclRefExpr *DRE = buildDeclRefExpr(
+ SemaRef, Cap.getCapturedVar(),
+ Cap.getCapturedVar()->getType().getNonLValueExprType(
+ SemaRef.Context),
+ Cap.getLocation(),
+ /*RefersToCapture=*/true);
+ Visit(DRE);
+ }
+ }
+ } else {
+ Visit(C);
+ }
+ }
}
}