Use DefId instead of NodeId while generating debuginfo for statics.
This commit is contained in:
parent
27a046e933
commit
d5ed655a08
5 changed files with 14 additions and 28 deletions
|
@ -304,7 +304,7 @@ pub fn trans_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
debuginfo::create_global_var_metadata(cx, id, g);
|
||||
debuginfo::create_global_var_metadata(cx, def_id, g);
|
||||
|
||||
if attr::contains_name(attrs, "thread_local") {
|
||||
llvm::set_thread_local_mode(g, cx.tls_model);
|
||||
|
|
|
@ -14,7 +14,7 @@ use self::EnumDiscriminantInfo::*;
|
|||
|
||||
use super::utils::{debug_context, DIB, span_start,
|
||||
get_namespace_for_item, create_DIArray, is_node_local_to_unit};
|
||||
use super::namespace::mangled_name_of_item;
|
||||
use super::namespace::mangled_name_of_instance;
|
||||
use super::type_names::compute_debuginfo_type_name;
|
||||
use super::{CrateDebugContext};
|
||||
use abi;
|
||||
|
@ -1634,19 +1634,18 @@ fn create_union_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
///
|
||||
/// Adds the created metadata nodes directly to the crate's IR.
|
||||
pub fn create_global_var_metadata(cx: &CodegenCx,
|
||||
node_id: ast::NodeId,
|
||||
def_id: DefId,
|
||||
global: ValueRef) {
|
||||
if cx.dbg_cx.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let tcx = cx.tcx;
|
||||
let node_def_id = tcx.hir.local_def_id(node_id);
|
||||
let no_mangle = attr::contains_name(&tcx.get_attrs(node_def_id), "no_mangle");
|
||||
let no_mangle = attr::contains_name(&tcx.get_attrs(def_id), "no_mangle");
|
||||
// We may want to remove the namespace scope if we're in an extern block, see:
|
||||
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952
|
||||
let var_scope = get_namespace_for_item(cx, node_def_id);
|
||||
let span = cx.tcx.def_span(node_def_id);
|
||||
let var_scope = get_namespace_for_item(cx, def_id);
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
|
||||
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
|
||||
let loc = span_start(cx, span);
|
||||
|
@ -1655,15 +1654,15 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
|
|||
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
|
||||
};
|
||||
|
||||
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
|
||||
let variable_type = Instance::mono(cx.tcx, node_def_id).ty(cx.tcx);
|
||||
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
|
||||
let variable_type = Instance::mono(cx.tcx, def_id).ty(cx.tcx);
|
||||
let type_metadata = type_metadata(cx, variable_type, span);
|
||||
let var_name = tcx.item_name(node_def_id).to_string();
|
||||
let var_name = tcx.item_name(def_id).to_string();
|
||||
let var_name = CString::new(var_name).unwrap();
|
||||
let linkage_name = if no_mangle {
|
||||
None
|
||||
} else {
|
||||
let linkage_name = mangled_name_of_item(cx, node_id);
|
||||
let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id));
|
||||
Some(CString::new(linkage_name.to_string()).unwrap())
|
||||
};
|
||||
|
||||
|
|
|
@ -254,14 +254,14 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
let linkage_name = mangled_name_of_instance(cx, instance);
|
||||
|
||||
let scope_line = span_start(cx, span).line;
|
||||
|
||||
let local_id = cx.tcx.hir.as_local_node_id(instance.def_id());
|
||||
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
|
||||
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
|
||||
|
||||
let function_name = CString::new(name).unwrap();
|
||||
let linkage_name = CString::new(linkage_name.to_string()).unwrap();
|
||||
|
||||
let mut flags = DIFlags::FlagPrototyped;
|
||||
|
||||
let local_id = cx.tcx.hir.as_local_node_id(def_id);
|
||||
match *cx.sess().entry_fn.borrow() {
|
||||
Some((id, _)) => {
|
||||
if local_id == Some(id) {
|
||||
|
|
|
@ -14,7 +14,6 @@ use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
|
|||
use super::utils::{DIB, debug_context};
|
||||
use monomorphize::Instance;
|
||||
use rustc::ty;
|
||||
use syntax::ast;
|
||||
|
||||
use llvm;
|
||||
use llvm::debuginfo::DIScope;
|
||||
|
@ -33,16 +32,6 @@ pub fn mangled_name_of_instance<'a, 'tcx>(
|
|||
tcx.symbol_name(instance)
|
||||
}
|
||||
|
||||
pub fn mangled_name_of_item<'a, 'tcx>(
|
||||
cx: &CodegenCx<'a, 'tcx>,
|
||||
node_id: ast::NodeId,
|
||||
) -> ty::SymbolName {
|
||||
let tcx = cx.tcx;
|
||||
let node_def_id = tcx.hir.local_def_id(node_id);
|
||||
let instance = Instance::mono(tcx, node_def_id);
|
||||
tcx.symbol_name(instance)
|
||||
}
|
||||
|
||||
pub fn item_namespace(cx: &CodegenCx, def_id: DefId) -> DIScope {
|
||||
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
|
||||
return scope;
|
||||
|
|
|
@ -21,9 +21,8 @@ use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
|
|||
use common::{CodegenCx};
|
||||
|
||||
use syntax_pos::{self, Span};
|
||||
use syntax::ast;
|
||||
|
||||
pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
|
||||
pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
|
||||
{
|
||||
// The is_local_to_unit flag indicates whether a function is local to the
|
||||
// current compilation unit (i.e. if it is *static* in the C-sense). The
|
||||
|
@ -33,7 +32,6 @@ pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
|
|||
// visible). It might better to use the `exported_items` set from
|
||||
// `driver::CrateAnalysis` in the future, but (atm) this set is not
|
||||
// available in the translation pass.
|
||||
let def_id = cx.tcx.hir.local_def_id(node_id);
|
||||
!cx.tcx.is_exported_symbol(def_id)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue