From 4837a6512ac7d2625bef9df551909e5b4d0a268f Mon Sep 17 00:00:00 2001
From: Nicola Cabiddu <nicola.cabiddu@mongodb.com>
Date: Tue, 5 Mar 2024 15:23:51 +0000
Subject: [PATCH] please windows builder warnings + x86

---
 src/realm/array_direct.hpp |  5 +++++
 src/realm/node_header.hpp  | 10 +++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/realm/array_direct.hpp b/src/realm/array_direct.hpp
index ab011903627..394b4e2d125 100644
--- a/src/realm/array_direct.hpp
+++ b/src/realm/array_direct.hpp
@@ -798,10 +798,15 @@ constexpr uint32_t inverse_width[65] = {
 inline int first_field_marked(int width, uint64_t vector)
 {
 #if REALM_WINDOWS
+#ifdef _WIN32
+    int lz = (int)_tzcnt_u32(vector);
+#else
     int lz = (int)_tzcnt_u64(vector); // TODO: not clear if this is ok on all platforms
+#endif
 #else
     int lz = __builtin_ctzll(vector);
 #endif
+
     int field = (lz * inverse_width[width]) >> 22;
     REALM_ASSERT_DEBUG(field == (lz / width));
     return field;
diff --git a/src/realm/node_header.hpp b/src/realm/node_header.hpp
index e91a7b25def..0a3fac6e4bd 100644
--- a/src/realm/node_header.hpp
+++ b/src/realm/node_header.hpp
@@ -401,11 +401,11 @@ class NodeHeader {
         }
         else if (enc == Encoding::Packed) {
             hb[2] = 0;
-            hb[3] = bits_pr_elem;
+            hb[3] = static_cast<uint8_t>(bits_pr_elem);
             hb[4] = (flags << 5) | (wtype_Extend << 3);
             hb[5] = (uint8_t)enc - wtype_Extend;
             auto hw = (uint16_t*)header;
-            hw[3] = num_elems;
+            hw[3] = static_cast<uint16_t>(num_elems);
         }
         else {
             REALM_ASSERT(false && "Illegal header encoding for chosen kind of header");
@@ -452,8 +452,8 @@ class NodeHeader {
         REALM_ASSERT(bits_pr_elemB <= 64);
         REALM_ASSERT(num_elemsA < 1024);
         REALM_ASSERT(num_elemsB < 1024);
-        hh[1] = ((bits_pr_elemB - 1) << 10) | num_elemsB;
-        hh[3] = ((bits_pr_elemA - 1) << 10) | num_elemsA;
+        hh[1] = static_cast<uint16_t>(((bits_pr_elemB - 1) << 10) | num_elemsB);
+        hh[3] = static_cast<uint16_t>(((bits_pr_elemA - 1) << 10) | num_elemsA);
     }
 
     // Setting element size for encodings with a single element size:
@@ -530,7 +530,7 @@ void inline NodeHeader::set_element_size<NodeHeader::Encoding::Packed>(char* hea
 {
     REALM_ASSERT(get_encoding(header) == Encoding::Packed);
     REALM_ASSERT(bits_per_element <= 64);
-    ((uint8_t*)header)[3] = static_cast<uint16_t>(bits_per_element);
+    ((uint8_t*)header)[3] = static_cast<uint8_t>(bits_per_element);
 }
 template <>
 void inline NodeHeader::set_element_size<NodeHeader::Encoding::WTypBits>(char* header, size_t bits_per_element)