Skip to content

Commit 03c8b92

Browse files
committed
Auto merge of #42803 - michaelwoerister:msdia-workaround, r=vadimcn
debuginfo: Work around crash-bug in MSDIA library Fixes #40477 (which also contains a description of the issue being fixed). r? @vadimcn
2 parents efdf55d + 8261413 commit 03c8b92

File tree

1 file changed

+27
-3
lines changed
  • src/librustc_trans/debuginfo

1 file changed

+27
-3
lines changed

src/librustc_trans/debuginfo/mod.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::ptr;
4343
use syntax_pos::{self, Span, Pos};
4444
use syntax::ast;
4545
use syntax::symbol::Symbol;
46-
use rustc::ty::layout;
46+
use rustc::ty::layout::{self, LayoutTyper};
4747

4848
pub mod gdb;
4949
mod utils;
@@ -320,8 +320,32 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
320320
};
321321

322322
// Arguments types
323-
for &argument_type in inputs {
324-
signature.push(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP));
323+
if cx.sess().target.target.options.is_like_msvc {
324+
// FIXME(#42800):
325+
// There is a bug in MSDIA that leads to a crash when it encounters
326+
// a fixed-size array of `u8` or something zero-sized in a
327+
// function-type (see #40477).
328+
// As a workaround, we replace those fixed-size arrays with a
329+
// pointer-type. So a function `fn foo(a: u8, b: [u8; 4])` would
330+
// appear as `fn foo(a: u8, b: *const u8)` in debuginfo,
331+
// and a function `fn bar(x: [(); 7])` as `fn bar(x: *const ())`.
332+
// This transformed type is wrong, but these function types are
333+
// already inaccurate due to ABI adjustments (see #42800).
334+
signature.extend(inputs.iter().map(|&t| {
335+
let t = match t.sty {
336+
ty::TyArray(ct, _)
337+
if (ct == cx.tcx().types.u8) ||
338+
(cx.layout_of(ct).size(cx).bytes() == 0) => {
339+
cx.tcx().mk_imm_ptr(ct)
340+
}
341+
_ => t
342+
};
343+
type_metadata(cx, t, syntax_pos::DUMMY_SP)
344+
}));
345+
} else {
346+
signature.extend(inputs.iter().map(|t| {
347+
type_metadata(cx, t, syntax_pos::DUMMY_SP)
348+
}));
325349
}
326350

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

0 commit comments

Comments
 (0)