Skip to content

Commit

Permalink
Fix building with Windows SDK and Clang-CL (#7337)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Naville authored Aug 15, 2024
1 parent 0612a0b commit c1454dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/msvc-static-build-clang-cl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: MSVC Clang-CL Static Build

on:
push:
pull_request:

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: windows-2019
env:
BUILD_TYPE: Release
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
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"
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
22 changes: 14 additions & 8 deletions src/util/mpz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ Revision History:
#define LEHMER_GCD
#endif


#if defined(__GNUC__)
#ifdef __has_builtin
#define HAS_BUILTIN(X) __has_builtin(X)
#else
#define HAS_BUILTIN(X) 0
#endif
#if HAS_BUILTIN(__builtin_ctz)
#define _trailing_zeros32(X) __builtin_ctz(X)
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC)))
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC))) && !defined(__clang__)
// This is needed for _tzcnt_u32 and friends.
#include <immintrin.h>
#define _trailing_zeros32(X) _tzcnt_u32(X)
Expand All @@ -62,11 +66,11 @@ static uint32_t _trailing_zeros32(uint32_t x) {
#endif

#if (defined(__LP64__) || defined(_WIN64)) && defined(_M_X64) && !defined(_M_ARM64EC)
#if defined(__GNUC__)
#define _trailing_zeros64(X) __builtin_ctzll(X)
#else
#define _trailing_zeros64(X) _tzcnt_u64(X)
#endif
#if HAS_BUILTIN(__builtin_ctzll)
#define _trailing_zeros64(X) __builtin_ctzll(X)
#elif !defined(__clang__)
#define _trailing_zeros64(X) _tzcnt_u64(X)
#endif
#else
static uint64_t _trailing_zeros64(uint64_t x) {
uint64_t r = 0;
Expand All @@ -75,6 +79,8 @@ static uint64_t _trailing_zeros64(uint64_t x) {
}
#endif

#undef HAS_BUILTIN

unsigned trailing_zeros(uint32_t x) {
return static_cast<unsigned>(_trailing_zeros32(x));
}
Expand Down

0 comments on commit c1454dc

Please sign in to comment.