Skip to content

Commit

Permalink
Fix an apparent x86 miscompilation on MSVC 19.38 (#16742)
Browse files Browse the repository at this point in the history
There's an apparent miscompilation of `dynamic_bitset` on x86 with
MSVC 19.38, where the following code:
```cpp
dynamic_bitset<uint64_t> 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<uint64_t>`. As soon as it uses `<uint32_t>`
any other instantiation of `<uint64_t>` 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 d3ec47a)
Service-Card-Id: 91885583
Service-Version: 1.19
  • Loading branch information
lhecker authored and DHowett committed Feb 21, 2024
1 parent 78da9bd commit 0ec73b1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/inc/til/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned long long, Allocator>& values, til::rect rc, ptrdiff_t pos) :
_bitmap_const_iterator(const dynamic_bitset<size_t, Allocator>& values, til::rect rc, ptrdiff_t pos) :
_values(values),
_rc(rc),
_pos(pos),
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
}

private:
const dynamic_bitset<unsigned long long, Allocator>& _values;
const dynamic_bitset<size_t, Allocator>& _values;
const til::rect _rc;
size_t _pos;
size_t _nextPos;
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
}
};

template<typename Allocator = std::allocator<unsigned long long>>
template<typename Allocator = std::allocator<size_t>>
class bitmap
{
public:
Expand Down Expand Up @@ -538,7 +538,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
allocator_type _alloc;
til::size _sz;
til::rect _rc;
dynamic_bitset<unsigned long long, allocator_type> _bits;
dynamic_bitset<size_t, allocator_type> _bits;

mutable std::optional<std::vector<til::rect, run_allocator_type>> _runs;

Expand All @@ -553,7 +553,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"

namespace pmr
{
using bitmap = ::til::details::bitmap<std::pmr::polymorphic_allocator<unsigned long long>>;
using bitmap = ::til::details::bitmap<std::pmr::polymorphic_allocator<size_t>>;
}
}

Expand Down

1 comment on commit 0ec73b1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (13)
atvis
CProc
hpj
LPCCH
NONCONST
rgi
spammy
tokeninfo
traceloggingprovider
userbase
VProc
VRaw
wcsnicmp
Previously acknowledged words that are now absent DESTINATIONNAME :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the release-1.19 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/7993404515/attempts/1'
Pattern suggestions ✂️ (1)

You could add these patterns to .github/actions/spelling/patterns/0ec73b1a6ec3ef0a83e58643ef7d511c096f1e4b.txt:

# Automatically suggested patterns
# hit-count: 1 file-count: 1
# tput arguments -- https://man7.org/linux/man-pages/man5/terminfo.5.html -- technically they can be more than 5 chars long...
\btput\s+(?:(?:-[SV]|-T\s*\w+)\s+)*\w{3,5}\b

Warnings (1)

See the 📜action log for details.

ℹ️ Warnings Count
ℹ️ candidate-pattern 1

See ℹ️ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.