Skip to content

Commit e60e04f

Browse files
committed
Fix Windows build
Cherrypick microsoft/mimalloc@5764845 to fix Windows CI.
1 parent 3651dba commit e60e04f

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

third-party/mimalloc/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ endif()
102102
# -----------------------------------------------------------------------------
103103
# Process options
104104
# -----------------------------------------------------------------------------
105+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
106+
set(MI_CLANG_CL "ON")
107+
endif()
105108

106109
# put -Wall early so other warnings can be disabled selectively
107110
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
108-
list(APPEND mi_cflags -Wall -Wextra -Wpedantic)
111+
if (MI_CLANG_CL)
112+
list(APPEND mi_cflags -W)
113+
else()
114+
list(APPEND mi_cflags -Wall -Wextra -Wpedantic)
115+
endif()
109116
endif()
110117
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
111118
list(APPEND mi_cflags -Wall -Wextra)
@@ -371,21 +378,21 @@ endif()
371378
# endif()
372379

373380
# Compiler flags
374-
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
381+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU" AND NOT MI_CLANG_CL)
375382
list(APPEND mi_cflags -Wno-unknown-pragmas -fvisibility=hidden)
376383
if(NOT MI_USE_CXX)
377384
list(APPEND mi_cflags -Wstrict-prototypes)
378385
endif()
379386
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
380387
list(APPEND mi_cflags -Wno-static-in-inline)
381-
endif()
388+
endif()
382389
endif()
383390

384391
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
385392
list(APPEND mi_cflags -fvisibility=hidden)
386393
endif()
387394

388-
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
395+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku" AND NOT MI_CLANG_CL)
389396
if(MI_LOCAL_DYNAMIC_TLS)
390397
list(APPEND mi_cflags -ftls-model=local-dynamic)
391398
else()
@@ -401,6 +408,9 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM
401408
if(MI_OVERRIDE)
402409
list(APPEND mi_cflags -fno-builtin-malloc)
403410
endif()
411+
endif()
412+
413+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
404414
if(MI_OPT_ARCH)
405415
if(MI_ARCH STREQUAL "arm64")
406416
set(MI_OPT_ARCH_FLAGS "-march=armv8.1-a") # fast atomics
@@ -410,9 +420,9 @@ endif()
410420

411421
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
412422
list(APPEND mi_cflags /Zc:__cplusplus)
413-
if(MI_OPT_ARCH)
423+
if(MI_OPT_ARCH AND NOT MI_CLANG_CL)
414424
if(MI_ARCH STREQUAL "arm64")
415-
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
425+
set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
416426
endif()
417427
endif()
418428
endif()

third-party/mimalloc/include/mimalloc/atomic.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ terms of the MIT license. A copy of the license can be found in the file
3131
#if defined(__cplusplus)
3232
// Use C++ atomics
3333
#include <atomic>
34-
#define _Atomic(tp) std::atomic<tp>
35-
#define mi_atomic(name) std::atomic_##name
36-
#define mi_memory_order(name) std::memory_order_##name
37-
#if (__cplusplus >= 202002L) // c++20, see issue #571
38-
#define MI_ATOMIC_VAR_INIT(x) x
34+
#define _Atomic(tp) std::atomic<tp>
35+
#define mi_atomic(name) std::atomic_##name
36+
#define mi_memory_order(name) std::memory_order_##name
37+
#if (__cplusplus >= 202002L) // c++20, see issue #571
38+
#define MI_ATOMIC_VAR_INIT(x) x
3939
#elif !defined(ATOMIC_VAR_INIT)
40-
#define MI_ATOMIC_VAR_INIT(x) x
40+
#define MI_ATOMIC_VAR_INIT(x) x
4141
#else
42-
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
42+
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
4343
#endif
4444
#elif defined(_MSC_VER)
4545
// Use MSVC C wrapper for C11 atomics
46-
#define _Atomic(tp) tp
47-
#define MI_ATOMIC_VAR_INIT(x) x
48-
#define mi_atomic(name) mi_atomic_##name
49-
#define mi_memory_order(name) mi_memory_order_##name
46+
#define _Atomic(tp) tp
47+
#define MI_ATOMIC_VAR_INIT(x) x
48+
#define mi_atomic(name) mi_atomic_##name
49+
#define mi_memory_order(name) mi_memory_order_##name
5050
#else
5151
// Use C11 atomics
5252
#include <stdatomic.h>
53-
#define mi_atomic(name) atomic_##name
54-
#define mi_memory_order(name) memory_order_##name
53+
#define mi_atomic(name) atomic_##name
54+
#define mi_memory_order(name) memory_order_##name
5555
#if (__STDC_VERSION__ >= 201710L) // c17, see issue #735
56-
#define MI_ATOMIC_VAR_INIT(x) x
56+
#define MI_ATOMIC_VAR_INIT(x) x
5757
#elif !defined(ATOMIC_VAR_INIT)
58-
#define MI_ATOMIC_VAR_INIT(x) x
58+
#define MI_ATOMIC_VAR_INIT(x) x
5959
#else
60-
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
60+
#define MI_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x)
6161
#endif
6262
#endif
6363

@@ -290,6 +290,7 @@ static inline bool mi_atomic_casi64_strong_acq_rel(volatile _Atomic(int64_t*)p,
290290
#define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
291291
#define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
292292
#define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
293+
#define mi_atomic_exchange_ptr_relaxed(tp,p,x) (tp*)mi_atomic_exchange_relaxed((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
293294
#define mi_atomic_exchange_ptr_release(tp,p,x) (tp*)mi_atomic_exchange_release((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
294295
#define mi_atomic_exchange_ptr_acq_rel(tp,p,x) (tp*)mi_atomic_exchange_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
295296

third-party/mimalloc/src/arena.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static void mi_arenas_try_purge( bool force, bool visit_all )
607607

608608
// check if any arena needs purging?
609609
const mi_msecs_t now = _mi_clock_now();
610-
mi_msecs_t arenas_expire = mi_atomic_load_acquire(&mi_arenas_purge_expire);
610+
mi_msecs_t arenas_expire = mi_atomic_loadi64_acquire(&mi_arenas_purge_expire);
611611
if (!force && (arenas_expire == 0 || arenas_expire < now)) return;
612612

613613
const size_t max_arena = mi_atomic_load_acquire(&mi_arena_count);
@@ -618,7 +618,7 @@ static void mi_arenas_try_purge( bool force, bool visit_all )
618618
mi_atomic_guard(&purge_guard)
619619
{
620620
// increase global expire: at most one purge per delay cycle
621-
mi_atomic_store_release(&mi_arenas_purge_expire, now + mi_arena_purge_delay());
621+
mi_atomic_storei64_release(&mi_arenas_purge_expire, now + mi_arena_purge_delay());
622622
size_t max_purge_count = (visit_all ? max_arena : 2);
623623
bool all_visited = true;
624624
for (size_t i = 0; i < max_arena; i++) {
@@ -635,7 +635,7 @@ static void mi_arenas_try_purge( bool force, bool visit_all )
635635
}
636636
if (all_visited) {
637637
// all arena's were visited and purged: reset global expire
638-
mi_atomic_store_release(&mi_arenas_purge_expire, 0);
638+
mi_atomic_storei64_release(&mi_arenas_purge_expire, 0);
639639
}
640640
}
641641
}

third-party/mimalloc/src/prim/windows/prim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int _mi_prim_free(void* addr, size_t size ) {
173173
// In mi_os_mem_alloc_aligned the fallback path may have returned a pointer inside
174174
// the memory region returned by VirtualAlloc; in that case we need to free using
175175
// the start of the region.
176-
MEMORY_BASIC_INFORMATION info = { 0 };
176+
MEMORY_BASIC_INFORMATION info; _mi_memzero_var(info);
177177
VirtualQuery(addr, &info, sizeof(info));
178178
if (info.AllocationBase < addr && ((uint8_t*)addr - (uint8_t*)info.AllocationBase) < (ptrdiff_t)MI_SEGMENT_SIZE) {
179179
errcode = 0;

0 commit comments

Comments
 (0)