Skip to content

Commit af04e94

Browse files
committed
rustc_codegen_llvm: move from empty enums to extern types.
1 parent 077be49 commit af04e94

File tree

18 files changed

+178
-197
lines changed

18 files changed

+178
-197
lines changed

src/librustc_codegen_llvm/allocator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::ffi::CString;
12-
use std::ptr;
1312

1413
use attributes;
1514
use libc::c_uint;
@@ -90,7 +89,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind
9089
callee,
9190
args.as_ptr(),
9291
args.len() as c_uint,
93-
ptr::null_mut(),
92+
None,
9493
"\0".as_ptr() as *const _);
9594
llvm::LLVMSetTailCall(ret, True);
9695
if output.is_some() {

src/librustc_codegen_llvm/back/archive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::ffi::{CString, CStr};
1414
use std::io;
1515
use std::mem;
1616
use std::path::{Path, PathBuf};
17-
use std::ptr;
17+
use std::ptr::{self, NonNull};
1818
use std::str;
1919

2020
use back::bytecode::RLIB_BYTECODE_EXTENSION;
@@ -246,7 +246,7 @@ impl<'a> ArchiveBuilder<'a> {
246246
let name = CString::new(child_name)?;
247247
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
248248
name.as_ptr(),
249-
child.raw()));
249+
NonNull::new(child.raw())));
250250
strings.push(name);
251251
}
252252
}
@@ -257,7 +257,7 @@ impl<'a> ArchiveBuilder<'a> {
257257
let name = CString::new(name_in_archive)?;
258258
members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
259259
name.as_ptr(),
260-
ptr::null_mut()));
260+
None));
261261
strings.push(path);
262262
strings.push(name);
263263
}
@@ -284,7 +284,7 @@ impl<'a> ArchiveBuilder<'a> {
284284
let name = CString::new(child_name)?;
285285
let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
286286
name.as_ptr(),
287-
child.raw());
287+
NonNull::new(child.raw()));
288288
members.push(m);
289289
strings.push(name);
290290
}

src/librustc_codegen_llvm/builder.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::borrow::Cow;
2626
use std::ffi::CString;
2727
use std::ops::Range;
2828
use std::ptr;
29+
use std::ptr::NonNull;
2930
use syntax_pos::Span;
3031

3132
// All Builders must have an llfn associated with them
@@ -211,7 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
211212
.join(", "));
212213

213214
let args = self.check_call("invoke", llfn, args);
214-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
215+
let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
215216

216217
unsafe {
217218
llvm::LLVMRustBuildInvoke(self.llbuilder,
@@ -909,7 +910,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
909910
.join(", "));
910911

911912
let args = self.check_call("call", llfn, args);
912-
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
913+
let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
913914

914915
unsafe {
915916
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@@ -1196,7 +1197,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11961197
parent: Option<ValueRef>,
11971198
args: &[ValueRef]) -> ValueRef {
11981199
self.count_insn("cleanuppad");
1199-
let parent = parent.unwrap_or(ptr::null_mut());
1200+
let parent = parent.and_then(NonNull::new);
12001201
let name = CString::new("cleanuppad").unwrap();
12011202
let ret = unsafe {
12021203
llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@@ -1212,7 +1213,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12121213
pub fn cleanup_ret(&self, cleanup: ValueRef,
12131214
unwind: Option<BasicBlockRef>) -> ValueRef {
12141215
self.count_insn("cleanupret");
1215-
let unwind = unwind.unwrap_or(ptr::null_mut());
1216+
let unwind = unwind.and_then(NonNull::new);
12161217
let ret = unsafe {
12171218
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
12181219
};
@@ -1248,8 +1249,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12481249
unwind: Option<BasicBlockRef>,
12491250
num_handlers: usize) -> ValueRef {
12501251
self.count_insn("catchswitch");
1251-
let parent = parent.unwrap_or(ptr::null_mut());
1252-
let unwind = unwind.unwrap_or(ptr::null_mut());
1252+
let parent = parent.and_then(NonNull::new);
1253+
let unwind = unwind.and_then(NonNull::new);
12531254
let name = CString::new("catchswitch").unwrap();
12541255
let ret = unsafe {
12551256
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

src/librustc_codegen_llvm/context.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_target::spec::{HasTargetSpec, Target};
3535

3636
use std::ffi::{CStr, CString};
3737
use std::cell::{Cell, RefCell};
38-
use std::ptr;
3938
use std::iter;
4039
use std::str;
4140
use std::sync::Arc;
@@ -280,7 +279,9 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
280279
None
281280
};
282281

283-
let mut cx = CodegenCx {
282+
let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
283+
284+
CodegenCx {
284285
tcx,
285286
check_overflow,
286287
use_dll_storage_attrs,
@@ -300,16 +301,14 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
300301
lltypes: RefCell::new(FxHashMap()),
301302
scalar_lltypes: RefCell::new(FxHashMap()),
302303
pointee_infos: RefCell::new(FxHashMap()),
303-
isize_ty: Type::from_ref(ptr::null_mut()),
304+
isize_ty,
304305
dbg_cx,
305306
eh_personality: Cell::new(None),
306307
eh_unwind_resume: Cell::new(None),
307308
rust_try_fn: Cell::new(None),
308309
intrinsics: RefCell::new(FxHashMap()),
309310
local_gen_sym_counter: Cell::new(0),
310-
};
311-
cx.isize_ty = Type::isize(&cx);
312-
cx
311+
}
313312
}
314313
}
315314

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

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

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

2021
use libc::c_uint;
21-
use std::ptr;
2222

2323
use syntax_pos::Pos;
2424

@@ -29,7 +29,7 @@ use syntax_pos::BytePos;
2929

3030
#[derive(Clone, Copy, Debug)]
3131
pub struct MirDebugScope {
32-
pub scope_metadata: DIScope,
32+
pub scope_metadata: Option<NonNull<DIScope_opaque>>,
3333
// Start and end offsets of the file to which this DIScope belongs.
3434
// These are used to quickly determine whether some span refers to the same file.
3535
pub file_start_pos: BytePos,
@@ -38,7 +38,7 @@ pub struct MirDebugScope {
3838

3939
impl MirDebugScope {
4040
pub fn is_valid(&self) -> bool {
41-
!self.scope_metadata.is_null()
41+
!self.scope_metadata.is_none()
4242
}
4343
}
4444

@@ -47,7 +47,7 @@ impl MirDebugScope {
4747
pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
4848
-> IndexVec<SourceScope, MirDebugScope> {
4949
let null_scope = MirDebugScope {
50-
scope_metadata: ptr::null_mut(),
50+
scope_metadata: None,
5151
file_start_pos: BytePos(0),
5252
file_end_pos: BytePos(0)
5353
};
@@ -95,7 +95,7 @@ fn make_mir_scope(cx: &CodegenCx,
9595
// The root is the function itself.
9696
let loc = span_start(cx, mir.span);
9797
scopes[scope] = MirDebugScope {
98-
scope_metadata: debug_context.fn_metadata,
98+
scope_metadata: NonNull::new(debug_context.fn_metadata),
9999
file_start_pos: loc.file.start_pos,
100100
file_end_pos: loc.file.end_pos,
101101
};
@@ -109,7 +109,7 @@ fn make_mir_scope(cx: &CodegenCx,
109109
// However, we don't skip creating a nested scope if
110110
// our parent is the root, because we might want to
111111
// put arguments in the root and not have shadowing.
112-
if parent_scope.scope_metadata != debug_context.fn_metadata {
112+
if parent_scope.scope_metadata.unwrap().as_ptr() != debug_context.fn_metadata {
113113
scopes[scope] = parent_scope;
114114
return;
115115
}
@@ -121,12 +121,12 @@ fn make_mir_scope(cx: &CodegenCx,
121121
debug_context.defining_crate);
122122

123123
let scope_metadata = unsafe {
124-
llvm::LLVMRustDIBuilderCreateLexicalBlock(
124+
NonNull::new(llvm::LLVMRustDIBuilderCreateLexicalBlock(
125125
DIB(cx),
126-
parent_scope.scope_metadata,
126+
parent_scope.scope_metadata.unwrap().as_ptr(),
127127
file_metadata,
128128
loc.line as c_uint,
129-
loc.col.to_usize() as c_uint)
129+
loc.col.to_usize() as c_uint))
130130
};
131131
scopes[scope] = MirDebugScope {
132132
scope_metadata,

src/librustc_codegen_llvm/debuginfo/gdb.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use declare;
1818
use type_::Type;
1919
use rustc::session::config::NoDebugInfo;
2020

21-
use std::ptr;
2221
use syntax::attr;
2322

2423

@@ -50,7 +49,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx)
5049
c_section_var_name.as_ptr() as *const _)
5150
};
5251

53-
if section_var == ptr::null_mut() {
52+
if section_var.is_null() {
5453
let section_name = b".debug_gdb_scripts\0";
5554
let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0";
5655

0 commit comments

Comments
 (0)