From: Alexey Bataev Date: Wed, 15 Jun 2016 11:20:48 +0000 (+0000) Subject: [OPENMP] Fix crash for 'schedule|dist_schedule' clauses during X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32c03b723d04144ec6ac6d7c873ceb6c3749d57b;p=clang [OPENMP] Fix crash for 'schedule|dist_schedule' clauses during instantiation. Added checks for non-dependent context when trygin to capture non-constant schedule chunk expression for proper codegen of outlined functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272775 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 36ad9e80e3..291b9fa018 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -7341,7 +7341,8 @@ OMPClause *Sema::ActOnOpenMPScheduleClause( << "schedule" << 1 << ChunkSize->getSourceRange(); return nullptr; } - } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { + } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && + !CurContext->isDependentContext()) { llvm::MapVector Captures; ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); HelperValStmt = buildPreInits(Context, Captures); @@ -10877,7 +10878,8 @@ OMPClause *Sema::ActOnOpenMPDistScheduleClause( << "dist_schedule" << ChunkSize->getSourceRange(); return nullptr; } - } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { + } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && + !CurContext->isDependentContext()) { llvm::MapVector Captures; ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); HelperValStmt = buildPreInits(Context, Captures); diff --git a/test/OpenMP/distribute_codegen.cpp b/test/OpenMP/distribute_codegen.cpp index f15a62c59b..23a5e14b94 100644 --- a/test/OpenMP/distribute_codegen.cpp +++ b/test/OpenMP/distribute_codegen.cpp @@ -238,4 +238,26 @@ void test_precond() { // no templates for now, as these require special handling in target regions and/or declare target +// HCHECK-LABEL: fint +// HCHECK: call {{.*}}i32 {{.+}}ftemplate +// HCHECK: ret i32 + +// HCHECK: load i16, i16* +// HCHECK: store i16 % +// HCHECK: call i32 @__tgt_target_teams( +// HCHECK: call void @__kmpc_for_static_init_4( +template +T ftemplate() { + short aa = 0; + +#pragma omp target +#pragma omp teams +#pragma omp distribute dist_schedule(static, aa) + for (int i = 0; i < 100; i++) { + } + return T(); +} + +int fint(void) { return ftemplate(); } + #endif diff --git a/test/OpenMP/for_codegen.cpp b/test/OpenMP/for_codegen.cpp index 39fd63fea7..1d24403a09 100644 --- a/test/OpenMP/for_codegen.cpp +++ b/test/OpenMP/for_codegen.cpp @@ -492,4 +492,25 @@ void loop_with_stmt_expr() { // CHECK: call void @__kmpc_for_static_init_4( // CHECK: call void @__kmpc_for_static_fini( + +// CHECK-LABEL: fint +// CHECK: call {{.*}}i32 {{.*}}ftemplate +// CHECK: ret i32 + +// CHECK: load i16, i16* +// CHECK: store i16 % +// CHECK: call void {{.+}}@__kmpc_fork_call( +// CHECK: call void @__kmpc_for_static_init_4( +template +T ftemplate() { + short aa = 0; + +#pragma omp parallel for schedule(static, aa) + for (int i = 0; i < 100; i++) { + } + return T(); +} + +int fint(void) { return ftemplate(); } + #endif // HEADER