[sanitizer] Use __atomic_load/store() built-ins for generic 32-bit targets

Simplifies the code and fixes the build on SPARC.
See discussion in: http://lists.llvm.org/pipermail/llvm-dev/2020-October/145937.html

Author: glaubitz (John Paul Adrian Glaubitz)
Reviewed-in: https://reviews.llvm.org/D89940
This commit is contained in:
Dmitry Vyukov 2020-10-30 09:17:46 +01:00
parent b4916918e5
commit 26c1ced41c
1 changed files with 3 additions and 15 deletions

View File

@ -50,11 +50,8 @@ inline typename T::Type atomic_load(
__sync_synchronize();
}
} else {
// 64-bit load on 32-bit platform.
// Gross, but simple and reliable.
// Assume that it is not in read-only memory.
v = __sync_fetch_and_add(
const_cast<typename T::Type volatile *>(&a->val_dont_use), 0);
__atomic_load(const_cast<typename T::Type volatile *>(&a->val_dont_use), &v,
__ATOMIC_SEQ_CST);
}
return v;
}
@ -79,16 +76,7 @@ inline void atomic_store(volatile T *a, typename T::Type v, memory_order mo) {
__sync_synchronize();
}
} else {
// 64-bit store on 32-bit platform.
// Gross, but simple and reliable.
typename T::Type cmp = a->val_dont_use;
typename T::Type cur;
for (;;) {
cur = __sync_val_compare_and_swap(&a->val_dont_use, cmp, v);
if (cur == cmp || cur == v)
break;
cmp = cur;
}
__atomic_store(&a->val_dont_use, &v, __ATOMIC_SEQ_CST);
}
}