Skip to content

[DRAFT] codegen: Copy to an alloca when the argument is neither by-val nor by-move for indirect pointer.#155343

Draft
dianqk wants to merge 1 commit intorust-lang:mainfrom
dianqk:indirect-by-ref
Draft

[DRAFT] codegen: Copy to an alloca when the argument is neither by-val nor by-move for indirect pointer.#155343
dianqk wants to merge 1 commit intorust-lang:mainfrom
dianqk:indirect-by-ref

Conversation

@dianqk
Copy link
Copy Markdown
Member

@dianqk dianqk commented Apr 15, 2026

Fixes #155241.

We should always copy to an alloca when passing the argument indirectly via a hidden pointer; the only exception is for by-val or by-move.

I haven't added test cases yet.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2026
self.codegen_argument(
bx,
op,
// Pass by-move for an explicit tail call, which has been handled above as well.
Copy link
Copy Markdown
Member Author

@dianqk dianqk Apr 15, 2026

Choose a reason for hiding this comment

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

This feels a bit awkward; perhaps the tail call handling can be moved into codegen_argument as well.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The issue has nothing to do with tail calls, does it...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. #151143 works well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But this PR is changing something about tail calls...?

Maybe it's just the comment that is confusing me. Why is it okay to always to by-move for tail call arguments? Cc @folkertdev

// CHECK: call void @test_simd(<4 x i32> <i32 2, i32 4, i32 6, i32 8>
test_simd(const { Simd::<i32, 4>([2, 4, 6, 8]) });

// CHECK: call void @test_simd_unaligned(%"minisimd::PackedSimd<i32, 3>" %1
Copy link
Copy Markdown
Member Author

@dianqk dianqk Apr 15, 2026

Choose a reason for hiding this comment

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

A redundant memcpy is skipped here.

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

release-mode heap corruption with non-generic FnOnce(Vec<usize>)

3 participants