Skip to content

Commit

Permalink
[cilksan] Add hook for LLVM intrinsic for x86 pause instruction. Fix …
Browse files Browse the repository at this point in the history
  • Loading branch information
neboat committed Aug 29, 2022
1 parent f0f5e9f commit 0928dd4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cilksan/libhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ CILKSAN_API void __csan_llvm_x86_avx2_gather_d_pd_256(
call_id, MAAP_count, prop, result, vbase, base, index, mask, scale);
}

CILKSAN_API void __csan_llvm_x86_sse2_pause(const csi_id_t call_id,
const csi_id_t func_id,
unsigned MAAP_count,
const call_prop_t prop) {
// Nothing to do to check a pause instruction.
return;
}

CILKSAN_API void __csan_llvm_stacksave(const csi_id_t call_id,
const csi_id_t func_id,
unsigned MAAP_count,
Expand Down
32 changes: 32 additions & 0 deletions test/cilksan/TestCases/intrinsics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %clang_cilksan -fopencilk -O0 %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s

#include <cilk/cilk.h>
#include <stdio.h>

_Atomic int x = 0;

void foo(void) {
while (!x) {
#ifdef __SSE__
__builtin_ia32_pause();
#endif
#ifdef __aarch64__
__builtin_arm_yield();
#endif
}
++x;
}

int main(int argc, char *argv[]) {
cilk_spawn { ++x; }
foo();
cilk_sync;
printf("x=%d\n", x);
return 0;
}

// CHECK: Running Cilksan race detector
// CHECK-NEXT: x=2
// CHECK: Cilksan detected 0 distinct races.
// CHECK-NEXT: Cilksan suppressed 0 duplicate race reports.

0 comments on commit 0928dd4

Please sign in to comment.