]> git.lizzy.rs Git - rust.git/commitdiff
rustc_codegen_llvm: move from empty enums to extern types.
authorIrina Popa <irinagpopa@gmail.com>
Wed, 27 Jun 2018 10:12:47 +0000 (13:12 +0300)
committerIrina Popa <irinagpopa@gmail.com>
Mon, 30 Jul 2018 15:12:47 +0000 (18:12 +0300)
18 files changed:
src/librustc_codegen_llvm/allocator.rs
src/librustc_codegen_llvm/back/archive.rs
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/context.rs
src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
src/librustc_codegen_llvm/debuginfo/gdb.rs
src/librustc_codegen_llvm/debuginfo/metadata.rs
src/librustc_codegen_llvm/debuginfo/mod.rs
src/librustc_codegen_llvm/debuginfo/namespace.rs
src/librustc_codegen_llvm/debuginfo/source_loc.rs
src/librustc_codegen_llvm/debuginfo/utils.rs
src/librustc_codegen_llvm/lib.rs
src/librustc_codegen_llvm/llvm/diagnostic.rs
src/librustc_codegen_llvm/llvm/ffi.rs
src/librustc_codegen_llvm/mir/mod.rs
src/librustc_codegen_llvm/mir/operand.rs
src/librustc_codegen_llvm/mir/place.rs
src/librustc_codegen_llvm/type_.rs

index eeb02e948f1ccbd7ec4471091e537e3ab5a607d7..49cdbf34fa95a6ac19e95e30a13ac2654eb78032 100644 (file)
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use std::ffi::CString;
-use std::ptr;
 
 use attributes;
 use libc::c_uint;
@@ -90,7 +89,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind
                                           callee,
                                           args.as_ptr(),
                                           args.len() as c_uint,
-                                          ptr::null_mut(),
+                                          None,
                                           "\0".as_ptr() as *const _);
         llvm::LLVMSetTailCall(ret, True);
         if output.is_some() {
index b99835cb5c64932876420447f871020f0ce4bdd9..4ea97911830c7aefa8b39adec53d2f46ced8405b 100644 (file)
@@ -14,7 +14,7 @@
 use std::io;
 use std::mem;
 use std::path::{Path, PathBuf};
-use std::ptr;
+use std::ptr::{self, NonNull};
 use std::str;
 
 use back::bytecode::RLIB_BYTECODE_EXTENSION;
@@ -246,7 +246,7 @@ fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
                     let name = CString::new(child_name)?;
                     members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
                                                                 name.as_ptr(),
-                                                                child.raw()));
+                                                                NonNull::new(child.raw())));
                     strings.push(name);
                 }
             }
@@ -257,7 +257,7 @@ fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
                         let name = CString::new(name_in_archive)?;
                         members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
                                                                     name.as_ptr(),
-                                                                    ptr::null_mut()));
+                                                                    None));
                         strings.push(path);
                         strings.push(name);
                     }
@@ -284,7 +284,7 @@ fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
                             let name = CString::new(child_name)?;
                             let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
                                                                    name.as_ptr(),
-                                                                   child.raw());
+                                                                   NonNull::new(child.raw()));
                             members.push(m);
                             strings.push(name);
                         }
index b34d0f1cd9070854c013d58fcfa43c1c7a220570..5f460a14ef9879914e4d15a33504c4811f81a5ca 100644 (file)
@@ -26,6 +26,7 @@
 use std::ffi::CString;
 use std::ops::Range;
 use std::ptr;
+use std::ptr::NonNull;
 use syntax_pos::Span;
 
 // All Builders must have an llfn associated with them
@@ -211,7 +212,7 @@ pub fn invoke(&self,
                    .join(", "));
 
         let args = self.check_call("invoke", llfn, args);
-        let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
+        let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
 
         unsafe {
             llvm::LLVMRustBuildInvoke(self.llbuilder,
@@ -909,7 +910,7 @@ pub fn call(&self, llfn: ValueRef, args: &[ValueRef],
                    .join(", "));
 
         let args = self.check_call("call", llfn, args);
-        let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
+        let bundle = bundle.as_ref().and_then(|b| NonNull::new(b.raw()));
 
         unsafe {
             llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@@ -1196,7 +1197,7 @@ pub fn cleanup_pad(&self,
                        parent: Option<ValueRef>,
                        args: &[ValueRef]) -> ValueRef {
         self.count_insn("cleanuppad");
-        let parent = parent.unwrap_or(ptr::null_mut());
+        let parent = parent.and_then(NonNull::new);
         let name = CString::new("cleanuppad").unwrap();
         let ret = unsafe {
             llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@@ -1212,7 +1213,7 @@ pub fn cleanup_pad(&self,
     pub fn cleanup_ret(&self, cleanup: ValueRef,
                        unwind: Option<BasicBlockRef>) -> ValueRef {
         self.count_insn("cleanupret");
-        let unwind = unwind.unwrap_or(ptr::null_mut());
+        let unwind = unwind.and_then(NonNull::new);
         let ret = unsafe {
             llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
         };
@@ -1248,8 +1249,8 @@ pub fn catch_switch(&self,
                         unwind: Option<BasicBlockRef>,
                         num_handlers: usize) -> ValueRef {
         self.count_insn("catchswitch");
-        let parent = parent.unwrap_or(ptr::null_mut());
-        let unwind = unwind.unwrap_or(ptr::null_mut());
+        let parent = parent.and_then(NonNull::new);
+        let unwind = unwind.and_then(NonNull::new);
         let name = CString::new("catchswitch").unwrap();
         let ret = unsafe {
             llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,
index b774d7c5def217a9a17f5bc501bc8ef60cdb7d07..130e14c976dee2817cacb1125838425c505843f4 100644 (file)
@@ -35,7 +35,6 @@
 
 use std::ffi::{CStr, CString};
 use std::cell::{Cell, RefCell};
-use std::ptr;
 use std::iter;
 use std::str;
 use std::sync::Arc;
@@ -280,7 +279,9 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                 None
             };
 
-            let mut cx = CodegenCx {
+            let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
+
+            CodegenCx {
                 tcx,
                 check_overflow,
                 use_dll_storage_attrs,
@@ -300,16 +301,14 @@ pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                 lltypes: RefCell::new(FxHashMap()),
                 scalar_lltypes: RefCell::new(FxHashMap()),
                 pointee_infos: RefCell::new(FxHashMap()),
-                isize_ty: Type::from_ref(ptr::null_mut()),
+                isize_ty,
                 dbg_cx,
                 eh_personality: Cell::new(None),
                 eh_unwind_resume: Cell::new(None),
                 rust_try_fn: Cell::new(None),
                 intrinsics: RefCell::new(FxHashMap()),
                 local_gen_sym_counter: Cell::new(0),
-            };
-            cx.isize_ty = Type::isize(&cx);
-            cx
+            }
         }
     }
 
index fcde7f9bbc33d8c1cc3681aaf049f5256d4b373d..dc92363a83354e2d79fc5ab056ed605a27662e4c 100644 (file)
 use super::utils::{DIB, span_start};
 
 use llvm;
-use llvm::debuginfo::DIScope;
+use llvm::debuginfo::DIScope_opaque;
 use common::CodegenCx;
 use rustc::mir::{Mir, SourceScope};
+use std::ptr::NonNull;
 
 use libc::c_uint;
-use std::ptr;
 
 use syntax_pos::Pos;
 
@@ -29,7 +29,7 @@
 
 #[derive(Clone, Copy, Debug)]
 pub struct MirDebugScope {
-    pub scope_metadata: DIScope,
+    pub scope_metadata: Option<NonNull<DIScope_opaque>>,
     // Start and end offsets of the file to which this DIScope belongs.
     // These are used to quickly determine whether some span refers to the same file.
     pub file_start_pos: BytePos,
@@ -38,7 +38,7 @@ pub struct MirDebugScope {
 
 impl MirDebugScope {
     pub fn is_valid(&self) -> bool {
-        !self.scope_metadata.is_null()
+        !self.scope_metadata.is_none()
     }
 }
 
@@ -47,7 +47,7 @@ pub fn is_valid(&self) -> bool {
 pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
     -> IndexVec<SourceScope, MirDebugScope> {
     let null_scope = MirDebugScope {
-        scope_metadata: ptr::null_mut(),
+        scope_metadata: None,
         file_start_pos: BytePos(0),
         file_end_pos: BytePos(0)
     };
@@ -95,7 +95,7 @@ fn make_mir_scope(cx: &CodegenCx,
         // The root is the function itself.
         let loc = span_start(cx, mir.span);
         scopes[scope] = MirDebugScope {
-            scope_metadata: debug_context.fn_metadata,
+            scope_metadata: NonNull::new(debug_context.fn_metadata),
             file_start_pos: loc.file.start_pos,
             file_end_pos: loc.file.end_pos,
         };
@@ -109,7 +109,7 @@ fn make_mir_scope(cx: &CodegenCx,
         // However, we don't skip creating a nested scope if
         // our parent is the root, because we might want to
         // put arguments in the root and not have shadowing.
-        if parent_scope.scope_metadata != debug_context.fn_metadata {
+        if parent_scope.scope_metadata.unwrap().as_ptr() != debug_context.fn_metadata {
             scopes[scope] = parent_scope;
             return;
         }
@@ -121,12 +121,12 @@ fn make_mir_scope(cx: &CodegenCx,
                                       debug_context.defining_crate);
 
     let scope_metadata = unsafe {
-        llvm::LLVMRustDIBuilderCreateLexicalBlock(
+        NonNull::new(llvm::LLVMRustDIBuilderCreateLexicalBlock(
             DIB(cx),
-            parent_scope.scope_metadata,
+            parent_scope.scope_metadata.unwrap().as_ptr(),
             file_metadata,
             loc.line as c_uint,
-            loc.col.to_usize() as c_uint)
+            loc.col.to_usize() as c_uint))
     };
     scopes[scope] = MirDebugScope {
         scope_metadata,
index 0b4858c7ab051085350c48fa95fa01d0e05fd5c3..4014ad95b9dd01ade3d0af9d6be03cec3790518b 100644 (file)
@@ -18,7 +18,6 @@
 use type_::Type;
 use rustc::session::config::NoDebugInfo;
 
-use std::ptr;
 use syntax::attr;
 
 
@@ -50,7 +49,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx)
                                  c_section_var_name.as_ptr() as *const _)
     };
 
-    if section_var == ptr::null_mut() {
+    if section_var.is_null() {
         let section_name = b".debug_gdb_scripts\0";
         let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0";
 
index 2f4dd5a7ce5bb0c3887fd46671943db43a995c05..59c14a6910ba2f896d0feefb9ca37cf49da77199 100644 (file)
@@ -20,7 +20,7 @@
 use abi;
 
 use llvm::{self, ValueRef};
-use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
+use llvm::debuginfo::{DIType, DIFile, DIScope_opaque, DIScope, DIDescriptor,
                       DICompositeType, DILexicalBlock, DIFlags};
 
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -41,6 +41,7 @@
 use std::fmt::Write;
 use std::iter;
 use std::ptr;
+use std::ptr::NonNull;
 use std::path::{Path, PathBuf};
 use syntax::ast;
 use syntax::symbol::{Interner, InternedString, Symbol};
@@ -64,8 +65,7 @@
 pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
 pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
 
-// ptr::null() doesn't work :(
-pub const NO_SCOPE_METADATA: DIScope = (0 as DIScope);
+pub const NO_SCOPE_METADATA: Option<NonNull<DIScope_opaque>> = None;
 
 #[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)]
 pub struct UniqueTypeId(ast::Name);
@@ -289,7 +289,7 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
     };
 
     let subrange = unsafe {
-        llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
+        NonNull::new(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound))
     };
 
     let subscripts = create_DIArray(DIB(cx), &[subrange]);
@@ -365,15 +365,17 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
         &signature,
     );
 
-    let signature_metadata: Vec<DIType> = iter::once(
+    let signature_metadata: Vec<_> = iter::once(
         // return type
         match signature.output().sty {
-            ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
-            _ => type_metadata(cx, signature.output(), span)
+            ty::TyTuple(ref tys) if tys.is_empty() => None,
+            _ => NonNull::new(type_metadata(cx, signature.output(), span))
         }
     ).chain(
         // regular arguments
-        signature.inputs().iter().map(|argument_type| type_metadata(cx, argument_type, span))
+        signature.inputs().iter().map(|argument_type| {
+            NonNull::new(type_metadata(cx, argument_type, span))
+        })
     ).collect();
 
     return_if_metadata_created_in_meantime!(cx, unique_type_id);
@@ -406,7 +408,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
     let containing_scope = match trait_type.sty {
         ty::TyDynamic(ref data, ..) => if let Some(principal) = data.principal() {
             let def_id = principal.def_id();
-            get_namespace_for_item(cx, def_id)
+            NonNull::new(get_namespace_for_item(cx, def_id))
         } else {
             NO_SCOPE_METADATA
         },
@@ -985,7 +987,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                                                   struct_type,
                                                   &struct_name,
                                                   unique_type_id,
-                                                  containing_scope);
+                                                  NonNull::new(containing_scope));
 
     create_and_register_recursive_type_forward_declaration(
         cx,
@@ -1317,7 +1319,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                                            layout.ty,
                                            &variant_name,
                                            unique_type_id,
-                                           containing_scope);
+                                           NonNull::new(containing_scope));
 
     // If this is not a univariant enum, there is also the discriminant field.
     let (discr_offset, discr_arg) = match discriminant_info {
@@ -1376,17 +1378,17 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
     let file_metadata = unknown_file_metadata(cx);
 
     let def = enum_type.ty_adt_def().unwrap();
-    let enumerators_metadata: Vec<DIDescriptor> = def.discriminants(cx.tcx)
+    let enumerators_metadata: Vec<_> = def.discriminants(cx.tcx)
         .zip(&def.variants)
         .map(|(discr, v)| {
             let token = v.name.as_str();
             let name = CString::new(token.as_bytes()).unwrap();
             unsafe {
-                llvm::LLVMRustDIBuilderCreateEnumerator(
+                NonNull::new(llvm::LLVMRustDIBuilderCreateEnumerator(
                     DIB(cx),
                     name.as_ptr(),
                     // FIXME: what if enumeration has i128 discriminant?
-                    discr.val as u64)
+                    discr.val as u64))
             }
         })
         .collect();
@@ -1459,7 +1461,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
         enum_type_size.bits(),
         enum_type_align.abi_bits() as u32,
         DIFlags::FlagZero,
-        ptr::null_mut(),
+        None,
         0, // RuntimeLang
         unique_type_id_str.as_ptr())
     };
@@ -1494,7 +1496,7 @@ fn composite_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                                      composite_type_name: &str,
                                      composite_type_unique_id: UniqueTypeId,
                                      member_descriptions: &[MemberDescription],
-                                     containing_scope: DIScope,
+                                     containing_scope: Option<NonNull<DIScope_opaque>>,
 
                                      // Ignore source location information as long as it
                                      // can't be reconstructed for non-local crates.
@@ -1535,13 +1537,13 @@ fn set_members_of_composite_type(cx: &CodegenCx,
         }
     }
 
-    let member_metadata: Vec<DIDescriptor> = member_descriptions
+    let member_metadata: Vec<_> = member_descriptions
         .iter()
         .map(|member_description| {
             let member_name = member_description.name.as_bytes();
             let member_name = CString::new(member_name).unwrap();
             unsafe {
-                llvm::LLVMRustDIBuilderCreateMemberType(
+                NonNull::new(llvm::LLVMRustDIBuilderCreateMemberType(
                     DIB(cx),
                     composite_type_metadata,
                     member_name.as_ptr(),
@@ -1551,7 +1553,7 @@ fn set_members_of_composite_type(cx: &CodegenCx,
                     member_description.align.abi_bits() as u32,
                     member_description.offset.bits(),
                     member_description.flags,
-                    member_description.type_metadata)
+                    member_description.type_metadata))
             }
         })
         .collect();
@@ -1570,7 +1572,7 @@ fn create_struct_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                                 struct_type: Ty<'tcx>,
                                 struct_type_name: &str,
                                 unique_type_id: UniqueTypeId,
-                                containing_scope: DIScope)
+                                containing_scope: Option<NonNull<DIScope_opaque>>)
                                 -> DICompositeType {
     let (struct_size, struct_align) = cx.size_and_align_of(struct_type);
 
@@ -1593,10 +1595,10 @@ fn create_struct_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
             struct_size.bits(),
             struct_align.abi_bits() as u32,
             DIFlags::FlagZero,
-            ptr::null_mut(),
+            None,
             empty_array,
             0,
-            ptr::null_mut(),
+            None,
             unique_type_id.as_ptr())
     };
 
@@ -1630,7 +1632,7 @@ fn create_union_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
             union_size.bits(),
             union_align.abi_bits() as u32,
             DIFlags::FlagZero,
-            empty_array,
+            NonNull::new(empty_array),
             0, // RuntimeLang
             unique_type_id.as_ptr())
     };
@@ -1684,7 +1686,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
 
     unsafe {
         llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
-                                                    var_scope,
+                                                    NonNull::new(var_scope),
                                                     var_name.as_ptr(),
                                                     // If null, linkage_name field is omitted,
                                                     // which is what we want for no_mangle statics
@@ -1695,7 +1697,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
                                                     type_metadata,
                                                     is_local_to_unit,
                                                     global,
-                                                    ptr::null_mut(),
+                                                    None,
                                                     global_align.abi() as u32,
         );
     }
@@ -1749,10 +1751,10 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
             Size::ZERO.bits(),
             cx.tcx.data_layout.pointer_align.abi_bits() as u32,
             DIFlags::FlagArtificial,
-            ptr::null_mut(),
+            None,
             empty_array,
             0,
-            type_metadata,
+            NonNull::new(type_metadata),
             name.as_ptr()
         );
 
@@ -1771,7 +1773,7 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                                                     vtable_type,
                                                     true,
                                                     vtable,
-                                                    ptr::null_mut(),
+                                                    None,
                                                     0);
     }
 }
index 9671db75baffeeb5b4c5db3c38dc57c24e1f1ed4..fcabd27332654c71cb4f359124fc7a4607f7017f 100644 (file)
@@ -39,7 +39,7 @@
 use libc::c_uint;
 use std::cell::{Cell, RefCell};
 use std::ffi::CString;
-use std::ptr;
+use std::ptr::NonNull;
 
 use syntax_pos::{self, Span, Pos};
 use syntax::ast;
@@ -290,7 +290,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
             cx.sess().opts.optimize != config::OptLevel::No,
             llfn,
             template_parameters,
-            ptr::null_mut())
+            None)
     };
 
     // Initialize fn debug context (including scope map and namespace map)
@@ -312,8 +312,8 @@ fn get_function_signature<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
 
         // Return type -- llvm::DIBuilder wants this at index 0
         signature.push(match sig.output().sty {
-            ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(),
-            _ => type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP)
+            ty::TyTuple(ref tys) if tys.is_empty() => None,
+            _ => NonNull::new(type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP))
         });
 
         let inputs = if sig.abi == Abi::RustCall {
@@ -342,19 +342,20 @@ fn get_function_signature<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                     }
                     _ => t
                 };
-                type_metadata(cx, t, syntax_pos::DUMMY_SP)
+                NonNull::new(type_metadata(cx, t, syntax_pos::DUMMY_SP))
             }));
         } else {
             signature.extend(inputs.iter().map(|t| {
-                type_metadata(cx, t, syntax_pos::DUMMY_SP)
+                NonNull::new(type_metadata(cx, t, syntax_pos::DUMMY_SP))
             }));
         }
 
         if sig.abi == Abi::RustCall && !sig.inputs().is_empty() {
             if let ty::TyTuple(args) = sig.inputs()[sig.inputs().len() - 1].sty {
                 signature.extend(
-                    args.iter().map(|argument_type|
-                        type_metadata(cx, argument_type, syntax_pos::DUMMY_SP))
+                    args.iter().map(|argument_type| {
+                        NonNull::new(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP))
+                    })
                 );
             }
         }
@@ -398,14 +399,14 @@ fn get_template_parameters<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
                         type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
                     let name = CString::new(name.as_str().as_bytes()).unwrap();
                     Some(unsafe {
-                        llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
+                        NonNull::new(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
                             DIB(cx),
-                            ptr::null_mut(),
+                            None,
                             name.as_ptr(),
                             actual_type_metadata,
                             file_metadata,
                             0,
-                            0)
+                            0))
                     })
                 } else {
                     None
index 51c45de9dc22a7633f1e8a6bdcaa35d5638acd28..b651f813408a066c56be819e979fe6c104d45282 100644 (file)
@@ -22,7 +22,7 @@
 use common::CodegenCx;
 
 use std::ffi::CString;
-use std::ptr;
+use std::ptr::NonNull;
 
 pub fn mangled_name_of_instance<'a, 'tcx>(
     cx: &CodegenCx<'a, 'tcx>,
@@ -38,11 +38,11 @@ pub fn item_namespace(cx: &CodegenCx, def_id: DefId) -> DIScope {
     }
 
     let def_key = cx.tcx.def_key(def_id);
-    let parent_scope = def_key.parent.map_or(ptr::null_mut(), |parent| {
-        item_namespace(cx, DefId {
+    let parent_scope = def_key.parent.and_then(|parent| {
+        NonNull::new(item_namespace(cx, DefId {
             krate: def_id.krate,
             index: parent
-        })
+        }))
     });
 
     let namespace_name = match def_key.disambiguated_data.data {
index 958d09413edfaed93b4ec343fd3977a62c161243..1a1462da3dd9ce12a096be18ae6bc48b1c47a692 100644 (file)
 use super::FunctionDebugContext;
 
 use llvm;
-use llvm::debuginfo::DIScope;
+use llvm::debuginfo::{DIScope_opaque, DIScope};
 use builder::Builder;
 
 use libc::c_uint;
-use std::ptr;
+use std::ptr::NonNull;
 use syntax_pos::{Span, Pos};
 
 /// Sets the current debug location at the beginning of the span.
 ///
 /// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
 pub fn set_source_location(
-    debug_context: &FunctionDebugContext, bx: &Builder, scope: DIScope, span: Span
+    debug_context: &FunctionDebugContext, bx: &Builder, scope: Option<NonNull<DIScope_opaque>>, span: Span
 ) {
     let function_debug_context = match *debug_context {
         FunctionDebugContext::DebugInfoDisabled => return,
@@ -40,7 +40,7 @@ pub fn set_source_location(
     let dbg_loc = if function_debug_context.source_locations_enabled.get() {
         debug!("set_source_location: {}", bx.sess().codemap().span_to_string(span));
         let loc = span_start(bx.cx, span);
-        InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
+        InternalDebugLocation::new(scope.unwrap().as_ptr(), loc.line, loc.col.to_usize())
     } else {
         UnknownLocation
     };
@@ -93,17 +93,17 @@ pub fn set_debug_location(bx: &Builder, debug_location: InternalDebugLocation) {
             debug!("setting debug location to {} {}", line, col);
 
             unsafe {
-                llvm::LLVMRustDIBuilderCreateDebugLocation(
+                NonNull::new(llvm::LLVMRustDIBuilderCreateDebugLocation(
                     debug_context(bx.cx).llcontext,
                     line as c_uint,
                     col_used,
                     scope,
-                    ptr::null_mut())
+                    None))
             }
         }
         UnknownLocation => {
             debug!("clearing debug location ");
-            ptr::null_mut()
+            None
         }
     };
 
index 9d37f99cb2a591f016538eb0b6bca3d91454f952..87da33166286ff4bdb2157cd99c07cb5344edfdd 100644 (file)
 use rustc::ty::DefIdTree;
 
 use llvm;
-use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
+use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor_opaque, DIArray};
 use common::{CodegenCx};
 
+use std::ptr::NonNull;
 use syntax_pos::{self, Span};
 
 pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
@@ -36,7 +37,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
 }
 
 #[allow(non_snake_case)]
-pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
+pub fn create_DIArray(builder: DIBuilderRef, arr: &[Option<NonNull<DIDescriptor_opaque>>]) -> DIArray {
     return unsafe {
         llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
     };
index 14ec81fc6655b6fe932701d3263224879eee81ed..0b5524990e89c53191984f2ef4103dade8a8cf35 100644 (file)
@@ -21,6 +21,7 @@
 #![feature(box_patterns)]
 #![feature(box_syntax)]
 #![feature(custom_attribute)]
+#![feature(extern_types)]
 #![feature(fs_read_write)]
 #![allow(unused_attributes)]
 #![feature(libc)]
index 0674bccd51e878241029c3f2008a11b620bc18e5..99175864b39a07b85855f5d202d56ccf2bdff177 100644 (file)
@@ -14,7 +14,6 @@
 pub use self::Diagnostic::*;
 
 use libc::c_uint;
-use std::ptr;
 
 use super::{DiagnosticInfoRef, TwineRef, ValueRef};
 
@@ -56,7 +55,7 @@ impl OptimizationDiagnostic {
     unsafe fn unpack(kind: OptimizationDiagnosticKind,
                      di: DiagnosticInfoRef)
                      -> OptimizationDiagnostic {
-        let mut function = ptr::null_mut();
+        let mut function = 0 as *mut _;
         let mut line = 0;
         let mut column = 0;
 
@@ -105,8 +104,8 @@ unsafe fn unpack(di: DiagnosticInfoRef) -> InlineAsmDiagnostic {
 
         let mut opt = InlineAsmDiagnostic {
             cookie: 0,
-            message: ptr::null_mut(),
-            instruction: ptr::null_mut(),
+            message: 0 as *mut _,
+            instruction: 0 as *mut _,
         };
 
         super::LLVMRustUnpackInlineAsmDiagnostic(di,
index afd1070a77ed75e6176610736ab10619a7b01b9d..6e61b327f1d796241612fc97c53c1be8100d9f90 100644 (file)
 // https://reviews.llvm.org/D26769
 
 use super::debuginfo::{
-    DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
-    DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
-    DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
+    DIBuilderRef, DIDescriptor_opaque, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType_opaque,
+    DIType, DIBasicType, DIDerivedType, DICompositeType, DIScope_opaque, DIScope, DIVariable,
+    DIGlobalVariable, DIArray_opaque, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
     DINameSpace, DIFlags,
 };
 
 use libc::{c_uint, c_int, size_t, c_char};
 use libc::{c_longlong, c_ulonglong, c_void};
 
+use std::ptr::NonNull;
+
 use super::RustStringRef;
 
 pub type Opcode = u32;
@@ -348,10 +350,10 @@ pub enum PassKind {
 }
 
 /// LLVMRustThinLTOData
-pub enum ThinLTOData {}
+extern { pub type ThinLTOData; }
 
 /// LLVMRustThinLTOBuffer
-pub enum ThinLTOBuffer {}
+extern { pub type ThinLTOBuffer; }
 
 /// LLVMRustThinLTOModule
 #[repr(C)]
@@ -373,83 +375,59 @@ pub enum ThreadLocalMode {
 }
 
 // Opaque pointer types
-#[allow(missing_copy_implementations)]
-pub enum Module_opaque {}
+extern { pub type Module_opaque; }
 pub type ModuleRef = *mut Module_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Context_opaque {}
+extern { pub type Context_opaque; }
 pub type ContextRef = *mut Context_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Type_opaque {}
+extern { pub type Type_opaque; }
 pub type TypeRef = *mut Type_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Value_opaque {}
+extern { pub type Value_opaque; }
 pub type ValueRef = *mut Value_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Metadata_opaque {}
+extern { pub type Metadata_opaque; }
 pub type MetadataRef = *mut Metadata_opaque;
-#[allow(missing_copy_implementations)]
-pub enum BasicBlock_opaque {}
+extern { pub type BasicBlock_opaque; }
 pub type BasicBlockRef = *mut BasicBlock_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Builder_opaque {}
+extern { pub type Builder_opaque; }
 pub type BuilderRef = *mut Builder_opaque;
-#[allow(missing_copy_implementations)]
-pub enum ExecutionEngine_opaque {}
+extern { pub type ExecutionEngine_opaque; }
 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
-#[allow(missing_copy_implementations)]
-pub enum MemoryBuffer_opaque {}
+extern { pub type MemoryBuffer_opaque; }
 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
-#[allow(missing_copy_implementations)]
-pub enum PassManager_opaque {}
+extern { pub type PassManager_opaque; }
 pub type PassManagerRef = *mut PassManager_opaque;
-#[allow(missing_copy_implementations)]
-pub enum PassManagerBuilder_opaque {}
+extern { pub type PassManagerBuilder_opaque; }
 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Use_opaque {}
+extern { pub type Use_opaque; }
 pub type UseRef = *mut Use_opaque;
-#[allow(missing_copy_implementations)]
-pub enum TargetData_opaque {}
+extern { pub type TargetData_opaque; }
 pub type TargetDataRef = *mut TargetData_opaque;
-#[allow(missing_copy_implementations)]
-pub enum ObjectFile_opaque {}
+extern { pub type ObjectFile_opaque; }
 pub type ObjectFileRef = *mut ObjectFile_opaque;
-#[allow(missing_copy_implementations)]
-pub enum SectionIterator_opaque {}
+extern { pub type SectionIterator_opaque; }
 pub type SectionIteratorRef = *mut SectionIterator_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Pass_opaque {}
+extern { pub type Pass_opaque; }
 pub type PassRef = *mut Pass_opaque;
-#[allow(missing_copy_implementations)]
-pub enum TargetMachine_opaque {}
+extern { pub type TargetMachine_opaque; }
 pub type TargetMachineRef = *mut TargetMachine_opaque;
-pub enum Archive_opaque {}
+extern { pub type Archive_opaque; }
 pub type ArchiveRef = *mut Archive_opaque;
-pub enum ArchiveIterator_opaque {}
+extern { pub type ArchiveIterator_opaque; }
 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
-pub enum ArchiveChild_opaque {}
+extern { pub type ArchiveChild_opaque; }
 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Twine_opaque {}
+extern { pub type Twine_opaque; }
 pub type TwineRef = *mut Twine_opaque;
-#[allow(missing_copy_implementations)]
-pub enum DiagnosticInfo_opaque {}
+extern { pub type DiagnosticInfo_opaque; }
 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
-#[allow(missing_copy_implementations)]
-pub enum DebugLoc_opaque {}
+extern { pub type DebugLoc_opaque; }
 pub type DebugLocRef = *mut DebugLoc_opaque;
-#[allow(missing_copy_implementations)]
-pub enum SMDiagnostic_opaque {}
+extern { pub type SMDiagnostic_opaque; }
 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
-#[allow(missing_copy_implementations)]
-pub enum RustArchiveMember_opaque {}
+extern { pub type RustArchiveMember_opaque; }
 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
-#[allow(missing_copy_implementations)]
-pub enum OperandBundleDef_opaque {}
+extern { pub type OperandBundleDef_opaque; }
 pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
-#[allow(missing_copy_implementations)]
-pub enum Linker_opaque {}
+extern { pub type Linker_opaque; }
 pub type LinkerRef = *mut Linker_opaque;
 
 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
@@ -457,26 +435,29 @@ pub enum Linker_opaque {}
 
 
 pub mod debuginfo {
-    use super::MetadataRef;
+    use super::Metadata_opaque;
 
-    #[allow(missing_copy_implementations)]
-    pub enum DIBuilder_opaque {}
+    extern { pub type DIBuilder_opaque; }
     pub type DIBuilderRef = *mut DIBuilder_opaque;
 
-    pub type DIDescriptor = MetadataRef;
-    pub type DIScope = DIDescriptor;
+    pub type DIDescriptor_opaque = Metadata_opaque;
+    pub type DIDescriptor = *mut DIDescriptor_opaque;
+    pub type DIScope_opaque = DIDescriptor_opaque;
+    pub type DIScope = *mut DIScope_opaque;
     pub type DILocation = DIDescriptor;
     pub type DIFile = DIScope;
     pub type DILexicalBlock = DIScope;
     pub type DISubprogram = DIScope;
     pub type DINameSpace = DIScope;
-    pub type DIType = DIDescriptor;
+    pub type DIType_opaque = DIDescriptor_opaque;
+    pub type DIType = *mut DIType_opaque;
     pub type DIBasicType = DIType;
     pub type DIDerivedType = DIType;
     pub type DICompositeType = DIDerivedType;
     pub type DIVariable = DIDescriptor;
     pub type DIGlobalVariable = DIDescriptor;
-    pub type DIArray = DIDescriptor;
+    pub type DIArray_opaque = DIDescriptor_opaque;
+    pub type DIArray = *mut DIArray_opaque;
     pub type DISubrange = DIDescriptor;
     pub type DIEnumerator = DIDescriptor;
     pub type DITemplateTypeParameter = DIDescriptor;
@@ -512,8 +493,9 @@ pub struct DIFlags: ::libc::uint32_t {
     }
 }
 
-pub enum ModuleBuffer {}
+extern { pub type ModuleBuffer; }
 
+#[allow(improper_ctypes)] // TODO remove this (use for NonNull)
 extern "C" {
     // Create and destroy contexts.
     pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> ContextRef;
@@ -793,7 +775,7 @@ pub fn LLVMAddIncoming(PhiNode: ValueRef,
     pub fn LLVMDisposeBuilder(Builder: BuilderRef);
 
     // Metadata
-    pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
+    pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: Option<NonNull<Value_opaque>>);
     pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
     pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
 
@@ -819,7 +801,7 @@ pub fn LLVMRustBuildInvoke(B: BuilderRef,
                                NumArgs: c_uint,
                                Then: BasicBlockRef,
                                Catch: BasicBlockRef,
-                               Bundle: OperandBundleDefRef,
+                               Bundle: Option<NonNull<OperandBundleDef_opaque>>,
                                Name: *const c_char)
                                -> ValueRef;
     pub fn LLVMBuildLandingPad(B: BuilderRef,
@@ -832,14 +814,14 @@ pub fn LLVMBuildLandingPad(B: BuilderRef,
     pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
 
     pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
-                                   ParentPad: ValueRef,
+                                   ParentPad: Option<NonNull<Value_opaque>>,
                                    ArgCnt: c_uint,
                                    Args: *const ValueRef,
                                    Name: *const c_char)
                                    -> ValueRef;
     pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
                                    CleanupPad: ValueRef,
-                                   UnwindBB: BasicBlockRef)
+                                   UnwindBB: Option<NonNull<BasicBlock_opaque>>)
                                    -> ValueRef;
     pub fn LLVMRustBuildCatchPad(B: BuilderRef,
                                  ParentPad: ValueRef,
@@ -849,8 +831,8 @@ pub fn LLVMRustBuildCatchPad(B: BuilderRef,
                                  -> ValueRef;
     pub fn LLVMRustBuildCatchRet(B: BuilderRef, Pad: ValueRef, BB: BasicBlockRef) -> ValueRef;
     pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
-                                    ParentPad: ValueRef,
-                                    BB: BasicBlockRef,
+                                    ParentPad: Option<NonNull<Value_opaque>>,
+                                    BB: Option<NonNull<BasicBlock_opaque>>,
                                     NumHandlers: c_uint,
                                     Name: *const c_char)
                                     -> ValueRef;
@@ -1161,7 +1143,7 @@ pub fn LLVMRustBuildCall(B: BuilderRef,
                              Fn: ValueRef,
                              Args: *const ValueRef,
                              NumArgs: c_uint,
-                             Bundle: OperandBundleDefRef,
+                             Bundle: Option<NonNull<OperandBundleDef_opaque>>,
                              Name: *const c_char)
                              -> ValueRef;
     pub fn LLVMBuildSelect(B: BuilderRef,
@@ -1433,7 +1415,7 @@ pub fn LLVMRustDIBuilderCreateFunction(Builder: DIBuilderRef,
                                            isOptimized: bool,
                                            Fn: ValueRef,
                                            TParam: DIArray,
-                                           Decl: DIDescriptor)
+                                           Decl: Option<NonNull<DIDescriptor_opaque>>)
                                            -> DISubprogram;
 
     pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef,
@@ -1451,17 +1433,17 @@ pub fn LLVMRustDIBuilderCreatePointerType(Builder: DIBuilderRef,
                                               -> DIDerivedType;
 
     pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef,
-                                             Scope: DIDescriptor,
+                                             Scope: Option<NonNull<DIDescriptor_opaque>>,
                                              Name: *const c_char,
                                              File: DIFile,
                                              LineNumber: c_uint,
                                              SizeInBits: u64,
                                              AlignInBits: u32,
                                              Flags: DIFlags,
-                                             DerivedFrom: DIType,
+                                             DerivedFrom: Option<NonNull<DIType_opaque>>,
                                              Elements: DIArray,
                                              RunTimeLang: c_uint,
-                                             VTableHolder: DIType,
+                                             VTableHolder: Option<NonNull<DIType_opaque>>,
                                              UniqueId: *const c_char)
                                              -> DICompositeType;
 
@@ -1490,7 +1472,7 @@ pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: DIBuilderRef,
                                                    -> DILexicalBlock;
 
     pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
-                                                 Context: DIScope,
+                                                 Context: Option<NonNull<DIScope_opaque>>,
                                                  Name: *const c_char,
                                                  LinkageName: *const c_char,
                                                  File: DIFile,
@@ -1498,7 +1480,7 @@ pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
                                                  Ty: DIType,
                                                  isLocalToUnit: bool,
                                                  Val: ValueRef,
-                                                 Decl: DIDescriptor,
+                                                 Decl: Option<NonNull<DIDescriptor_opaque>>,
                                                  AlignInBits: u32)
                                                  -> DIGlobalVariable;
 
@@ -1535,7 +1517,7 @@ pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
                                                 -> DISubrange;
 
     pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
-                                             Ptr: *const DIDescriptor,
+                                             Ptr: *const Option<NonNull<DIDescriptor_opaque>>,
                                              Count: c_uint)
                                              -> DIArray;
 
@@ -1572,7 +1554,7 @@ pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef,
                                             SizeInBits: u64,
                                             AlignInBits: u32,
                                             Flags: DIFlags,
-                                            Elements: DIArray,
+                                            Elements: Option<NonNull<DIArray_opaque>>,
                                             RunTimeLang: c_uint,
                                             UniqueId: *const c_char)
                                             -> DIType;
@@ -1580,7 +1562,7 @@ pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef,
     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
 
     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
-                                                        Scope: DIScope,
+                                                        Scope: Option<NonNull<DIScope_opaque>>,
                                                         Name: *const c_char,
                                                         Ty: DIType,
                                                         File: DIFile,
@@ -1590,7 +1572,7 @@ pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
 
 
     pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
-                                            Scope: DIScope,
+                                            Scope: Option<NonNull<DIScope_opaque>>,
                                             Name: *const c_char,
                                             File: DIFile,
                                             LineNo: c_uint)
@@ -1604,7 +1586,7 @@ pub fn LLVMRustDIBuilderCreateDebugLocation(Context: ContextRef,
                                                 Line: c_uint,
                                                 Column: c_uint,
                                                 Scope: DIScope,
-                                                InlinedAt: MetadataRef)
+                                                InlinedAt: Option<NonNull<Metadata_opaque>>)
                                                 -> ValueRef;
     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
@@ -1720,7 +1702,7 @@ pub fn LLVMRustWriteArchive(Dst: *const c_char,
                                 -> LLVMRustResult;
     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
                                     Name: *const c_char,
-                                    Child: ArchiveChildRef)
+                                    Child: Option<NonNull<ArchiveChild_opaque>>)
                                     -> RustArchiveMemberRef;
     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
 
index 312939408c62cf0f9badab6166f6570383802120..5fb4cbfb982d52ff0a6574a1baac7b4944212523 100644 (file)
@@ -11,7 +11,7 @@
 use common::{C_i32, C_null};
 use libc::c_uint;
 use llvm::{self, ValueRef, BasicBlockRef};
-use llvm::debuginfo::DIScope;
+use llvm::debuginfo::DIScope_opaque;
 use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts};
 use rustc::ty::layout::{LayoutOf, TyLayout};
 use rustc::mir::{self, Mir};
@@ -29,6 +29,7 @@
 use syntax::symbol::keywords;
 
 use std::iter;
+use std::ptr::NonNull;
 
 use rustc_data_structures::bitvec::BitVector;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
@@ -121,7 +122,7 @@ pub fn set_debug_loc(&mut self, bx: &Builder, source_info: mir::SourceInfo) {
         debuginfo::set_source_location(&self.debug_context, bx, scope, span);
     }
 
-    pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (DIScope, Span) {
+    pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (Option<NonNull<DIScope_opaque>>, Span) {
         // Bail out if debug info emission is not enabled.
         match self.debug_context {
             FunctionDebugContext::DebugInfoDisabled |
@@ -161,16 +162,16 @@ pub fn debug_loc(&mut self, source_info: mir::SourceInfo) -> (DIScope, Span) {
     // corresponding to span's containing source scope.  If so, we need to create a DIScope
     // "extension" into that file.
     fn scope_metadata_for_loc(&self, scope_id: mir::SourceScope, pos: BytePos)
-                               -> llvm::debuginfo::DIScope {
+                               -> Option<NonNull<DIScope_opaque>> {
         let scope_metadata = self.scopes[scope_id].scope_metadata;
         if pos < self.scopes[scope_id].file_start_pos ||
            pos >= self.scopes[scope_id].file_end_pos {
             let cm = self.cx.sess().codemap();
             let defining_crate = self.debug_context.get_ref(DUMMY_SP).defining_crate;
-            debuginfo::extend_scope_to_file(self.cx,
-                                            scope_metadata,
+            NonNull::new(debuginfo::extend_scope_to_file(self.cx,
+                                            scope_metadata.unwrap().as_ptr(),
                                             &cm.lookup_char_pos(pos).file,
-                                            defining_crate)
+                                            defining_crate))
         } else {
             scope_metadata
         }
@@ -280,7 +281,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
                         span: decl.source_info.span,
                         scope: decl.visibility_scope,
                     });
-                    declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
+                    declare_local(&bx, &fx.debug_context, name, layout.ty, scope.unwrap().as_ptr(),
                         VariableAccess::DirectVariable { alloca: place.llval },
                         VariableKind::LocalVariable, span);
                 }
@@ -424,8 +425,8 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
 
     // Get the argument scope, if it exists and if we need it.
     let arg_scope = scopes[mir::OUTERMOST_SOURCE_SCOPE];
-    let arg_scope = if arg_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo {
-        Some(arg_scope.scope_metadata)
+    let arg_scope = if bx.sess().opts.debuginfo == FullDebugInfo {
+        arg_scope.scope_metadata
     } else {
         None
     };
@@ -471,7 +472,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
                     bx,
                     &fx.debug_context,
                     arg_decl.name.unwrap_or(keywords::Invalid.name()),
-                    arg_ty, scope,
+                    arg_ty, scope.as_ptr(),
                     variable_access,
                     VariableKind::ArgumentVariable(arg_index + 1),
                     DUMMY_SP
@@ -550,7 +551,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
                     &fx.debug_context,
                     arg_decl.name.unwrap_or(keywords::Invalid.name()),
                     arg.layout.ty,
-                    scope,
+                    scope.as_ptr(),
                     variable_access,
                     VariableKind::ArgumentVariable(arg_index + 1),
                     DUMMY_SP
@@ -601,7 +602,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
                     &fx.debug_context,
                     decl.debug_name,
                     ty,
-                    scope,
+                    scope.as_ptr(),
                     variable_access,
                     VariableKind::LocalVariable,
                     DUMMY_SP
index c433df51110e352b9cabc0b41418abd8858df37e..78c83f200a517da5db04f9c48005422bd1483943 100644 (file)
@@ -24,7 +24,6 @@
 use type_of::LayoutLlvmExt;
 
 use std::fmt;
-use std::ptr;
 
 use super::{FunctionCx, LocalRef};
 use super::constant::scalar_to_llvm;
@@ -160,7 +159,7 @@ pub fn deref(self, cx: &CodegenCx<'a, 'tcx>) -> PlaceRef<'tcx> {
         let projected_ty = self.layout.ty.builtin_deref(true)
             .unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty;
         let (llptr, llextra) = match self.val {
-            OperandValue::Immediate(llptr) => (llptr, ptr::null_mut()),
+            OperandValue::Immediate(llptr) => (llptr, 0 as *mut _),
             OperandValue::Pair(llptr, llextra) => (llptr, llextra),
             OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self)
         };
index 9abf9077a9577f4d6b48672f3ca3463a9c0712f6..aff29b06b8f31b1fc76f65f43582498e09bc199f 100644 (file)
@@ -24,8 +24,6 @@
 use glue;
 use mir::constant::const_alloc_to_llvm;
 
-use std::ptr;
-
 use super::{FunctionCx, LocalRef};
 use super::operand::{OperandRef, OperandValue};
 
@@ -51,7 +49,7 @@ pub fn new_sized(llval: ValueRef,
                      -> PlaceRef<'tcx> {
         PlaceRef {
             llval,
-            llextra: ptr::null_mut(),
+            llextra: 0 as *mut _,
             layout,
             align
         }
@@ -126,7 +124,7 @@ pub fn load(&self, bx: &Builder<'a, 'tcx>) -> OperandRef<'tcx> {
         };
 
         let val = if self.layout.is_llvm_immediate() {
-            let mut const_llval = ptr::null_mut();
+            let mut const_llval = 0 as *mut _;
             unsafe {
                 let global = llvm::LLVMIsAGlobalVariable(self.llval);
                 if !global.is_null() && llvm::LLVMIsGlobalConstant(global) == llvm::True {
@@ -187,7 +185,7 @@ pub fn project_field(self, bx: &Builder<'a, 'tcx>, ix: usize) -> PlaceRef<'tcx>
                 llextra: if cx.type_has_metadata(field.ty) {
                     self.llextra
                 } else {
-                    ptr::null_mut()
+                    0 as *mut _
                 },
                 layout: field,
                 align,
@@ -390,7 +388,7 @@ pub fn project_index(&self, bx: &Builder<'a, 'tcx>, llindex: ValueRef)
                          -> PlaceRef<'tcx> {
         PlaceRef {
             llval: bx.inbounds_gep(self.llval, &[C_usize(bx.cx, 0), llindex]),
-            llextra: ptr::null_mut(),
+            llextra: 0 as *mut _,
             layout: self.layout.field(bx.cx, 0),
             align: self.align
         }
index a77acc4f1756f016de71784f726a9a9c64412302..37157635b2d67578f94cf30ffb6d301cb317f96a 100644 (file)
@@ -22,7 +22,6 @@
 use std::ffi::CString;
 use std::fmt;
 use std::mem;
-use std::ptr;
 
 use libc::c_uint;
 
@@ -103,6 +102,11 @@ pub fn ix(cx: &CodegenCx, num_bits: u64) -> Type {
         ty!(llvm::LLVMIntTypeInContext(cx.llcx, num_bits as c_uint))
     }
 
+    // Creates an integer type with the given number of bits, e.g. i24
+    pub fn ix_llcx(llcx: ContextRef, num_bits: u64) -> Type {
+        ty!(llvm::LLVMIntTypeInContext(llcx, num_bits as c_uint))
+    }
+
     pub fn f32(cx: &CodegenCx) -> Type {
         ty!(llvm::LLVMFloatTypeInContext(cx.llcx))
     }
@@ -128,12 +132,7 @@ pub fn i8p_llcx(llcx: ContextRef) -> Type {
     }
 
     pub fn isize(cx: &CodegenCx) -> Type {
-        match &cx.tcx.sess.target.target.target_pointer_width[..] {
-            "16" => Type::i16(cx),
-            "32" => Type::i32(cx),
-            "64" => Type::i64(cx),
-            tws => bug!("Unsupported target word size for int: {}", tws),
-        }
+        cx.isize_ty
     }
 
     pub fn c_int(cx: &CodegenCx) -> Type {
@@ -241,7 +240,7 @@ pub fn vector_length(&self) -> usize {
     pub fn func_params(&self) -> Vec<Type> {
         unsafe {
             let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as usize;
-            let mut args = vec![Type { rf: ptr::null_mut() }; n_args];
+            let mut args = vec![Type { rf: 0 as *mut _ }; n_args];
             llvm::LLVMGetParamTypes(self.to_ref(),
                                     args.as_mut_ptr() as *mut TypeRef);
             args