Skip to content

Commit 39d4faf

Browse files
committed
Auto merge of #27025 - dotdash:issue-26484, r=pnkfelix
See the commits for details r? @arielb1
2 parents 4e51763 + 3d65c7f commit 39d4faf

File tree

4 files changed

+84
-28
lines changed

4 files changed

+84
-28
lines changed

src/librustc_trans/trans/debuginfo/metadata.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,31 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
796796
}
797797
}
798798
ty::TyBareFn(_, ref barefnty) => {
799-
subroutine_type_metadata(cx, unique_type_id, &barefnty.sig, usage_site_span)
799+
let fn_metadata = subroutine_type_metadata(cx,
800+
unique_type_id,
801+
&barefnty.sig,
802+
usage_site_span).metadata;
803+
match debug_context(cx).type_map
804+
.borrow()
805+
.find_metadata_for_unique_id(unique_type_id) {
806+
Some(metadata) => return metadata,
807+
None => { /* proceed normally */ }
808+
};
809+
810+
// This is actually a function pointer, so wrap it in pointer DI
811+
MetadataCreationResult::new(pointer_type_metadata(cx, t, fn_metadata), false)
812+
800813
}
801814
ty::TyClosure(def_id, substs) => {
802815
let infcx = infer::normalizing_infer_ctxt(cx.tcx(), &cx.tcx().tables);
803-
let sig = infcx.closure_type(def_id, substs).sig;
804-
subroutine_type_metadata(cx, unique_type_id, &sig, usage_site_span)
816+
let upvars = infcx.closure_upvars(def_id, substs).unwrap();
817+
let upvar_types = upvars.iter().map(|u| u.ty).collect::<Vec<_>>();
818+
819+
prepare_tuple_metadata(cx,
820+
t,
821+
&upvar_types[..],
822+
unique_type_id,
823+
usage_site_span).finalize(cx)
805824
}
806825
ty::TyStruct(def_id, substs) => {
807826
prepare_struct_metadata(cx,
@@ -920,7 +939,7 @@ pub fn scope_metadata(fcx: &FunctionContext,
920939
}
921940
}
922941

923-
fn diverging_type_metadata(cx: &CrateContext) -> DIType {
942+
pub fn diverging_type_metadata(cx: &CrateContext) -> DIType {
924943
unsafe {
925944
llvm::LLVMDIBuilderCreateBasicType(
926945
DIB(cx),

src/librustc_trans/trans/debuginfo/mod.rs

+37-23
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use self::utils::{DIB, span_start, assert_type_for_node_id, contains_nodebug_att
1818
create_DIArray, is_node_local_to_unit};
1919
use self::namespace::{namespace_for_item, NamespaceTreeNode};
2020
use self::type_names::compute_debuginfo_type_name;
21-
use self::metadata::{type_metadata, file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
21+
use self::metadata::{type_metadata, diverging_type_metadata};
22+
use self::metadata::{file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
2223
use self::source_loc::InternalDebugLocation;
2324

2425
use llvm;
@@ -29,8 +30,8 @@ use middle::subst::{self, Substs};
2930
use rustc::ast_map;
3031
use trans::common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
3132
use trans;
32-
use trans::monomorphize;
33-
use middle::ty::Ty;
33+
use trans::{monomorphize, type_of};
34+
use middle::ty::{self, Ty};
3435
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
3536
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
3637

@@ -40,7 +41,7 @@ use std::ffi::CString;
4041
use std::ptr;
4142
use std::rc::Rc;
4243
use syntax::codemap::{Span, Pos};
43-
use syntax::{ast, codemap, ast_util};
44+
use syntax::{abi, ast, codemap, ast_util};
4445
use syntax::attr::IntType;
4546
use syntax::parse::token::{self, special_idents};
4647

@@ -325,7 +326,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
325326
let function_type_metadata = unsafe {
326327
let fn_signature = get_function_signature(cx,
327328
fn_ast_id,
328-
&*fn_decl,
329329
param_substs,
330330
span);
331331
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
@@ -402,35 +402,49 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
402402

403403
fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
404404
fn_ast_id: ast::NodeId,
405-
fn_decl: &ast::FnDecl,
406405
param_substs: &Substs<'tcx>,
407406
error_reporting_span: Span) -> DIArray {
408407
if cx.sess().opts.debuginfo == LimitedDebugInfo {
409408
return create_DIArray(DIB(cx), &[]);
410409
}
411410

412-
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
413-
414411
// Return type -- llvm::DIBuilder wants this at index 0
415412
assert_type_for_node_id(cx, fn_ast_id, error_reporting_span);
416-
let return_type = cx.tcx().node_id_to_type(fn_ast_id);
417-
let return_type = monomorphize::apply_param_substs(cx.tcx(),
418-
param_substs,
419-
&return_type);
420-
if return_type.is_nil() {
421-
signature.push(ptr::null_mut())
413+
let fn_type = cx.tcx().node_id_to_type(fn_ast_id);
414+
415+
let (sig, abi) = match fn_type.sty {
416+
ty::TyBareFn(_, ref barefnty) => {
417+
(cx.tcx().erase_late_bound_regions(&barefnty.sig), barefnty.abi)
418+
}
419+
ty::TyClosure(def_id, substs) => {
420+
let closure_type = cx.tcx().closure_type(def_id, substs);
421+
(cx.tcx().erase_late_bound_regions(&closure_type.sig), closure_type.abi)
422+
}
423+
424+
_ => cx.sess().bug("get_function_metdata: Expected a function type!")
425+
};
426+
let sig = monomorphize::apply_param_substs(cx.tcx(), param_substs, &sig);
427+
428+
let mut signature = Vec::with_capacity(sig.inputs.len() + 1);
429+
430+
// Return type -- llvm::DIBuilder wants this at index 0
431+
signature.push(match sig.output {
432+
ty::FnConverging(ret_ty) => match ret_ty.sty {
433+
ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
434+
_ => type_metadata(cx, ret_ty, codemap::DUMMY_SP)
435+
},
436+
ty::FnDiverging => diverging_type_metadata(cx)
437+
});
438+
439+
let inputs = &if abi == abi::RustCall {
440+
type_of::untuple_arguments(cx, &sig.inputs)
422441
} else {
423-
signature.push(type_metadata(cx, return_type, codemap::DUMMY_SP));
424-
}
442+
sig.inputs
443+
};
425444

426445
// Arguments types
427-
for arg in &fn_decl.inputs {
428-
assert_type_for_node_id(cx, arg.pat.id, arg.pat.span);
429-
let arg_type = cx.tcx().node_id_to_type(arg.pat.id);
430-
let arg_type = monomorphize::apply_param_substs(cx.tcx(),
431-
param_substs,
432-
&arg_type);
433-
signature.push(type_metadata(cx, arg_type, codemap::DUMMY_SP));
446+
for &argument_type in inputs {
447+
signature.push(type_metadata(cx, argument_type, codemap::DUMMY_SP));
434448
}
435449

436450
return create_DIArray(DIB(cx), &signature[..]);

src/test/debuginfo/basic-types-metadata.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
// gdb-check:type = f32
4343
// gdb-command:whatis f64
4444
// gdb-check:type = f64
45+
// gdb-command:whatis fnptr
46+
// gdb-check:type = [...] (*)([...])
4547
// gdb-command:info functions _yyy
46-
// gdb-check:[...]![...]_yyy([...])([...]);
48+
// gdb-check:[...]![...]_yyy([...]);
4749
// gdb-command:continue
4850

4951
#![allow(unused_variables)]
@@ -65,6 +67,7 @@ fn main() {
6567
let u64: u64 = 64;
6668
let f32: f32 = 2.5;
6769
let f64: f64 = 3.5;
70+
let fnptr : fn() = _zzz;
6871
_zzz(); // #break
6972
if 1 == 1 { _yyy(); }
7073
}

src/test/run-pass/issue-26484.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-g
12+
13+
fn helper<F: FnOnce(usize) -> bool>(_f: F) {
14+
print!("");
15+
}
16+
17+
fn main() {
18+
let cond = 0;
19+
helper(|v| v == cond)
20+
}

0 commit comments

Comments
 (0)