ABataev added a comment. The fixed patch. Several codegen tests require some adjustment.
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index afe0f1a..ecb0fb2 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -919,6 +919,11 @@ static const Expr *getExprAsWritten(const Expr *E) { if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) E = ICE->getSubExprAsWritten(); + + if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) + if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) + E = getExprAsWritten(CED->getInit()); + return E->IgnoreParens(); } @@ -3830,6 +3835,9 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, MarkDeclarationsReferencedInExpr(E); } } + if (auto *LC = dyn_cast<OMPLinearClause>(Clause)) + if (Expr *E = LC->getStep()) + MarkDeclarationsReferencedInExpr(E); DSAStack->setForceVarCapturing(/*V=*/false); } else if (CaptureRegions.size() > 1 || CaptureRegions.back() != OMPD_unknown) { @@ -11396,12 +11404,88 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( llvm_unreachable("Unknown OpenMP directive"); } break; + case OMPC_linear: + switch (DKind) { + case OMPD_taskloop_simd: + case OMPD_master_taskloop_simd: + case OMPD_parallel_master_taskloop_simd: + CaptureRegion = OMPD_taskloop; + break; + case OMPD_target_simd: + CaptureRegion = OMPD_target; + break; + case OMPD_target_teams_distribute_simd: + case OMPD_teams_distribute_simd: + CaptureRegion = OMPD_teams; + break; + case OMPD_target_parallel_for: + case OMPD_target_parallel_for_simd: + case OMPD_target_teams_distribute_parallel_for: + case OMPD_target_teams_distribute_parallel_for_simd: + case OMPD_teams_distribute_parallel_for: + case OMPD_teams_distribute_parallel_for_simd: + case OMPD_distribute_parallel_for: + case OMPD_distribute_parallel_for_simd: + case OMPD_parallel_for: + case OMPD_parallel_for_simd: + CaptureRegion = OMPD_parallel; + break; + case OMPD_simd: + case OMPD_for: + case OMPD_for_simd: + case OMPD_distribute_simd: + break; + case OMPD_parallel_master_taskloop: + case OMPD_task: + case OMPD_taskloop: + case OMPD_master_taskloop: + case OMPD_target_update: + case OMPD_target_enter_data: + case OMPD_target_exit_data: + case OMPD_target: + case OMPD_target_teams: + case OMPD_target_parallel: + case OMPD_target_teams_distribute: + case OMPD_target_data: + case OMPD_teams: + case OMPD_teams_distribute: + case OMPD_cancel: + case OMPD_parallel: + case OMPD_parallel_master: + case OMPD_parallel_sections: + case OMPD_threadprivate: + case OMPD_allocate: + case OMPD_taskyield: + case OMPD_barrier: + case OMPD_taskwait: + case OMPD_cancellation_point: + case OMPD_flush: + case OMPD_declare_reduction: + case OMPD_declare_mapper: + case OMPD_declare_simd: + case OMPD_declare_variant: + case OMPD_declare_target: + case OMPD_end_declare_target: + case OMPD_sections: + case OMPD_section: + case OMPD_single: + case OMPD_master: + case OMPD_critical: + case OMPD_taskgroup: + case OMPD_distribute: + case OMPD_ordered: + case OMPD_atomic: + case OMPD_requires: + llvm_unreachable("Unexpected OpenMP directive with linear-clause"); + case OMPD_unknown: + llvm_unreachable("Unknown OpenMP directive"); + } + break; case OMPC_firstprivate: case OMPC_lastprivate: case OMPC_reduction: case OMPC_task_reduction: case OMPC_in_reduction: - case OMPC_linear: case OMPC_default: case OMPC_proc_bind: case OMPC_safelen: @@ -14377,6 +14461,16 @@ OMPClause *Sema::ActOnOpenMPLinearClause( if (Val.isInvalid()) return nullptr; StepExpr = Val.get(); + OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); + OpenMPDirectiveKind CaptureRegion = + getOpenMPCaptureRegionForClause(DKind, OMPC_linear, LangOpts.OpenMP); + if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { + StepExpr = MakeFullExpr(StepExpr).get(); + llvm::MapVector<const Expr *, DeclRefExpr *> Captures; + StepExpr = tryBuildCapture(*this, StepExpr, Captures).get(); + for (const auto &Pair : Captures) + ExprCaptures.push_back(Pair.second->getDecl()); + } // Build var to save the step value. VarDecl *SaveVar = @@ -14503,7 +14597,7 @@ static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, ++CurPrivate; } if (Expr *S = Clause.getStep()) - UsedExprs.push_back(S); + UsedExprs.push_back(getExprAsWritten(S)); // Fill the remaining part with the nullptr. UsedExprs.append(Clause.varlist_size() + 1 - UsedExprs.size(), nullptr); Clause.setUpdates(Updates); Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D71475/new/ https://reviews.llvm.org/D71475 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits