You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- apply suggestions from code review
- include note about backends no overriding `va_end` and `va_copy` in
the doc comment.
- link to where `va_copy` is lowered to `memcpy`
Co-authored-by: Ralf Jung <post@ralfj.de>
Copy file name to clipboardExpand all lines: library/core/src/ffi/va_list.rs
+22-6Lines changed: 22 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,10 @@ use crate::marker::PhantomCovariantLifetime;
34
34
//
35
35
// The Clang `BuiltinVaListKind` enumerates the `va_list` variations that Clang supports,
36
36
// and we mirror these here.
37
+
//
38
+
// For all current LLVM targets, `va_copy` lowers to `memcpy`. Hence the inner structs below all
39
+
// derive `Copy`. However, in the future we might want to support a target where `va_copy`
40
+
// allocates, or otherwise violates the requirements of `Copy`. Therefore `VaList` is only `Clone`.
37
41
crate::cfg_select! {
38
42
all(
39
43
target_arch = "aarch64",
@@ -45,6 +49,8 @@ crate::cfg_select! {
45
49
///
46
50
/// See the [AArch64 Procedure Call Standard] for more details.
47
51
///
52
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L12682-L12700>
/// See the [LLVM source] and [GCC header] for more details.
64
70
///
71
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/PowerPC/PPCISelLowering.cpp#L3755-L3764>
/// See the [S/390x ELF Application Binary Interface Supplement] for more details.
83
91
///
92
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp#L4457-L4472>
/// See the [System V AMD64 ABI] for more details.
100
110
///
111
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/X86/X86ISelLowering.cpp#26319>
112
+
/// (github won't render that file, look for `SDValue LowerVACOPY`)
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/Xtensa/XtensaISelLowering.cpp#L1260>
/// See the [LLVM source] for more details. On bare metal Hexagon uses an opaque pointer.
134
149
///
150
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/5aee01a3df011e660f26660bc30a8c94a1651d8e/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp#L1087-L1102>
// That pointer is probably just the next variadic argument on the caller's stack.
157
174
_ => {
158
175
/// Basic implementation of a `va_list`.
176
+
///
177
+
/// `va_copy` is `memcpy`: <https://github.com/llvm/llvm-project/blob/87e8e7d8f0db53060ef2f6ef4ab612fc0f2b4490/llvm/lib/Transforms/IPO/ExpandVariadics.cpp#L127-L129>
159
178
#[repr(transparent)]
160
179
#[derive(Debug,Clone,Copy)]
161
180
structVaListInner{
@@ -190,12 +209,9 @@ impl Clone for VaList<'_> {
190
209
#[inline]
191
210
fnclone(&self) -> Self{
192
211
// We only implement Clone and not Copy because some future target might not be able to
193
-
// implement Copy (e.g. because it allocates).
194
-
195
-
// We still use a `va_copy` intrinsic to provide a hook for const evaluation. The hook is
196
-
// used to report UB when a variable argument list is duplicated with a manual `memcpy`.
197
-
// While that works in practice for all current targets, we want to be able to support
198
-
// targets in the future where that is not the case.
212
+
// implement Copy (e.g. because it allocates). For the same reason we use an intrinsic
213
+
// to do the copying: the fact that on all current targets, this is just `memcpy`, is an implementation
214
+
// detail. The intrinsic lets Miri catch UB from code incorrectly relying on that implementation detail.
0 commit comments