Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let mplace = ecx.force_allocation(&place)?;

// Consume the remaining arguments by putting them into the variable argument
// list.
let varargs = ecx.allocate_varargs(&mut caller_args, &mut callee_args_abis)?;
// list. We disable retagging to avoid creating protected tags. Protection should
// only use callee-side information, and the varargs have no static callee-side type.
let varargs = M::with_retag_mode(ecx, RetagMode::None, |ecx| {
ecx.allocate_varargs(&mut caller_args, &mut callee_args_abis)
})?;

// When the frame is dropped, these variable arguments are deallocated.
ecx.frame_mut().va_list = varargs.clone();
let key = ecx.va_list_ptr(varargs.into());
Expand Down
21 changes: 21 additions & 0 deletions src/tools/miri/tests/pass/both_borrows/c_variadics.rs

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.

Why is this just a TB test? It also applies to SB, doesn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup - I adjusted the test and moved it over to both_borrows.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@revisions: stack tree tree_implicit_writes
//@[tree_implicit_writes]compile-flags: -Zmiri-tree-borrows -Zmiri-tree-borrows-implicit-writes
//@[tree]compile-flags: -Zmiri-tree-borrows
#![feature(c_variadic)]

fn main() {
Comment thread
icmccorm marked this conversation as resolved.
unsafe extern "C" fn write_with_first_arg(
ptr_to_val: *mut i32,
_hidden_mut_ref_to_val: ...
) {
// Retagging needs to be disabled for arguments
// within the VaList. Otherwise, this write access
// will be undefined behavior.
unsafe { *ptr_to_val = 32; }
}

let mut val: i32 = 0;
unsafe {
write_with_first_arg(&raw mut val, &val);
}
}
Loading