Skip to content

Commit

Permalink
Require #[repr(C)] on MiriFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Sep 26, 2020
1 parent 5857365 commit 2a2a93d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ extern "Rust" {
/// and `MiriFrame` should be declared as follows:
///
/// ```rust
/// #[repr(C)]
/// struct MiriFrame {
/// // The name of the function being executed, encoded in UTF-8
/// name: Box<[u8]>,
Expand Down
9 changes: 7 additions & 2 deletions src/shims/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;
use helpers::check_arg_count;
use rustc_middle::ty::TypeAndMut;
use rustc_middle::ty::{self, TypeAndMut};
use rustc_ast::ast::Mutability;
use rustc_span::BytePos;
use rustc_target::abi::Size;
Expand Down Expand Up @@ -105,7 +105,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let lineno_alloc = Scalar::from_u32(lineno);
let colno_alloc = Scalar::from_u32(colno);

let dest = this.force_allocation_maybe_sized(dest, MemPlaceMeta::None)?.0;
let dest = this.force_allocation(dest)?;
if let ty::Adt(adt, _) = dest.layout.ty.kind() {
if !adt.repr.c() {
throw_ub_format!("miri_resolve_frame must be declared with a `#[repr(C)]` return type");
}
}

this.write_immediate(name_alloc.to_ref(), this.mplace_field(dest, 0)?.into())?;
this.write_immediate(filename_alloc.to_ref(), this.mplace_field(dest, 1)?.into())?;
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/backtrace-api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "Rust" {
}

#[derive(Debug)]
#[repr(C)]
struct MiriFrame {
name: Box<[u8]>,
filename: Box<[u8]>,
Expand Down
8 changes: 4 additions & 4 deletions tests/run-pass/backtrace-api.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$DIR/backtrace-api.rs:19:59 (func_c)
$DIR/backtrace-api.rs:18:53 (func_b::<u8>)
$DIR/backtrace-api.rs:17:50 (func_a)
$DIR/backtrace-api.rs:23:18 (main)
$DIR/backtrace-api.rs:20:59 (func_c)
$DIR/backtrace-api.rs:19:53 (func_b::<u8>)
$DIR/backtrace-api.rs:18:50 (func_a)
$DIR/backtrace-api.rs:24:18 (main)
RUSTLIB/src/rust/library/core/src/ops/function.rs:LL:COL (<fn() as std::ops::FnOnce<()>>::call_once - shim(fn()))
RUSTLIB/src/rust/library/std/src/sys_common/backtrace.rs:LL:COL (std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>)
RUSTLIB/src/rust/library/std/src/rt.rs:LL:COL (std::rt::lang_start::<()>::{{closure}}#0)
Expand Down
8 changes: 4 additions & 4 deletions tests/run-pass/backtrace-api.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$DIR/backtrace-api.rs:19:59 (func_c)
$DIR/backtrace-api.rs:18:53 (func_b::<u8>)
$DIR/backtrace-api.rs:17:50 (func_a)
$DIR/backtrace-api.rs:23:18 (main)
$DIR/backtrace-api.rs:20:59 (func_c)
$DIR/backtrace-api.rs:19:53 (func_b::<u8>)
$DIR/backtrace-api.rs:18:50 (func_a)
$DIR/backtrace-api.rs:24:18 (main)

0 comments on commit 2a2a93d

Please sign in to comment.