pub fn create_global_var_metadata(
    cx: &CodegenCx<'ll, '_>,
    def_id: DefId,
    global: &'ll Value,
) {
    if cx.dbg_cx.is_none() {
        return;
    }

    let tcx = cx.tcx;
    let attrs = tcx.codegen_fn_attrs(def_id);

    if attrs.flags.contains(CodegenFnAttrFlags::NO_DEBUG) {
        return;
    }

    let no_mangle = attrs.flags.contains(CodegenFnAttrFlags::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, def_id);
    let span = tcx.def_span(def_id);

    let (file_metadata, line_number) = if !span.is_dummy() {
        let loc = span_start(cx, span);
        (file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
    } else {
        (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
    };

    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 = SmallCStr::new(&tcx.item_name(def_id).as_str());
    let linkage_name = if no_mangle {
        None
    } else {
        let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id));
        Some(SmallCStr::new(&linkage_name.as_str()))
    };

    let global_align = cx.align_of(variable_type);

    unsafe {
        llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
                                                    Some(var_scope),
                                                    var_name.as_ptr(),
                                                    // If null, linkage_name field is omitted,
                                                    // which is what we want for no_mangle statics
                                                    linkage_name.as_ref()
                                                     .map_or(ptr::null(), |name| name.as_ptr()),
                                                    file_metadata,
                                                    line_number,
                                                    type_metadata,
                                                    is_local_to_unit,
                                                    global,
                                                    None,
                                                    global_align.abi() as u32,
        );
    }
}
/// Creates debug information for the given global variable.
///
/// Adds the created metadata nodes directly to the crate's IR.
Creates debug information for the given global variable.
Adds the created metadata nodes directly to the crate's IR.
Creates debug information for the given global variable . Adds the created metadata nodes directly to the crate ' s IR .
pub fn create_global_var_metadata(
    cx: &CodegenCx<'ll, '_>,
    def_id: DefId,
    global: &'ll Value,
) {
    if cx.dbg_cx.is_none() {
        return;
    }
    let tcx = cx.tcx;
    let attrs = tcx.codegen_fn_attrs(def_id);
    if attrs.flags.contains(CodegenFnAttrFlags::NO_DEBUG) {
        return;
    }
    let no_mangle = attrs.flags.contains(CodegenFnAttrFlags::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, def_id);
    let span = tcx.def_span(def_id);
    let (file_metadata, line_number) = if !span.is_dummy() {
        let loc = span_start(cx, span);
        (file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line as c_uint)
    } else {
        (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
    };
    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 = SmallCStr::new(&tcx.item_name(def_id).as_str());
    let linkage_name = if no_mangle {
        None
    } else {
        let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id));
        Some(SmallCStr::new(&linkage_name.as_str()))
    };
    let global_align = cx.align_of(variable_type);
    unsafe {
        llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
                                                    Some(var_scope),
                                                    var_name.as_ptr(),
                                                    // If null, linkage_name field is omitted,
                                                    // which is what we want for no_mangle statics
                                                    linkage_name.as_ref()
                                                     .map_or(ptr::null(), |name| name.as_ptr()),
                                                    file_metadata,
                                                    line_number,
                                                    type_metadata,
                                                    is_local_to_unit,
                                                    global,
                                                    None,
                                                    global_align.abi() as u32,
        );
    }
}
pub fn create_global_var_metadata ( cx : & CodegenCx < ' ll , ' _ > , def_id : DefId , global : & ' ll Value , ) { if cx . dbg_cx . is_none ( ) { return ; } let tcx = cx . tcx ; let attrs = tcx . codegen_fn_attrs ( def_id ) ; if attrs . flags . contains ( CodegenFnAttrFlags :: NO_DEBUG ) { return ; } let no_mangle = attrs . flags . contains ( CodegenFnAttrFlags :: 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 , def_id ) ; let span = tcx . def_span ( def_id ) ; let ( file_metadata , line_number ) = if ! span . is_dummy ( ) { let loc = span_start ( cx , span ) ; ( file_metadata ( cx , & loc . file . name , LOCAL_CRATE ) , loc . line as c_uint ) } else { ( unknown_file_metadata ( cx ) , UNKNOWN_LINE_NUMBER ) } ; 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 = SmallCStr :: new ( & tcx . item_name ( def_id ) . as_str ( ) ) ; let linkage_name = if no_mangle { None } else { let linkage_name = mangled_name_of_instance ( cx , Instance :: mono ( tcx , def_id ) ) ; Some ( SmallCStr :: new ( & linkage_name . as_str ( ) ) ) } ; let global_align = cx . align_of ( variable_type ) ; unsafe { llvm :: LLVMRustDIBuilderCreateStaticVariable ( DIB ( cx ) , Some ( var_scope ) , var_name . as_ptr ( ) , // If null, linkage_name field is omitted, // which is what we want for no_mangle statics linkage_name . as_ref ( ) . map_or ( ptr :: null ( ) , | name | name . as_ptr ( ) ) , file_metadata , line_number , type_metadata , is_local_to_unit , global , None , global_align . abi ( ) as u32 , ) ; } }
Creates debug information for the given global variable.
Creates debug information for the given global variable .
cx
&CodegenCx<'ll, '_>
def_id
DefId
global
&'ll Value
cx
&CodegenCx<'ll, '_>
def_id
DefId
global
&'ll Value