From 2742f3de37e5856e2ab291248d7217332f51c912 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 21 Feb 2024 18:54:35 +0100 Subject: [PATCH] Fix an apparent x86 miscompilation on MSVC 19.38 (#16742) There's an apparent miscompilation of `dynamic_bitset` on x86 with MSVC 19.38, where the following code: ```cpp dynamic_bitset bits(80 * 24, 0); bits.set(0, 3 * 80, true); ``` is expected to set the first 3.75 blocks to 1 which should produce the following blocks: ``` 0xffffffffffffffff 0xffffffffffffffff 0xffffffffffffffff 0x0000ffffffffffff ``` but it actually produces: ``` 0xffffffffffffffff 0x00000000ffffffff 0xffffffffffffffff 0x0000ffffffffffff ``` The weird thing here is that this only happens if `til::bitmap` uses a `dynamic_bitset`. As soon as it uses `` any other instantiation of `` is magically fixed. Conclusion: Use `size_t` until we know what's going on. Last known good CL version: 14.37.32822 Current broken CL version: 14.38.33130 ## Validation Steps Performed The following test completes successfully again: ```cpp til::bitmap map{ { 80, 24 } }; map.translate({ 0, 3 }, true); VERIFY_ARE_EQUAL(3u, map.runs().size()); ``` (cherry picked from commit d3ec47a7fc3d4d5d50d2b66bae5f1a872ce3322d) Service-Card-Id: 91894072 Service-Version: 1.18 --- src/inc/til/bitmap.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/inc/til/bitmap.h b/src/inc/til/bitmap.h index 38213500477..3934af878cc 100644 --- a/src/inc/til/bitmap.h +++ b/src/inc/til/bitmap.h @@ -23,7 +23,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" using pointer = const til::rect*; using reference = const til::rect&; - _bitmap_const_iterator(const dynamic_bitset& values, til::rect rc, ptrdiff_t pos) : + _bitmap_const_iterator(const dynamic_bitset& values, til::rect rc, ptrdiff_t pos) : _values(values), _rc(rc), _pos(pos), @@ -77,7 +77,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" } private: - const dynamic_bitset& _values; + const dynamic_bitset& _values; const til::rect _rc; size_t _pos; size_t _nextPos; @@ -133,7 +133,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" } }; - template> + template> class bitmap { public: @@ -538,7 +538,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" allocator_type _alloc; til::size _sz; til::rect _rc; - dynamic_bitset _bits; + dynamic_bitset _bits; mutable std::optional> _runs; @@ -553,7 +553,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" namespace pmr { - using bitmap = ::til::details::bitmap>; + using bitmap = ::til::details::bitmap>; } }