[libc-commits] [libc] [libc] fix 32bit atomic tests (PR #119087)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Sat Dec 7 10:41:47 PST 2024


https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/119087

None

>From dee05358a4e237436c444a306d0766d60950f55f Mon Sep 17 00:00:00 2001
From: schrodingerzhu <i at zhuyi.fan>
Date: Sat, 7 Dec 2024 13:40:28 -0500
Subject: [PATCH] [libc] fix 32bit atomic tests

---
 libc/test/src/__support/CPP/atomic_test.cpp | 25 +++++++++++----------
 1 file changed, 13 insertions(+), 12 deletions(-)

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');
 }



More information about the libc-commits mailing list