[compiler-rt] [nfc][tsan] Simplify morder conversion (PR #115075)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 13:50:25 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

All valid values should fit into a byte.
This slightly reduce generated code on x86_64.


---
Full diff: https://github.com/llvm/llvm-project/pull/115075.diff


1 Files Affected:

- (modified) compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp (+3-1) 


``````````diff
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp b/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
index d12e0f596a7fb4..dd37e86ebd7583 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
@@ -515,7 +515,9 @@ static morder to_morder(int mo) {
   // since we use __sync_ atomics for actual atomic operations,
   // we can safely ignore it as well. It also subtly affects semantics,
   // but we don't model the difference.
-  return static_cast<morder>(mo & 0x7fff);
+  morder res = static_cast<morder>(static_cast<u8>(mo));
+  DCHECK_LE(res, mo_seq_cst);
+  return res;
 }
 
 #  define ATOMIC_IMPL(func, mo, ...)                                  \

``````````

</details>


https://github.com/llvm/llvm-project/pull/115075


More information about the llvm-commits mailing list