Skip to content

Commit 1e27f44

Browse files
Navillearbipher
authored andcommitted
Fix building with Windows SDK and Clang-CL (Z3Prover#7337)
* Fix building with Windows SDK and Clang-CL * Attempt to add Clang-CL to CI build configurations * Fix typo * Enable EHsc explicitly when using ClangCL due to it being default turned-off * Override CMAKE_<LANG>_FLAGS instead due to Z3 resets the _INIT variants
1 parent 895e764 commit 1e27f44

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: MSVC Clang-CL Static Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read # to fetch code (actions/checkout)
9+
10+
jobs:
11+
build:
12+
runs-on: windows-2019
13+
env:
14+
BUILD_TYPE: Release
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
19+
- name: Build
20+
run: |
21+
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DZ3_BUILD_LIBZ3_SHARED=OFF -DZ3_BUILD_LIBZ3_MSVC_STATIC=ON -T ClangCL -DCMAKE_C_FLAGS="/EHsc" -DCMAKE_CXX_FLAGS="/EHsc"
22+
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
23+

src/util/mpz.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ Revision History:
4646
#define LEHMER_GCD
4747
#endif
4848

49-
50-
#if defined(__GNUC__)
49+
#ifdef __has_builtin
50+
#define HAS_BUILTIN(X) __has_builtin(X)
51+
#else
52+
#define HAS_BUILTIN(X) 0
53+
#endif
54+
#if HAS_BUILTIN(__builtin_ctz)
5155
#define _trailing_zeros32(X) __builtin_ctz(X)
52-
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC)))
56+
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC))) && !defined(__clang__)
5357
// This is needed for _tzcnt_u32 and friends.
5458
#include <immintrin.h>
5559
#define _trailing_zeros32(X) _tzcnt_u32(X)
@@ -62,11 +66,11 @@ static uint32_t _trailing_zeros32(uint32_t x) {
6266
#endif
6367

6468
#if (defined(__LP64__) || defined(_WIN64)) && defined(_M_X64) && !defined(_M_ARM64EC)
65-
#if defined(__GNUC__)
66-
#define _trailing_zeros64(X) __builtin_ctzll(X)
67-
#else
68-
#define _trailing_zeros64(X) _tzcnt_u64(X)
69-
#endif
69+
#if HAS_BUILTIN(__builtin_ctzll)
70+
#define _trailing_zeros64(X) __builtin_ctzll(X)
71+
#elif !defined(__clang__)
72+
#define _trailing_zeros64(X) _tzcnt_u64(X)
73+
#endif
7074
#else
7175
static uint64_t _trailing_zeros64(uint64_t x) {
7276
uint64_t r = 0;
@@ -75,6 +79,8 @@ static uint64_t _trailing_zeros64(uint64_t x) {
7579
}
7680
#endif
7781

82+
#undef HAS_BUILTIN
83+
7884
unsigned trailing_zeros(uint32_t x) {
7985
return static_cast<unsigned>(_trailing_zeros32(x));
8086
}

0 commit comments

Comments
 (0)