]> 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>
Thu, 22 Aug 2024 14:47:59 +0000 (16:47 +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 719673fbf34a1a313620855af212d94db21517fd..fba3575d4d63abc63fd8924e318f9acc986e9dc2 100644 (file)
@@ -191,9 +191,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 1c49ef56123552011344b0fd182f2deb50130a19..0016f7f2234bf3f73d313bcb2158cac773ac9e02 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 e122ae1aad6570ce489b275582fa7866d2a1e0dc..2077f068e7a988098fbfc623dc8c84d7dda1af15 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -243,6 +243,10 @@ struct ALIGNED_(64) 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: */
@@ -323,7 +327,10 @@ struct ALIGNED_(64) 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
 };
 
 typedef enum {
index 536da7d1f8fce0317100ddd7aacfc539c6672a07..30ff7db3b756e9dc146394d576188d5b0cb09cc4 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -115,6 +115,11 @@ struct ALIGNED_(64) 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;
 
@@ -148,6 +153,9 @@ struct ALIGNED_(64) inflate_state {
 #ifdef HAVE_ARCH_INFLATE_STATE
     arch_inflate_state arch;    /* architecture-specific extensions */
 #endif
+#if defined(_M_IX86) || defined(_M_ARM)
+    int padding2[8];
+#endif
 };
 
 void Z_INTERNAL PREFIX(fixedtables)(struct inflate_state *state);
index 70c5b5441cfffaaef9fc32db5efc978181056ab6..481373334344237468b57f9a306392b88e81ead7 100644 (file)
@@ -201,6 +201,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 9157eef9e356ba0fd71b9843f558719b92736c7d..4e9d4035041549395ef91b228efea96c13a2645a 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;}