Repository navigation
Commit fd959c9
authored
Rollup merge of #163121 - Amanieu:inline-dest-rawptr, r=saethlin
Borrow the destination place with a raw pointer in MIR inlining
Background: if the destination place in the caller involves a `Deref` or `Index` projection then the inliner will capture a mutable reference to the destination place before the call and write back the return value using that pointer at the end of the call. This is necessary because such projections are unstable and may cause the place to evaluate to a different location at the end of the call.
However the use of `&mut` instead of `&raw mut` causes 2 problems:
1. Because call arguments are copied after the destination place is evaluated, if the same place is present in an argument and the destination then it would invalidate the destination reference, causing the later write through it to be UB.
2. Creating a mutable reference to an uninhabited type is immediate UB according to rust-lang/unsafe-code-guidelines#413, and this is enforced by Miri.
While the first issue could be addressed by using two-phased borrows or by copying arguments beforehand, a raw pointer is the only way to handle the second. It's also not possible to special-case uninhabited types since it may not be possible to determine whether the destination is inhabited in generic code.
r? wg-mir-opt2 files changed
Lines changed: 58 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
886 | 886 | | |
887 | 887 | | |
888 | 888 | | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
901 | 894 | | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
| 895 | + | |
907 | 896 | | |
908 | 897 | | |
909 | 898 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
0 commit comments