Skip to content

Destroy heap array elements in reverse order - #684

Merged
nunoplopes merged 3 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-e57emj8t1z
Nov 26, 2026
Merged

nunoplopes merged 3 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-e57emj8t1z

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Heap delete[] calls nontrivial element destructors in forward order in both output models, so later elements can be torn down after objects they depend on. The generated loops now run from the last index to the first, before releasing the allocation.

cc @lucic71 @nunoplopes

The fixture in tests/unit/delete_array_order.cpp allocates three records with id/value pairs 1:10, 2:20, and 3:30. Native C++ prints 3:30 2:20 1:10; the prior translations printed the opposite order. Both translations now match native output, retaining each element's stored value.

The change reverses the existing ranges rather than introducing another destruction mechanism. Argument evaluation, element-count calculation, and deallocation calls are unchanged. Scalar deletion and trivial element handling are unchanged too. Both generated Rust expectations accompany the new fixture.

The unsafe model still infers array lengths from allocator size; padding and zero-length allocation handling are unchanged.

The scoped Debug and Release lit runs each passed 8 tests, with 0 failures and 0 skips, covering heap allocation/deletion, destructor handling, and the new order fixture in both models. Clang-format and generated-Rust formatting checks passed.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@nunoplopes
nunoplopes merged commit c8becea into Cpp2Rust:master Nov 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants