Repository navigation
Keep mapped-call temporaries local to global initializers - #665
Merged
nunoplopes merged 1 commit intoNov 19, 2026
Merged
Conversation
Signed-off-by: Perfloop Agent <agent@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.
Global initializers containing mapped calls such as
std::min(0, 0)fail to compile in refcount output because temporary operands become ordinary Rust statics but use thread-local access. Unsafe output handles this literal-only call, but also fails nonconstant temporary initialization, including mixed-type conversions.cpp2rust/converter/converter.cppnow gives mapped-call arguments initializer-local storage through the enclosing full expression, including Rust-only cast temporaries. Enclosing calls share that storage for temporary arrays and records; hoisted bindings have unique names.Refcount global assignments bind right-hand sides before entering the thread-local closure, keeping temporary initialization outside it and preserving C++17's right-operand-first sequencing for same-type assignments.
tests/unit/global_call_temporaries.cppcovers reference-taking consumers, mixed-type initialization, enclosing aggregates and global assignments. Both Rust expectations were added.Still broken:
i += (i = 10, std::max(1.5, 0.5)), which still reads the left operand first;S t(std::max(3, 4) + 1)andR rr{std::min(5, 6) + 0};s.substr(std::min(1, 2), std::max(2, 3));const int &r = read(std::min(4, 5));with a value-returningread;std::maxoverstd::stringtemporaries, which needs nontrivial result copying;read(std::min(0, 1)),return read(std::max(2, 3)), and the same pattern in a mem-initializer.Testing
Linux Release
ninja check: lit ontests/unit,tests/std,tests/ubandtests/multi-filereports 645 passed, 33 expected failures, no unexpected failures and no skips, compared with 644 passed and the same 33 expected failures on the base. Cargo reports 78 libcc2rs unit tests passed, 1 libcc2rs-macros compile-fail test passed and 22 control-flow tests passed, with no failures or ignored tests.The original fixture, before adding the assignment cases, fails on the base with 58 refcount rustc errors (E0015, E0277, E0599) and 24 unsafe errors (E0015, E0133). The expanded fixture compiles and matches native execution in both models. clang-format 23 reports no changes for the changed C++ files.
To ask for a change, comment or review in plain words.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.