bors
f676c20edd
Auto merge of #155343 - dianqk:indirect-by-ref, r=nikic
...
codegen: Copy to an alloca when the argument is neither by-val nor by-move for indirect pointer.
Fixes https://github.com/rust-lang/rust/issues/155241 .
When a value is passed via an indirect pointer, the value needs to be copied to a new alloca. For x86_64-unknown-linux-gnu, `Thing` is the case:
```rust
#[derive(Clone, Copy)]
struct Thing(usize, usize, usize);
pub fn foo() {
let thing = Thing(0, 0, 0);
bar(thing);
assert_eq!(thing.0, 0);
}
#[inline(never)]
#[unsafe(no_mangle)]
pub fn bar(mut thing: Thing) {
thing.0 = 1;
}
```
Before passing the thing to the bar function, the thing needs to be copied to an alloca that is passed to bar.
```llvm
%0 = alloca [24 x i8], align 8
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %thing, i64 24, i1 false)
call void @bar(ptr %0)
```
This patch applies the rule to the untupled arguments as well.
```rust
#![feature(fn_traits)]
#[derive(Clone, Copy)]
struct Thing(usize, usize, usize);
#[inline(never)]
#[unsafe(no_mangle)]
pub fn foo() {
let thing = (Thing(0, 0, 0),);
(|mut thing: Thing| {
thing.0 = 1;
}).call(thing);
assert_eq!(thing.0.0, 0);
}
```
For this case, this patch changes from
```llvm
; call example::foo::{closure#0}
call void @_RNCNvCs15qdZVLwHPA_7example3foo0B3_(ptr ..., ptr %thing)
```
to
```llvm
%0 = alloca [24 x i8], align 8
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %thing, i64 24, i1 false)
; call example::foo::{closure#0}
call void @_RNCNvCs15qdZVLwHPA_7example3foo0B3_(ptr ..., ptr %0)
```
However, the same rule cannot be applied to tail calls that would be unsound, because the caller's stack frame is overwritten by the callee's stack frame. Fortunately, https://github.com/rust-lang/rust/pull/151143 has already handled the special case. We must not copy again.
No copy is needed for by-move arguments, because the argument is passed to the called "in-place".
No copy is also needed for by-val arguments, because the attribute implies that a hidden copy of the pointee is made between the caller and the callee.
NOTE: The patch has a trick for tail calls that we pass by-move. We can choose to copy an alloca even for by-move arguments, but tail calls require MUST-by-move.
2026-04-22 15:47:21 +00:00
..
2025-11-06 15:39:45 -08:00
2025-12-05 08:37:22 -06:00
2026-03-02 23:30:45 -05:00
2025-07-22 14:28:48 +02:00
2025-11-08 10:57:35 -07:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-11-02 16:20:06 +01:00
2025-12-18 19:12:09 -05:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-04-09 09:42:47 +01:00
2026-03-08 10:22:26 -03:00
2025-07-22 14:28:48 +02:00
2026-04-20 19:15:52 +02:00
2026-01-26 13:43:06 -06:00
2026-01-12 11:03:07 +01:00
2025-07-22 14:28:48 +02:00
2026-02-17 20:16:29 +00:00
2026-04-19 16:04:29 +02:00
2026-03-12 16:45:42 -07:00
2026-01-20 16:26:15 +08:00
2026-01-25 16:27:23 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2026-04-16 11:37:45 +02:00
2025-07-22 14:28:48 +02:00
2026-01-13 15:21:20 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2026-03-12 16:45:42 -07:00
2026-04-01 12:38:55 +00:00
2026-04-03 10:37:42 +00:00
2026-02-03 22:44:44 +01:00
2026-03-18 15:17:56 +01:00
2025-07-22 14:28:48 +02:00
2025-09-11 16:13:32 -07:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2026-01-26 12:43:52 +00:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-02-27 12:08:59 -08:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2026-01-21 23:39:03 +00:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-11-20 19:23:10 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-02-09 15:53:38 -05:00
2025-09-09 21:54:54 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-01-20 14:47:04 +01:00
2026-01-09 10:41:37 +01:00
2025-07-22 14:28:48 +02:00
2026-03-13 11:54:06 +00:00
2025-07-22 14:28:48 +02:00
2026-04-03 22:31:45 +00:00
2025-11-19 11:55:09 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-08-15 16:42:21 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-09-01 13:45:00 +07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-08-15 16:56:11 +00:00
2025-07-22 14:28:48 +02:00
2026-02-12 09:58:25 +01:00
2025-07-26 01:02:29 +02:00
2026-02-02 18:45:26 -05:00
2025-11-19 11:55:09 +00:00
2025-08-21 11:07:25 +01:00
2025-07-22 14:28:48 +02:00
2025-08-01 18:38:22 +01:00
2025-07-22 14:28:48 +02:00
2026-02-14 01:39:16 -08:00
2025-10-13 16:52:12 +00:00
2026-02-25 21:31:51 +08:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2026-04-22 17:37:17 +08:00
2025-07-22 14:28:48 +02:00
2026-02-10 12:39:45 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-21 18:48:04 +08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-21 13:04:48 -06:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-19 13:19:22 +04:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-29 11:20:23 -07:00
2025-07-22 14:28:48 +02:00
2025-11-19 11:55:09 +00:00
2025-07-22 14:28:48 +02:00
2025-10-10 20:14:23 -04:00
2025-09-16 11:49:20 -07:00
2025-09-16 11:49:20 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-04-22 17:37:17 +08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-09-13 16:06:22 -07:00
2026-03-12 16:45:42 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-10-02 14:55:50 +08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-27 14:42:07 +03:00
2026-02-27 12:08:59 -08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-11-02 16:20:06 +01:00
2025-09-05 20:44:49 -04:00
2026-01-20 16:26:15 +08:00
2025-07-29 18:59:09 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-02-20 20:22:31 -08:00
2025-07-22 14:28:48 +02:00
2025-07-29 11:20:23 -07:00
2025-07-22 14:28:48 +02:00
2025-12-03 14:34:07 -08:00
2025-10-23 00:38:28 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2026-03-29 02:11:32 -05:00
2025-07-22 14:28:48 +02:00
2026-03-05 11:53:38 +01:00
2025-11-02 16:20:06 +01:00
2025-08-06 18:01:07 +00:00
2025-07-22 14:28:48 +02:00
2026-03-13 10:17:20 -04:00
2025-09-23 10:21:17 +02:00
2026-03-17 10:51:31 +01:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2026-04-22 17:37:17 +08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-04-14 03:25:02 +05:30
2025-11-26 13:31:26 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-09 09:18:23 +00:00
2025-07-22 14:28:48 +02:00
2025-10-10 20:14:23 -04:00
2025-09-16 11:49:20 -07:00
2025-08-21 11:07:25 +01:00
2025-07-22 14:28:48 +02:00
2025-09-21 20:37:51 -04:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-02 15:18:55 +01:00
2025-07-22 14:28:48 +02:00
2025-08-11 22:00:41 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-04-16 12:29:39 +00:00
2026-02-24 08:33:15 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-05 11:53:38 +01:00
2025-11-23 08:23:49 -05:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-11-19 11:55:09 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-03 08:12:16 -06:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-21 13:04:48 -06:00
2026-03-12 16:45:42 -07:00
2025-07-22 14:28:48 +02:00
2026-02-11 20:42:35 -06:00
2025-07-22 14:28:48 +02:00
2026-03-31 09:06:31 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-09-23 10:59:29 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-19 11:55:09 +00:00
2026-01-24 19:23:17 +02:00
2026-04-13 13:26:50 +02:00
2026-04-03 03:22:19 +02:00
2026-03-13 10:17:20 -04:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-10-31 16:12:30 -07:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-07 10:42:02 -08:00
2025-11-02 16:20:06 +01:00
2025-08-18 19:37:13 +00:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2025-11-06 12:49:48 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-01-05 05:17:56 +09:00
2025-10-31 16:12:30 -07:00
2025-07-22 14:28:48 +02:00
2025-11-21 13:04:48 -06:00
2025-11-21 13:04:48 -06:00
2025-12-21 00:58:00 +00:00
2026-03-13 10:17:20 -04:00
2025-09-16 11:49:20 -07:00
2025-10-31 16:12:30 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-10-31 16:12:30 -07:00
2025-08-21 11:07:25 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-02-02 16:47:09 +05:30
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-12-31 15:22:07 +01:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-09-16 11:49:20 -07:00
2026-02-27 10:51:55 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-11-02 16:20:06 +01:00
2026-04-01 21:29:42 -05:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-11-02 16:20:06 +01:00
2025-09-16 11:49:20 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-29 11:20:23 -07:00
2025-11-19 13:19:22 +04:00
2025-07-22 14:28:48 +02:00
2025-08-18 19:37:13 +00:00
2025-11-23 08:23:49 -05:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-05 11:53:38 +01:00
2025-09-11 16:13:32 -07:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-09-26 13:32:03 -04:00
2025-07-22 14:28:48 +02:00
2026-03-12 16:45:42 -07:00
2025-07-22 14:28:48 +02:00
2026-03-03 19:46:06 -08:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-09-26 13:32:03 -04:00
2025-11-21 13:04:48 -06:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00
2026-03-05 11:53:38 +01:00
2025-07-22 14:28:48 +02:00
2025-10-30 15:13:32 +03:00
2025-07-22 14:28:48 +02:00
2025-07-22 14:28:48 +02:00