Skip to content

Commit

Permalink
[CGCilk] Fix code generation of unreachable _Cilk_sync statements. Fi…
Browse files Browse the repository at this point in the history
…xes issue llvm#93.
  • Loading branch information
neboat authored and tarunprabhu committed Oct 12, 2023
1 parent 8cc6a33 commit 1fb6c50
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions clang/lib/CodeGen/CGCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,13 @@ llvm::Instruction *CodeGenFunction::EmitSyncRegionStart() {
void CodeGenFunction::EmitCilkSyncStmt(const CilkSyncStmt &S) {
llvm::BasicBlock *ContinueBlock = createBasicBlock("sync.continue");

// If this code is reachable then emit a stop point (if generating
// debug info). We have to do this ourselves because we are on the
// "simple" statement path.
if (HaveInsertPoint())
EmitStopPoint(&S);
// Check if we are generating unreachable code.
if (!HaveInsertPoint())
// We don't need to generate actual code.
return;

// Generate a stoppoint if we are emitting debug info.
EmitStopPoint(&S);

EnsureSyncRegion();

Expand Down
18 changes: 18 additions & 0 deletions clang/test/Cilk/unreachable-sync.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Check that a sync is not inserted when clang recognizes that it is not reachable.
//
// RUN: %clang_cc1 -fopencilk -ftapir=none -triple x86_64-unknown-linux-gnu -std=c++11 -emit-llvm %s -o - | FileCheck %s
int create() {
return 1;
_Cilk_sync;
}

// CHECK: define dso_local {{.*}}i32 @_Z6createv()
// CHECK: {
// CHECK: ret i32 1
// CHECK-NOT: sync
// CHECK: }

int main([[maybe_unused]] int argc, char *argv[]) {
int e = create();
return 0;
}

0 comments on commit 1fb6c50

Please sign in to comment.