From: Alexey Bataev Date: Wed, 20 Jan 2016 12:29:47 +0000 (+0000) Subject: [OPENMP 4.0] Fix for codegen of 'cancel' directive within 'sections' directive. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26598eecd5cb20b931227626744a7bb5de6b4496;p=clang [OPENMP 4.0] Fix for codegen of 'cancel' directive within 'sections' directive. Allow to emit code for 'cancel' directive within 'sections' directive with single sub-section. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258307 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 3b97ba2469..6d82f4bd7e 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3685,8 +3685,6 @@ void CGOpenMPRuntime::emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, // kmp_int32 cncl_kind); if (auto *OMPRegionInfo = dyn_cast_or_null(CGF.CapturedStmtInfo)) { - if (OMPRegionInfo->getDirectiveKind() == OMPD_single) - return; auto &&ThenGen = [this, Loc, CancelRegion, OMPRegionInfo](CodeGenFunction &CGF) { llvm::Value *Args[] = { diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index 793e1a9731..1507f84aee 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -1786,7 +1786,11 @@ CodeGenFunction::EmitSections(const OMPExecutableDirective &S) { CGF.EmitOMPPrivateClause(S, SingleScope); (void)SingleScope.Privatize(); + auto Exit = CGF.getJumpDestInCurrentScope("omp.sections.exit"); + CGF.BreakContinueStack.push_back(BreakContinue(Exit, Exit)); CGF.EmitStmt(Stmt); + CGF.EmitBlock(Exit.getBlock()); + CGF.BreakContinueStack.pop_back(); }; CGM.getOpenMPRuntime().emitSingleRegion(*this, CodeGen, S.getLocStart(), llvm::None, llvm::None, llvm::None, @@ -2647,7 +2651,8 @@ CodeGenFunction::getOMPCancelDestination(OpenMPDirectiveKind Kind) { if (Kind == OMPD_parallel || Kind == OMPD_task) return ReturnBlock; assert(Kind == OMPD_for || Kind == OMPD_section || Kind == OMPD_sections || - Kind == OMPD_parallel_sections || Kind == OMPD_parallel_for); + Kind == OMPD_parallel_sections || Kind == OMPD_parallel_for || + Kind == OMPD_single); return BreakContinueStack.back().BreakBlock; } diff --git a/test/OpenMP/cancel_codegen.cpp b/test/OpenMP/cancel_codegen.cpp index e2dd3673ca..ac72866c88 100644 --- a/test/OpenMP/cancel_codegen.cpp +++ b/test/OpenMP/cancel_codegen.cpp @@ -20,7 +20,7 @@ int main (int argc, char **argv) { #pragma omp cancel sections } // CHECK: call i32 @__kmpc_single( -// CHECK-NOT: @__kmpc_cancel +// CHECK: call i32 @__kmpc_cancel( // CHECK: call void @__kmpc_end_single( // CHECK: call void @__kmpc_barrier(%ident_t* #pragma omp sections @@ -126,7 +126,7 @@ for (int i = 0; i < argc; ++i) { // CHECK: define internal void @{{[^(]+}}(i32* {{[^,]+}}, i32* {{[^,]+}}) // CHECK: call i32 @__kmpc_single( -// CHECK-NOT: @__kmpc_cancel +// CHECK: call i32 @__kmpc_cancel( // CHECK: call void @__kmpc_end_single( // CHECK: ret void