]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Enable warning C4242 and treat warnings as errors for Visual C++.
authorMika Lindqvist <postmaster@raasu.org>
Mon, 12 Aug 2024 23:20:19 +0000 (02:20 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 17 Sep 2024 12:05:18 +0000 (14:05 +0200)
CMakeLists.txt
arch/arm/chunkset_neon.c
arch/arm/neon_intrins.h
arch/x86/adler32_avx512_p.h
arch/x86/x86_intrins.h
deflate.h
inflate.h
test/CMakeLists.txt
test/fuzz/fuzzer_minigzip.c
test/test_gzio.cc
zbuild.h

index 23c182974f0fb77433be9475601f80fa71e97322..02f05de47d34ee24dc7d4a4f4edb0ff6ba4e38ec 100644 (file)
@@ -190,9 +190,9 @@ elseif(MSVC)
     # (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should
     # avoid mistakes.
     # /Oi ?
-    set(WARNFLAGS /W3)
+    set(WARNFLAGS /W3 /w34242 /WX)
     set(WARNFLAGS_MAINTAINER /W4)
-    set(WARNFLAGS_DISABLE)
+    set(WARNFLAGS_DISABLE /wd4206 /wd4054)
     if(BASEARCH_ARM_FOUND)
         add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
         if(NOT "${ARCH}" MATCHES "aarch64")
index f9a444b0681fc02a832fd3399a6cc1be37c77533..ba32921e009b9963f3cc83d60ad24acd9a2cd5c6 100644 (file)
@@ -84,7 +84,9 @@ static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t
     a = vld1_u8(buf);
     b = vld1_u8(buf + 8);
     ret0 = vtbl1_u8(a, perm_vec0);
-    uint8x8x2_t ab = {{a, b}};
+    uint8x8x2_t ab;
+    ab.val[0] = a;
+    ab.val[1] = b;
     ret1 = vtbl2_u8(ab, perm_vec1);
     return vcombine_u8(ret0, ret1);
 #endif
index a9e99ec88a9ce968abdcf0cc7a12ad77af31fe48..5dc242d5211ae11a742e27be790c2c3f2f847f15 100644 (file)
 #  ifndef ARM_NEON_HASLD4
 
 static inline uint16x8x4_t vld1q_u16_x4(uint16_t const *a) {
-    uint16x8x4_t ret = (uint16x8x4_t) {{
-                          vld1q_u16(a),
-                          vld1q_u16(a+8),
-                          vld1q_u16(a+16),
-                          vld1q_u16(a+24)}};
+    uint16x8x4_t ret;
+    ret.val[0] = vld1q_u16(a);
+    ret.val[1] = vld1q_u16(a+8);
+    ret.val[2] = vld1q_u16(a+16);
+    ret.val[3] = vld1q_u16(a+24);
     return ret;
 }
 
 static inline uint8x16x4_t vld1q_u8_x4(uint8_t const *a) {
-    uint8x16x4_t ret = (uint8x16x4_t) {{
-                          vld1q_u8(a),
-                          vld1q_u8(a+16),
-                          vld1q_u8(a+32),
-                          vld1q_u8(a+48)}};
+    uint8x16x4_t ret;
+    ret.val[0] = vld1q_u8(a);
+    ret.val[1] = vld1q_u8(a+16);
+    ret.val[2] = vld1q_u8(a+32);
+    ret.val[3] = vld1q_u8(a+48);
     return ret;
 }
 
index 5b79d2ab6ee7dde1791e18d02f3ab51008b0d3b1..742269053c061f568bc8b66f0c9944b5ea9b3753 100644 (file)
@@ -3,6 +3,17 @@
 
 #include <immintrin.h>
 #include <stdint.h>
+
+/* Written because Visual C++ toolchains before v142 have constant overflow in AVX512 intrinsic macros */
+#if defined(_MSC_VER) && !defined(_MM_K0_REG8)
+#  undef _mm512_extracti64x4_epi64
+#  define _mm512_extracti64x4_epi64(v1, e1) _mm512_maskz_extracti64x4_epi64(UINT8_MAX, v1, e1)
+#  undef _mm512_set1_epi16
+#  define _mm512_set1_epi16(e1) _mm512_maskz_set1_epi16(UINT32_MAX, e1)
+#  undef _mm512_maddubs_epi16
+#  define _mm512_maddubs_epi16(v1, v2) _mm512_maskz_maddubs_epi16(UINT32_MAX, v1, v2)
+#endif
+
 /* Written because *_add_epi32(a) sets off ubsan */
 static inline uint32_t _mm512_reduce_add_epu32(__m512i x) {
     __m256i a = _mm512_extracti64x4_epi64(x, 1);
index 0e596d18a14391bf12478197fdd469b1bd901d16..a2ec0027c31cbabb7af79be34f1c4f0c66b2de91 100644 (file)
@@ -84,4 +84,9 @@ static inline __m512i _mm512_zextsi128_si512(__m128i a) {
 #endif // __AVX512F__
 #endif // defined(_MSC_VER) && _MSC_VER < 1914
 
+/* Visual C++ toolchains before v142 have constant overflow in AVX512 intrinsics */
+#if defined(_MSC_VER) && defined(__AVX512F__) && !defined(_MM_K0_REG8)
+#  undef _mm512_extracti32x4_epi32
+#  define _mm512_extracti32x4_epi32(v1, e1) _mm512_maskz_extracti32x4_epi32(UINT8_MAX, v1, e1)
+#endif
 #endif // include guard X86_INTRINS_H
index 8001b47c999d8fb6456081da50de6829fccca4da..77effb2a07dbb8876ad6b3e127c8f4935d068059 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -214,6 +214,10 @@ struct internal_state {
 
     int nice_match; /* Stop searching when current match exceeds this */
 
+#if defined(_M_IX86) || defined(_M_ARM)
+    int padding[2];
+#endif
+
     struct crc32_fold_s ALIGNED_(16) crc_fold;
 
                 /* used by trees.c: */
@@ -283,7 +287,10 @@ struct internal_state {
     /* Number of valid bits in bi_buf.  All bits above the last valid bit are always zero. */
 
     /* Reserved for future use and alignment purposes */
-    int32_t reserved[11];
+    int32_t reserved[19];
+#if defined(_M_IX86) || defined(_M_ARM)
+    int32_t padding2[4];
+#endif
 } ALIGNED_(8);
 
 typedef enum {
index 39cdf5d683c39efc01d89c54b7693596c08ef505..f8b6b36972d7a43666199adebdd34f2796a87596 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -103,6 +103,11 @@ struct inflate_state {
     uint32_t whave;             /* valid bytes in the window */
     uint32_t wnext;             /* window write index */
     unsigned char *window;      /* allocated sliding window, if needed */
+#if defined(_M_IX86) || defined(_M_ARM)
+    uint32_t padding;
+#else
+    uint32_t padding[2];
+#endif
 
     struct crc32_fold_s ALIGNED_(16) crc_fold;
 
@@ -132,6 +137,9 @@ struct inflate_state {
     int back;                   /* bits back of last unprocessed length/lit */
     unsigned was;               /* initial length of match */
     uint32_t chunksize;         /* size of memory copying chunk */
+#if defined(_M_IX86) || defined(_M_ARM)
+    int padding2[8];
+#endif
 };
 
 int Z_INTERNAL PREFIX(inflate_ensure_window)(struct inflate_state *state);
index 19ad4a3ec275a6559dc001a394960a16699c76a8..622e2519406babf4d12a5186779f90140dfe1113 100644 (file)
@@ -202,6 +202,13 @@ if(WITH_GTEST)
         add_executable(gtest_zlib ${TEST_SRCS})
         configure_test_executable(gtest_zlib)
 
+        if(MSVC)
+            target_compile_options(gtest_zlib PRIVATE /wd4389)
+            if(BASEARCH_ARM_FOUND)
+                target_compile_options(gtest_zlib PRIVATE /EHsc)
+            endif()
+        endif()
+
         if(WITH_SANITIZER STREQUAL "Memory")
             target_link_directories(gtest_zlib PRIVATE $ENV{LLVM_BUILD_DIR}/lib)
             target_link_options(gtest_zlib PRIVATE
index fbbe19c3b050ddb173749f46a3835faa20f8e239..6e388819625897d6e8bf81d9719815738221659b 100644 (file)
@@ -302,7 +302,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) {
         }
         if (len == 0)
             break;
-        assert(0 == memcmp(data + offset, buf, len));
+        int c = memcmp(data + offset, buf, len);
+        assert(0 == c);
+        Z_UNUSED(c); // in Release build, assert() is a no-op.
         offset += len;
     }
 
index 3cab1dbe408fdeb79dbba775074a39155a188dcf..032e3e1c5178186829d661397c68c036bae9086b 100644 (file)
@@ -30,6 +30,7 @@ TEST(gzip, readwrite) {
     gzFile file;
     int err;
 
+    Z_UNUSED(compr);
     /* Write gz file with test data */
     file = PREFIX(gzopen)(TESTFILE, "wb");
     ASSERT_TRUE(file != NULL);
index 206eed23121f861287c97dab9c032af9ea22a22f..0717fe40a94eab3082b78cc7201388165dc35d43 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 #  include <stdio.h>
    extern int Z_INTERNAL z_verbose;
    extern void Z_INTERNAL z_error(const char *m);
-#  define Assert(cond, msg) {if (!(cond)) z_error(msg);}
+#  define Assert(cond, msg) {int _cond = (cond); if (!_cond) z_error(msg);}
 #  define Trace(x) {if (z_verbose >= 0) fprintf x;}
 #  define Tracev(x) {if (z_verbose > 0) fprintf x;}
 #  define Tracevv(x) {if (z_verbose > 1) fprintf x;}