]> granicus.if.org Git - clang/commitdiff
[OPENMP 4.0] Fix for codegen of 'cancel' directive within 'sections' directive.
authorAlexey Bataev <a.bataev@hotmail.com>
Wed, 20 Jan 2016 12:29:47 +0000 (12:29 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Wed, 20 Jan 2016 12:29:47 +0000 (12:29 +0000)
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

lib/CodeGen/CGOpenMPRuntime.cpp
lib/CodeGen/CGStmtOpenMP.cpp
test/OpenMP/cancel_codegen.cpp

index 3b97ba2469ae1967fba9fcbb0d753b3da351ffa7..6d82f4bd7e231be2f8b4500c0f6be279600f729e 100644 (file)
@@ -3685,8 +3685,6 @@ void CGOpenMPRuntime::emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc,
   // kmp_int32 cncl_kind);
   if (auto *OMPRegionInfo =
           dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo)) {
-    if (OMPRegionInfo->getDirectiveKind() == OMPD_single)
-      return;
     auto &&ThenGen = [this, Loc, CancelRegion,
                       OMPRegionInfo](CodeGenFunction &CGF) {
       llvm::Value *Args[] = {
index 793e1a97314802f4c29402bf7d430c2c9f138188..1507f84aeee97ecf7b394a6713fff5313b6dd59d 100644 (file)
@@ -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;
 }
 
index e2dd3673caff389c46f0868f51ece19002a4c422..ac72866c880293866f3c488ff044e49c5cbd83b1 100644 (file)
@@ -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