Skip to content

Commit 39d6529

Browse files
dvyukovmemfrob
authored andcommitted
[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
1 parent 7650c1d commit 39d6529

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang_other.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ inline typename T::Type atomic_load(
5050
__sync_synchronize();
5151
}
5252
} else {
53-
// 64-bit load on 32-bit platform.
54-
// Gross, but simple and reliable.
55-
// Assume that it is not in read-only memory.
56-
v = __sync_fetch_and_add(
57-
const_cast<typename T::Type volatile *>(&a->val_dont_use), 0);
53+
__atomic_load(const_cast<typename T::Type volatile *>(&a->val_dont_use), &v,
54+
__ATOMIC_SEQ_CST);
5855
}
5956
return v;
6057
}
@@ -79,16 +76,7 @@ inline void atomic_store(volatile T *a, typename T::Type v, memory_order mo) {
7976
__sync_synchronize();
8077
}
8178
} else {
82-
// 64-bit store on 32-bit platform.
83-
// Gross, but simple and reliable.
84-
typename T::Type cmp = a->val_dont_use;
85-
typename T::Type cur;
86-
for (;;) {
87-
cur = __sync_val_compare_and_swap(&a->val_dont_use, cmp, v);
88-
if (cur == cmp || cur == v)
89-
break;
90-
cmp = cur;
91-
}
79+
__atomic_store(&a->val_dont_use, &v, __ATOMIC_SEQ_CST);
9280
}
9381
}
9482

0 commit comments

Comments
 (0)