Skip to content

debuginfo: Work around crash-bug in MSDIA library #42803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2017
Merged
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
30 changes: 27 additions & 3 deletions src/librustc_trans/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::ptr;
use syntax_pos::{self, Span, Pos};
use syntax::ast;
use syntax::symbol::Symbol;
use rustc::ty::layout;
use rustc::ty::layout::{self, LayoutTyper};

pub mod gdb;
mod utils;
Expand Down Expand Up @@ -320,8 +320,32 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
};

// Arguments types
for &argument_type in inputs {
signature.push(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP));
if cx.sess().target.target.options.is_like_msvc {
// FIXME(#42800):
// There is a bug in MSDIA that leads to a crash when it encounters
// a fixed-size array of `u8` or something zero-sized in a
// function-type (see #40477).
// As a workaround, we replace those fixed-size arrays with a
// pointer-type. So a function `fn foo(a: u8, b: [u8; 4])` would
// appear as `fn foo(a: u8, b: *const u8)` in debuginfo,
// and a function `fn bar(x: [(); 7])` as `fn bar(x: *const ())`.
// This transformed type is wrong, but these function types are
// already inaccurate due to ABI adjustments (see #42800).
signature.extend(inputs.iter().map(|&t| {
let t = match t.sty {
ty::TyArray(ct, _)
if (ct == cx.tcx().types.u8) ||
(cx.layout_of(ct).size(cx).bytes() == 0) => {
cx.tcx().mk_imm_ptr(ct)
}
_ => t
};
type_metadata(cx, t, syntax_pos::DUMMY_SP)
}));
} else {
signature.extend(inputs.iter().map(|t| {
type_metadata(cx, t, syntax_pos::DUMMY_SP)
}));
}

if sig.abi == Abi::RustCall && !sig.inputs().is_empty() {
Expand Down