Repository navigation
Fix rvalue usage of vector<bool>::reference - #576
Merged
Merged
Conversation
nunoplopes
pushed a commit
that referenced
this pull request
Nov 1, 2026
Make substring calls evaluate their receiver and arguments once in both output models. Duplicating an operand during inline substitution can change both the selected bytes and caller state; this handles the substring case of #575. The side-effect cases in [tests/unit/string.cpp](tests/unit/string.cpp) compare substring bytes and final counters with C++ for position, count and receiver expressions. - Capture the receiver and arguments in a tuple match, which also keeps temporary receivers alive until the substring has been copied. - Borrow the source after evaluating the arguments, so argument expressions can modify it before the slice is read. - Materialize temporary receivers before taking their address in the unsafe converter. The result remains an independent, null-terminated copy of the selected slice. No whole-source clone is introduced; reference-counted receivers must now be addressable. Existing range clipping and overflow handling are unchanged. ## Testing - `lit` on `tests/unit/string.cpp` and `tests/unit/string_substr.cpp` (Linux, Release build): pass. Both fail without this change. - Full suite (unit, ub and multi-file) on Linux at ce0915c: 1142 pass / 14 xfail / 0 fail before; 1144 pass / 14 xfail / 0 fail with this change. The two new passes are the tests above. On macOS, one expected output in `string_substr.cpp` hard-codes the libstdc++ `std::string` size; a fix for that follows. - `clang-format --dry-run --Werror` on the changed C++ files, `rustfmt --check` on the changed rule files, and `cargo clippy --all-targets --all-features -- -Dwarnings` on `rules/`: clean. [tests/unit/string_substr.cpp](tests/unit/string_substr.cpp) checks receiver-before-argument ordering, source mutations in either argument, independent result storage, and temporary, pointer, field and container-element receivers. The generated Rust expectations cover both models. Related work: #576 changes vector proxy handling in the converter and binds repeated operands in vector rules; this change handles substring expansion. [Case and evidence](<https://app.perfloop.ai/t/oss/case_gs6rt5cvpd>) --- Generated by [Perfloop](https://app.perfloop.ai). Human sponsor: [Tomás Senart](https://github.com/tsenart). --------- Signed-off-by: Perfloop Agent <agent@perfloop.ai> Signed-off-by: Tomás Senart <ts@perfloop.ai>
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.
vector<bool>::referenceis not a real reference type, it's a proxy. Handle that using ExprMapsValueToPointer which checks values, the vector bool reference, translated as pointers.Also use __a0 = a0 in the vector rules because I++ runs 2 times otherwise.