test: Add a test for atomic load/store of large integers
Test atomically loading/storing 128 bit integers on 64 bit, and 64 bit integers on 32 bit. This test case covers the root cause of https://github.com/mstorsjo/llvm-mingw/issues/538.
This commit is contained in:
1 parent
9610c61240
commit
49afca5984
2 files changed
+52
-1
No files matched your search
+1
-1
@@ -101,7 +101,7 @@ ifneq ($(HAVE_CFGUARD),)
|
||||
TESTS_CFGUARD = cfguard-test
|
||||
TESTS_ASAN_CFGUARD = $(TESTS_ASAN)
|
||||
endif
|
||||
TESTS_ATOMIC = atomic-helpers
|
||||
TESTS_ATOMIC = atomic-helpers atomic-load-store
|
||||
|
||||
TARGETS_C = $(addsuffix $(EXEEXT), $(TESTS_C))
|
||||
TARGETS_C_DLL = $(addsuffix $(DLLEXT), $(TESTS_C_DLL))
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Martin Storsjo
|
||||
*
|
||||
* This file is part of llvm-mingw.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __SIZEOF_INT128__
|
||||
#define TYPE __uint128_t
|
||||
#else
|
||||
#define TYPE uint64_t
|
||||
#endif
|
||||
|
||||
_Atomic(TYPE) atomic_var;
|
||||
TYPE regular_var;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
regular_var = 0x0123456789abcdef;
|
||||
#ifdef __SIZEOF_INT128__
|
||||
regular_var <<= 64;
|
||||
regular_var |= 0xfedcba9876543210;
|
||||
#endif
|
||||
memcpy(&atomic_var, ®ular_var, sizeof(regular_var));
|
||||
regular_var = atomic_load(&atomic_var);
|
||||
if (memcmp(&atomic_var, ®ular_var, sizeof(regular_var))) {
|
||||
printf("load failed\n");
|
||||
return 1;
|
||||
}
|
||||
atomic_store(&atomic_var, regular_var);
|
||||
if (memcmp(&atomic_var, ®ular_var, sizeof(regular_var))) {
|
||||
printf("store failed\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user