Skip to content

Commit eed48f5

Browse files
committed
rustc_codegen_llvm: use safe references for Metadata and DI*.
1 parent 6d0d82c commit eed48f5

File tree

12 files changed

+411
-377
lines changed

12 files changed

+411
-377
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use super::ModuleKind;
3131
use abi;
3232
use back::link;
3333
use back::write::{self, OngoingCodegen};
34-
use llvm::{ValueRef, Vector, get_param};
34+
use llvm::{TypeKind, ValueRef, get_param};
3535
use llvm;
3636
use metadata;
3737
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -349,10 +349,10 @@ fn cast_shift_rhs<'ll, F, G>(op: hir::BinOpKind,
349349
if op.is_shift() {
350350
let mut rhs_llty = val_ty(rhs);
351351
let mut lhs_llty = val_ty(lhs);
352-
if rhs_llty.kind() == Vector {
352+
if rhs_llty.kind() == TypeKind::Vector {
353353
rhs_llty = rhs_llty.element_type()
354354
}
355-
if lhs_llty.kind() == Vector {
355+
if lhs_llty.kind() == TypeKind::Vector {
356356
lhs_llty = lhs_llty.element_type()
357357
}
358358
let rhs_sz = rhs_llty.int_width();

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use super::metadata::file_metadata;
1313
use super::utils::{DIB, span_start};
1414

1515
use llvm;
16-
use llvm::debuginfo::DIScope_opaque;
16+
use llvm::debuginfo::DIScope;
1717
use common::CodegenCx;
1818
use rustc::mir::{Mir, SourceScope};
19-
use std::ptr::NonNull;
2019

2120
use libc::c_uint;
2221

@@ -28,24 +27,24 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2827
use syntax_pos::BytePos;
2928

3029
#[derive(Clone, Copy, Debug)]
31-
pub struct MirDebugScope {
32-
pub scope_metadata: Option<NonNull<DIScope_opaque>>,
30+
pub struct MirDebugScope<'ll> {
31+
pub scope_metadata: Option<&'ll DIScope>,
3332
// Start and end offsets of the file to which this DIScope belongs.
3433
// These are used to quickly determine whether some span refers to the same file.
3534
pub file_start_pos: BytePos,
3635
pub file_end_pos: BytePos,
3736
}
3837

39-
impl MirDebugScope {
38+
impl MirDebugScope<'ll> {
4039
pub fn is_valid(&self) -> bool {
4140
!self.scope_metadata.is_none()
4241
}
4342
}
4443

4544
/// Produce DIScope DIEs for each MIR Scope which has variables defined in it.
4645
/// If debuginfo is disabled, the returned vector is empty.
47-
pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
48-
-> IndexVec<SourceScope, MirDebugScope> {
46+
pub fn create_mir_scopes(cx: &CodegenCx<'ll, '_>, mir: &Mir, debug_context: &FunctionDebugContext<'ll>)
47+
-> IndexVec<SourceScope, MirDebugScope<'ll>> {
4948
let null_scope = MirDebugScope {
5049
scope_metadata: None,
5150
file_start_pos: BytePos(0),
@@ -77,12 +76,12 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
7776
scopes
7877
}
7978

80-
fn make_mir_scope(cx: &CodegenCx,
79+
fn make_mir_scope(cx: &CodegenCx<'ll, '_>,
8180
mir: &Mir,
8281
has_variables: &BitVector<SourceScope>,
83-
debug_context: &FunctionDebugContextData,
82+
debug_context: &FunctionDebugContextData<'ll>,
8483
scope: SourceScope,
85-
scopes: &mut IndexVec<SourceScope, MirDebugScope>) {
84+
scopes: &mut IndexVec<SourceScope, MirDebugScope<'ll>>) {
8685
if scopes[scope].is_valid() {
8786
return;
8887
}
@@ -95,7 +94,7 @@ fn make_mir_scope(cx: &CodegenCx,
9594
// The root is the function itself.
9695
let loc = span_start(cx, mir.span);
9796
scopes[scope] = MirDebugScope {
98-
scope_metadata: NonNull::new(debug_context.fn_metadata),
97+
scope_metadata: Some(debug_context.fn_metadata),
9998
file_start_pos: loc.file.start_pos,
10099
file_end_pos: loc.file.end_pos,
101100
};
@@ -109,7 +108,7 @@ fn make_mir_scope(cx: &CodegenCx,
109108
// However, we don't skip creating a nested scope if
110109
// our parent is the root, because we might want to
111110
// put arguments in the root and not have shadowing.
112-
if parent_scope.scope_metadata.unwrap().as_ptr() != debug_context.fn_metadata {
111+
if parent_scope.scope_metadata.unwrap() != debug_context.fn_metadata {
113112
scopes[scope] = parent_scope;
114113
return;
115114
}
@@ -121,9 +120,9 @@ fn make_mir_scope(cx: &CodegenCx,
121120
debug_context.defining_crate);
122121

123122
let scope_metadata = unsafe {
124-
NonNull::new(llvm::LLVMRustDIBuilderCreateLexicalBlock(
123+
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
125124
DIB(cx),
126-
parent_scope.scope_metadata.unwrap().as_ptr(),
125+
parent_scope.scope_metadata.unwrap(),
127126
file_metadata,
128127
loc.line as c_uint,
129128
loc.col.to_usize() as c_uint))

0 commit comments

Comments
 (0)