From deb9cd644989ae1ff8ee1c45951fa4d01d5a77e4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:55:52 +0000 Subject: [PATCH 1/5] [UPSTREAM, secp256k1] cmake: Adjust diagnostic flags for clang-cl --- src/secp256k1/CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/secp256k1/CMakeLists.txt b/src/secp256k1/CMakeLists.txt index 041bfa3dca..f8a78ce12e 100644 --- a/src/secp256k1/CMakeLists.txt +++ b/src/secp256k1/CMakeLists.txt @@ -242,17 +242,21 @@ endif() include(TryAppendCFlags) if(MSVC) - # Keep the following commands ordered lexicographically. + # For both cl and clang-cl compilers. try_append_c_flags(/W3) # Production quality warning level. - try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned". - try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data". - try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data". # Eliminate deprecation warnings for the older, less secure functions. add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +else() + try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers. +endif() +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + # Keep the following commands ordered lexicographically. + try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned". + try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data". + try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data". else() # Keep the following commands ordered lexicographically. try_append_c_flags(-pedantic) - try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers. try_append_c_flags(-Wcast-align) # GCC >= 2.95. try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0. try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only. From 6f55b3d653bd3b39245c5fa65b72668198ddb469 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:21:38 +0000 Subject: [PATCH 2/5] cmake: Adjust diagnostic flags for clang-cl --- CMakeLists.txt | 14 +++++++++----- cmake/leveldb.cmake | 8 +++++--- cmake/module/TryAppendCXXFlags.cmake | 6 +++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dba6f255d..59fd4d2e5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,18 +395,22 @@ include(cmake/ccache.cmake) add_library(warn_interface INTERFACE) target_link_libraries(core_interface INTERFACE warn_interface) if(MSVC) + # For both cl and clang-cl compilers. try_append_cxx_flags("/W3" TARGET warn_interface SKIP_LINK) - try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK) - try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK) - try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK) - try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK) - try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK) target_compile_definitions(warn_interface INTERFACE _CRT_SECURE_NO_WARNINGS _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING ) else() try_append_cxx_flags("-Wall" TARGET warn_interface SKIP_LINK) +endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + try_append_cxx_flags("/wd4018" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("/wd4244" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("/wd4267" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("/wd4715" TARGET warn_interface SKIP_LINK) + try_append_cxx_flags("/wd4805" TARGET warn_interface SKIP_LINK) +else() try_append_cxx_flags("-Wextra" TARGET warn_interface SKIP_LINK) try_append_cxx_flags("-Wgnu" TARGET warn_interface SKIP_LINK) # Some compilers will ignore -Wformat-security without -Wformat, so just combine the two here. diff --git a/cmake/leveldb.cmake b/cmake/leveldb.cmake index 823a5d8e3d..5516ca029a 100644 --- a/cmake/leveldb.cmake +++ b/cmake/leveldb.cmake @@ -81,12 +81,14 @@ target_include_directories(leveldb add_library(nowarn_leveldb_interface INTERFACE) if(MSVC) - target_compile_options(nowarn_leveldb_interface INTERFACE - /wd4722 - ) target_compile_definitions(nowarn_leveldb_interface INTERFACE _CRT_NONSTDC_NO_WARNINGS ) +endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(nowarn_leveldb_interface INTERFACE + /wd4722 + ) else() target_compile_options(nowarn_leveldb_interface INTERFACE -Wno-conditional-uninitialized diff --git a/cmake/module/TryAppendCXXFlags.cmake b/cmake/module/TryAppendCXXFlags.cmake index dc0a9b7f8f..ebb7414c0e 100644 --- a/cmake/module/TryAppendCXXFlags.cmake +++ b/cmake/module/TryAppendCXXFlags.cmake @@ -120,7 +120,11 @@ function(try_append_cxx_flags flags) endfunction() if(MSVC) - try_append_cxx_flags("/WX /options:strict" VAR working_compiler_werror_flag SKIP_LINK) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + try_append_cxx_flags("/WX /options:strict" VAR working_compiler_werror_flag SKIP_LINK) + else() + try_append_cxx_flags("/WX" VAR working_compiler_werror_flag SKIP_LINK) + endif() else() try_append_cxx_flags("-Werror" VAR working_compiler_werror_flag SKIP_LINK) endif() From adc86c30c5614de8717ee540c2ff84aa8460d60e Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:18:14 +0000 Subject: [PATCH 3/5] ci: Test building with clang-cl --- .github/workflows/ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 740d31ae56..5b275f0401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -165,10 +165,13 @@ jobs: include: - job-type: standard generate-options: '-DBUILD_GUI=ON -DWITH_BDB=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON -DWERROR=ON' - job-name: 'Win64 native, VS 2022' + job-name: 'Win64 native, MSVC' + - job-type: clang-cl + generate-options: '-T ClangCL -DBUILD_GUI=ON -DWITH_BDB=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON' + job-name: 'Win64 native, clang-cl' - job-type: fuzz generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="sqlite" -DBUILD_GUI=OFF -DBUILD_FOR_FUZZING=ON -DWERROR=ON' - job-name: 'Win64 native fuzz, VS 2022' + job-name: 'Win64 native fuzz, MSVC' steps: - name: Checkout @@ -225,13 +228,13 @@ jobs: cmake --build . -j $env:NUMBER_OF_PROCESSORS --config Release - name: Run test suite - if: matrix.job-type == 'standard' + if: matrix.job-type != 'fuzz' working-directory: build run: | ctest --output-on-failure --stop-on-failure -j $env:NUMBER_OF_PROCESSORS -C Release - name: Run functional tests - if: matrix.job-type == 'standard' + if: matrix.job-type != 'fuzz' working-directory: build env: BITCOIND: '${{ github.workspace }}\build\src\Release\bitcoind.exe' From 4022d5ecca87b3f2bdfb3eb2823f547483a2ba73 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:07:26 +0000 Subject: [PATCH 4/5] cmake: Restrict MSVC-specific workaround to MSVC compiler only This change enables compiling `fuzz/utxo_snapshot.cpp` with clang-cl. --- src/test/fuzz/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/fuzz/CMakeLists.txt b/src/test/fuzz/CMakeLists.txt index f65ed62b2d..7481f23680 100644 --- a/src/test/fuzz/CMakeLists.txt +++ b/src/test/fuzz/CMakeLists.txt @@ -127,7 +127,7 @@ add_executable(fuzz # Visual Studio 2022 version 17.12 introduced a bug # that causes an internal compiler error. # See: https://github.com/bitcoin/bitcoin/issues/31303 - $<$:utxo_snapshot.cpp> + $<$,$,19.42>>>:utxo_snapshot.cpp> utxo_total_supply.cpp validation_load_mempool.cpp vecdeque.cpp From caa61b5c7a07536925f42b3cd52dd0ba5e768fe4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:09:22 +0000 Subject: [PATCH 5/5] ci: Switch "Win64 native, fuzz" job to clang-cl --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b275f0401..3da6d7b35f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,8 +170,8 @@ jobs: generate-options: '-T ClangCL -DBUILD_GUI=ON -DWITH_BDB=ON -DWITH_ZMQ=ON -DBUILD_BENCH=ON' job-name: 'Win64 native, clang-cl' - job-type: fuzz - generate-options: '-DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="sqlite" -DBUILD_GUI=OFF -DBUILD_FOR_FUZZING=ON -DWERROR=ON' - job-name: 'Win64 native fuzz, MSVC' + generate-options: '-T ClangCL -DVCPKG_MANIFEST_NO_DEFAULT_FEATURES=ON -DVCPKG_MANIFEST_FEATURES="sqlite" -DBUILD_GUI=OFF -DBUILD_FOR_FUZZING=ON' + job-name: 'Win64 native, fuzz, clang-cl' steps: - name: Checkout