{{ message }}
Fix wstring::find_first_of infinite loop on ARM64#6345
Open
StephanTLavavej wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an ARM64/ARM64EC infinite loop in basic_string(_view)::find_first_of for 2-byte (and larger) element types, a regression introduced in MSVC Build Tools 14.51 (PR #6115). In the Neon bitmap worker _Impl_first_neon, the scalar tail's index advance (++_Ix;) lived at the bottom of a do/while loop, so a continue taken for haystack elements >= 256 (the _Any_of case) skipped the increment and froze the index, hanging forever. The fix moves the increment into the loop condition so it is always executed.
Changes:
- Made the scalar-tail index advance unconditional in
_Impl_first_neonby folding++_Ixinto thedo/whilecondition. - Added a targeted regression test
test_gh_6342_find_first_of()covering the large-char × matching-char combinations in the scalar tail. - Added a product-code comment linking the
_Use_bitmap_neonthreshold to the new test.
Show a summary per file
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
BillyONeal
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #6342 which is a regression in the MSVC Build Tools 14.51, so I might need to think about backporting this.
I've verified that without the fix, my cleaned-up test case triggers the infinite loop in our PR/CI system.
I enhanced the test case to cover 4 combinations: large character absent/present at a position before matching character absent/present. (This theoretically guards against behavior like "oh, large character found, immediately return
npos".) I reset the haystack to allL'x'at the end, even though those writes are dead, to make the pattern clear. I felt that this was simpler than allowing mutations to accumulate between each check, which is harder to keep track of.It's unusual for our product code comments to mention test code, but in this case because we have a performance threshold in the product code that affects whether the test code exercises something meaningful, I felt that a single-line comment was warranted.
The bugfix is intentionally minimal since I have no insight into ARM64 performance effects.
I reviewed all occurrences of
continue;and I believe this was the only damaged one.