Skip to content

Commit 4360b4c

Browse files
committed
Sync before exiting a cilk_scope with a non-compound statement body.
1 parent 0849cc6 commit 4360b4c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

clang/lib/CodeGen/CGCilk.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ void CodeGenFunction::EmitCilkSyncStmt(const CilkSyncStmt &S) {
456456
void CodeGenFunction::EmitCilkScopeStmt(const CilkScopeStmt &S) {
457457
LexicalScope CilkScope(*this, S.getSourceRange());
458458

459-
// If this _Cilk_scope is outermost in the function, emit
459+
// If this cilk_scope is outermost in the function, emit
460460
// tapir_runtime_{start,end} intrinsics around the scope.
461461
bool ThisScopeIsOutermost = false;
462462
if (!WithinCilkScope) {
@@ -465,13 +465,14 @@ void CodeGenFunction::EmitCilkScopeStmt(const CilkScopeStmt &S) {
465465
}
466466

467467
{
468+
ScopeIsSynced = true;
468469
// Add a taskframe around this scope in case there are other spawns outside
469470
// of this scope, which would need to be synced separately.
470471
TaskFrameScope TFScope(*this);
471472
if (ThisScopeIsOutermost && !CurSyncRegion) {
472473
llvm::Instruction *TapirRTStart = Builder.CreateCall(
473474
CGM.getIntrinsic(llvm::Intrinsic::tapir_runtime_start));
474-
// Mark the end of the _Cilk_scope with tapir_runtime_end.
475+
// Mark the end of the cilk_scope with tapir_runtime_end.
475476
EHStack.pushCleanup<TapirRuntimeEndCleanup>(NormalAndEHCleanup,
476477
TapirRTStart);
477478
}
@@ -485,8 +486,8 @@ void CodeGenFunction::EmitCilkScopeStmt(const CilkScopeStmt &S) {
485486
EmitStmt(S.getBody());
486487
}
487488

488-
// If this _Cilk_scope is outermost in the function, mark that CodeGen is no
489-
// longer emitting within a _Cilk_scope.
489+
// If this cilk_scope is outermost in the function, mark that CodeGen is no
490+
// longer emitting within a cilk_scope.
490491
if (ThisScopeIsOutermost)
491492
WithinCilkScope = false;
492493
}

clang/test/Cilk/double-scope.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -emit-llvm -fopencilk -mllvm -use-opencilk-runtime-bc=false -mllvm -debug-abi-calls -O0 -x c %s -o /dev/null
2+
// RUN: %clang_cc1 -emit-llvm -fopencilk -mllvm -use-opencilk-runtime-bc=false -mllvm -debug-abi-calls -O1 -x c %s -o /dev/null
3+
// If the compiler doesn't crash the bug is fixed.
4+
5+
void ccc()
6+
{
7+
extern void ddd(void);
8+
cilk_scope { cilk_scope cilk_spawn { ddd(); } }
9+
}

clang/test/Cilk/scope.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -emit-llvm -fopencilk -disable-llvm-passes -O1 -x c %s -o - | FileCheck %s
2+
3+
extern void bbb(void);
4+
5+
// CHECK-LABEL: @aaa
6+
int aaa(int argc, char *argv[])
7+
{
8+
// CHECK: call token @llvm.tapir.runtime.start()
9+
cilk_scope
10+
for (int i = 0; i < argc; ++i)
11+
// CHECK: detach within
12+
// CHECK: call void @bbb
13+
// CHECK-NEXT: reattach within
14+
// sync must precede runtime end
15+
// CHECK: sync within
16+
// CHECK: call void @llvm.tapir.runtime.end
17+
cilk_spawn { bbb(); }
18+
return 0;
19+
}

0 commit comments

Comments
 (0)