diff options
| author | Irina Popa <irinagpopa@gmail.com> | 2018-07-10 13:28:39 +0300 |
|---|---|---|
| committer | Irina Popa <irinagpopa@gmail.com> | 2018-07-30 19:49:18 +0300 |
| commit | f375185314e94a266f76ad7ffdd61b2d4608e97d (patch) | |
| tree | d6c6c5916c94c03cac0f1de43b1626bf495bec69 /src/librustc_codegen_llvm/debuginfo | |
| parent | 8d1768434168875e9ce2d4273ca1ed9e6f69d18f (diff) | |
| download | rust-f375185314e94a266f76ad7ffdd61b2d4608e97d.tar.gz rust-f375185314e94a266f76ad7ffdd61b2d4608e97d.zip | |
rustc_codegen_llvm: use safe references for Value.
Diffstat (limited to 'src/librustc_codegen_llvm/debuginfo')
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/gdb.rs | 13 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/metadata.rs | 21 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/mod.rs | 12 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/debuginfo/source_loc.rs | 3 |
4 files changed, 26 insertions, 23 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/gdb.rs b/src/librustc_codegen_llvm/debuginfo/gdb.rs index de43a4522cc..08128a729b5 100644 --- a/src/librustc_codegen_llvm/debuginfo/gdb.rs +++ b/src/librustc_codegen_llvm/debuginfo/gdb.rs @@ -15,8 +15,9 @@ use llvm; use common::{C_bytes, CodegenCx, C_i32}; use builder::Builder; use declare; -use type_::Type; use rustc::session::config::NoDebugInfo; +use type_::Type; +use value::Value; use syntax::attr; @@ -39,8 +40,8 @@ pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &Builder) { /// Allocates the global variable responsible for the .debug_gdb_scripts binary /// section. -pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx) - -> llvm::ValueRef { +pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) + -> &'ll Value { let c_section_var_name = "__rustc_debug_gdb_scripts_section__\0"; let section_var_name = &c_section_var_name[..c_section_var_name.len()-1]; @@ -49,7 +50,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx) c_section_var_name.as_ptr() as *const _) }; - if section_var.is_null() { + section_var.unwrap_or_else(|| { let section_name = b".debug_gdb_scripts\0"; let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0"; @@ -71,9 +72,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx) llvm::LLVMSetAlignment(section_var, 1); section_var } - } else { - section_var - } + }) } pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx) -> bool { diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index ae2e350dc65..69ef92ed98e 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -18,8 +18,9 @@ use super::namespace::mangled_name_of_instance; use super::type_names::compute_debuginfo_type_name; use super::{CrateDebugContext}; use abi; +use value::Value; -use llvm::{self, ValueRef}; +use llvm; use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType, DILexicalBlock, DIFlags}; @@ -890,7 +891,7 @@ pub fn compile_unit_metadata(tcx: TyCtxt, return unit_metadata; }; - fn path_to_mdstring(llcx: &llvm::Context, path: &Path) -> llvm::ValueRef { + fn path_to_mdstring(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value { let path_str = path2cstr(path); unsafe { llvm::LLVMMDStringInContext(llcx, @@ -1679,9 +1680,11 @@ fn create_union_stub( /// 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, - def_id: DefId, - global: ValueRef) { +pub fn create_global_var_metadata( + cx: &CodegenCx<'ll, '_>, + def_id: DefId, + global: &'ll Value, +) { if cx.dbg_cx.is_none() { return; } @@ -1759,9 +1762,11 @@ pub fn extend_scope_to_file( /// given type. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, - ty: ty::Ty<'tcx>, - vtable: ValueRef) { +pub fn create_vtable_metadata( + cx: &CodegenCx<'ll, 'tcx>, + ty: ty::Ty<'tcx>, + vtable: &'ll Value, +) { if cx.dbg_cx.is_none() { return; } diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 27a4c60b36d..3b6b7b2d77b 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -21,7 +21,6 @@ use self::metadata::{type_metadata, file_metadata, TypeMap}; use self::source_loc::InternalDebugLocation::{self, UnknownLocation}; use llvm; -use llvm::ValueRef; use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilder, DISubprogram, DIArray, DIFlags}; use rustc::hir::CodegenFnAttrFlags; use rustc::hir::def_id::{DefId, CrateNum}; @@ -35,6 +34,7 @@ use rustc::ty::{self, ParamEnv, Ty, InstanceDef}; use rustc::mir; use rustc::session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet}; +use value::Value; use libc::c_uint; use std::cell::{Cell, RefCell}; @@ -135,12 +135,12 @@ pub struct FunctionDebugContextData<'ll> { pub defining_crate: CrateNum, } -pub enum VariableAccess<'a> { +pub enum VariableAccess<'a, 'll> { // The llptr given is an alloca containing the variable's value - DirectVariable { alloca: ValueRef }, + DirectVariable { alloca: &'ll Value }, // The llptr given is an alloca containing the start of some pointer chain // leading to the variable's content. - IndirectVariable { alloca: ValueRef, address_operations: &'a [i64] } + IndirectVariable { alloca: &'ll Value, address_operations: &'a [i64] } } pub enum VariableKind { @@ -204,7 +204,7 @@ pub fn create_function_debug_context( cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>, sig: ty::FnSig<'tcx>, - llfn: ValueRef, + llfn: &'ll Value, mir: &mir::Mir, ) -> FunctionDebugContext<'ll> { if cx.sess().opts.debuginfo == NoDebugInfo { @@ -482,7 +482,7 @@ pub fn declare_local( variable_name: ast::Name, variable_type: Ty<'tcx>, scope_metadata: &'ll DIScope, - variable_access: VariableAccess, + variable_access: VariableAccess<'_, 'll>, variable_kind: VariableKind, span: Span, ) { diff --git a/src/librustc_codegen_llvm/debuginfo/source_loc.rs b/src/librustc_codegen_llvm/debuginfo/source_loc.rs index ae117ffd3ec..55cf1393943 100644 --- a/src/librustc_codegen_llvm/debuginfo/source_loc.rs +++ b/src/librustc_codegen_llvm/debuginfo/source_loc.rs @@ -19,7 +19,6 @@ use llvm::debuginfo::DIScope; use builder::Builder; use libc::c_uint; -use std::ptr::NonNull; use syntax_pos::{Span, Pos}; /// Sets the current debug location at the beginning of the span. @@ -96,7 +95,7 @@ pub fn set_debug_location(bx: &Builder<'_, 'll, '_>, debug_location: InternalDeb debug!("setting debug location to {} {}", line, col); unsafe { - NonNull::new(llvm::LLVMRustDIBuilderCreateDebugLocation( + Some(llvm::LLVMRustDIBuilderCreateDebugLocation( debug_context(bx.cx).llcontext, line as c_uint, col_used, |
