Skip to content

Commit

Permalink
Reapply "[tsan] Don't use enum __tsan_memory_order in tsan interfac…
Browse files Browse the repository at this point in the history
…e"" (#115034)

In C++ it's UB to use undeclared values as enum.
And there is support __ATOMIC_HLE_ACQUIRE and
__ATOMIC_HLE_RELEASE need such values.

So use `int` in TSAN interface, and mask out
irrelevant bits and cast to enum ASAP.

`ThreadSanitizer.cpp` already declare morder parameterd
in these functions as `i32`.

This may looks like a slight change, as we
previously didn't mask out additional bits for `fmo`,
and `NoTsanAtomic` call. But from implementation
it's clear that they are expecting exact enum.


Reverts #115032
Reapply #114724
  • Loading branch information
vitalybuka authored Nov 5, 2024
1 parent 803f957 commit 17d9565
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 286 deletions.
169 changes: 82 additions & 87 deletions compiler-rt/include/sanitizer/tsan_interface_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,183 +43,178 @@ typedef enum {
} __tsan_memory_order;

__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_load(const volatile __tsan_atomic8 *a, __tsan_memory_order mo);
__tsan_atomic8_load(const volatile __tsan_atomic8 *a, int mo);
__tsan_atomic16 SANITIZER_CDECL
__tsan_atomic16_load(const volatile __tsan_atomic16 *a, __tsan_memory_order mo);
__tsan_atomic16_load(const volatile __tsan_atomic16 *a, int mo);
__tsan_atomic32 SANITIZER_CDECL
__tsan_atomic32_load(const volatile __tsan_atomic32 *a, __tsan_memory_order mo);
__tsan_atomic32_load(const volatile __tsan_atomic32 *a, int mo);
__tsan_atomic64 SANITIZER_CDECL
__tsan_atomic64_load(const volatile __tsan_atomic64 *a, __tsan_memory_order mo);
__tsan_atomic64_load(const volatile __tsan_atomic64 *a, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_load(
const volatile __tsan_atomic128 *a, __tsan_memory_order mo);
__tsan_atomic128 SANITIZER_CDECL
__tsan_atomic128_load(const volatile __tsan_atomic128 *a, int mo);
#endif

void SANITIZER_CDECL __tsan_atomic8_store(volatile __tsan_atomic8 *a,
__tsan_atomic8 v,
__tsan_memory_order mo);
__tsan_atomic8 v, int mo);
void SANITIZER_CDECL __tsan_atomic16_store(volatile __tsan_atomic16 *a,
__tsan_atomic16 v,
__tsan_memory_order mo);
__tsan_atomic16 v, int mo);
void SANITIZER_CDECL __tsan_atomic32_store(volatile __tsan_atomic32 *a,
__tsan_atomic32 v,
__tsan_memory_order mo);
__tsan_atomic32 v, int mo);
void SANITIZER_CDECL __tsan_atomic64_store(volatile __tsan_atomic64 *a,
__tsan_atomic64 v,
__tsan_memory_order mo);
__tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
void SANITIZER_CDECL __tsan_atomic128_store(volatile __tsan_atomic128 *a,
__tsan_atomic128 v,
__tsan_memory_order mo);
__tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_exchange(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_exchange(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_exchange(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_exchange(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_exchange(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_exchange(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_add(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_add(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_add(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_add(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_add(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_add(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_sub(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_sub(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_sub(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_sub(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_sub(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_sub(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_and(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_and(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_and(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_and(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_and(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_and(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_or(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_or(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_or(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_or(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_or(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_or(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_xor(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_xor(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_xor(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_xor(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_xor(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_xor(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_fetch_nand(
volatile __tsan_atomic8 *a, __tsan_atomic8 v, __tsan_memory_order mo);
__tsan_atomic8 SANITIZER_CDECL
__tsan_atomic8_fetch_nand(volatile __tsan_atomic8 *a, __tsan_atomic8 v, int mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_fetch_nand(
volatile __tsan_atomic16 *a, __tsan_atomic16 v, __tsan_memory_order mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 v, int mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_fetch_nand(
volatile __tsan_atomic32 *a, __tsan_atomic32 v, __tsan_memory_order mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 v, int mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_fetch_nand(
volatile __tsan_atomic64 *a, __tsan_atomic64 v, __tsan_memory_order mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 v, int mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_fetch_nand(
volatile __tsan_atomic128 *a, __tsan_atomic128 v, __tsan_memory_order mo);
volatile __tsan_atomic128 *a, __tsan_atomic128 v, int mo);
#endif

int SANITIZER_CDECL __tsan_atomic8_compare_exchange_weak(
volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic16_compare_exchange_weak(
volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic32_compare_exchange_weak(
volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic64_compare_exchange_weak(
volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v, int mo,
int fail_mo);
#if __TSAN_HAS_INT128
int SANITIZER_CDECL __tsan_atomic128_compare_exchange_weak(
volatile __tsan_atomic128 *a, __tsan_atomic128 *c, __tsan_atomic128 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
int mo, int fail_mo);
#endif

int SANITIZER_CDECL __tsan_atomic8_compare_exchange_strong(
volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic8 *a, __tsan_atomic8 *c, __tsan_atomic8 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic16_compare_exchange_strong(
volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 *c, __tsan_atomic16 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic32_compare_exchange_strong(
volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 *c, __tsan_atomic32 v, int mo,
int fail_mo);
int SANITIZER_CDECL __tsan_atomic64_compare_exchange_strong(
volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 *c, __tsan_atomic64 v, int mo,
int fail_mo);
#if __TSAN_HAS_INT128
int SANITIZER_CDECL __tsan_atomic128_compare_exchange_strong(
volatile __tsan_atomic128 *a, __tsan_atomic128 *c, __tsan_atomic128 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
int mo, int fail_mo);
#endif

__tsan_atomic8 SANITIZER_CDECL __tsan_atomic8_compare_exchange_val(
volatile __tsan_atomic8 *a, __tsan_atomic8 c, __tsan_atomic8 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic8 *a, __tsan_atomic8 c, __tsan_atomic8 v, int mo,
int fail_mo);
__tsan_atomic16 SANITIZER_CDECL __tsan_atomic16_compare_exchange_val(
volatile __tsan_atomic16 *a, __tsan_atomic16 c, __tsan_atomic16 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic16 *a, __tsan_atomic16 c, __tsan_atomic16 v, int mo,
int fail_mo);
__tsan_atomic32 SANITIZER_CDECL __tsan_atomic32_compare_exchange_val(
volatile __tsan_atomic32 *a, __tsan_atomic32 c, __tsan_atomic32 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic32 *a, __tsan_atomic32 c, __tsan_atomic32 v, int mo,
int fail_mo);
__tsan_atomic64 SANITIZER_CDECL __tsan_atomic64_compare_exchange_val(
volatile __tsan_atomic64 *a, __tsan_atomic64 c, __tsan_atomic64 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
volatile __tsan_atomic64 *a, __tsan_atomic64 c, __tsan_atomic64 v, int mo,
int fail_mo);
#if __TSAN_HAS_INT128
__tsan_atomic128 SANITIZER_CDECL __tsan_atomic128_compare_exchange_val(
volatile __tsan_atomic128 *a, __tsan_atomic128 c, __tsan_atomic128 v,
__tsan_memory_order mo, __tsan_memory_order fail_mo);
int mo, int fail_mo);
#endif

void SANITIZER_CDECL __tsan_atomic_thread_fence(__tsan_memory_order mo);
void SANITIZER_CDECL __tsan_atomic_signal_fence(__tsan_memory_order mo);
void SANITIZER_CDECL __tsan_atomic_thread_fence(int mo);
void SANITIZER_CDECL __tsan_atomic_signal_fence(int mo);

#ifdef __cplusplus
} // extern "C"
Expand Down
Loading

0 comments on commit 17d9565

Please sign in to comment.