[libc-commits] [libc] [libc] fix 32bit atomic tests (PR #119087)
via libc-commits
libc-commits at lists.llvm.org
Sat Dec 7 10:42:21 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Schrodinger ZHU Yifan (SchrodingerZhu)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/119087.diff
1 Files Affected:
- (modified) libc/test/src/__support/CPP/atomic_test.cpp (+13-12)
``````````diff
diff --git a/libc/test/src/__support/CPP/atomic_test.cpp b/libc/test/src/__support/CPP/atomic_test.cpp
index 8772ad05f49ff7..5c3f60e9a68cd3 100644
--- a/libc/test/src/__support/CPP/atomic_test.cpp
+++ b/libc/test/src/__support/CPP/atomic_test.cpp
@@ -33,19 +33,20 @@ TEST(LlvmLibcAtomicTest, CompareExchangeStrong) {
ASSERT_EQ(aint.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED), 100);
}
-struct TrivialData {
- int a;
- int b;
+struct alignas(void *) TrivialData {
+ char a;
+ char b;
+ char padding[sizeof(void *) - 2];
};
TEST(LlvmLibcAtomicTest, TrivialCompositeData) {
- LIBC_NAMESPACE::cpp::Atomic<TrivialData> data({1, 2});
- ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 1);
- ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 2);
-
- auto old = data.exchange({3, 4});
- ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 3);
- ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 4);
- ASSERT_EQ(old.a, 1);
- ASSERT_EQ(old.b, 2);
+ LIBC_NAMESPACE::cpp::Atomic<TrivialData> data({'a', 'b', {}});
+ ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 'a');
+ ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 'b');
+
+ auto old = data.exchange({'c', 'd', {}});
+ ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 'c');
+ ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 'd');
+ ASSERT_EQ(old.a, 'a');
+ ASSERT_EQ(old.b, 'b');
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/119087
More information about the libc-commits
mailing list