1
Fork 0

rustc_codegen_llvm: move from empty enums to extern types.

This commit is contained in:
Irina Popa 2018-06-27 13:12:47 +03:00
parent 077be49bde
commit af04e9426c
18 changed files with 178 additions and 197 deletions

View file

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
use std::ffi::CString; use std::ffi::CString;
use std::ptr;
use attributes; use attributes;
use libc::c_uint; use libc::c_uint;
@ -90,7 +89,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind
callee, callee,
args.as_ptr(), args.as_ptr(),
args.len() as c_uint, args.len() as c_uint,
ptr::null_mut(), None,
"\0".as_ptr() as *const _); "\0".as_ptr() as *const _);
llvm::LLVMSetTailCall(ret, True); llvm::LLVMSetTailCall(ret, True);
if output.is_some() { if output.is_some() {

View file

@ -14,7 +14,7 @@ use std::ffi::{CString, CStr};
use std::io; use std::io;
use std::mem; use std::mem;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::ptr; use std::ptr::{self, NonNull};
use std::str; use std::str;
use back::bytecode::RLIB_BYTECODE_EXTENSION; use back::bytecode::RLIB_BYTECODE_EXTENSION;
@ -246,7 +246,7 @@ impl<'a> ArchiveBuilder<'a> {
let name = CString::new(child_name)?; let name = CString::new(child_name)?;
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(), members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(), name.as_ptr(),
child.raw())); NonNull::new(child.raw())));
strings.push(name); strings.push(name);
} }
} }
@ -257,7 +257,7 @@ impl<'a> ArchiveBuilder<'a> {
let name = CString::new(name_in_archive)?; let name = CString::new(name_in_archive)?;
members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(), members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
name.as_ptr(), name.as_ptr(),
ptr::null_mut())); None));
strings.push(path); strings.push(path);
strings.push(name); strings.push(name);
} }
@ -284,7 +284,7 @@ impl<'a> ArchiveBuilder<'a> {
let name = CString::new(child_name)?; let name = CString::new(child_name)?;
let m = llvm::LLVMRustArchiveMemberNew(ptr::null(), let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(), name.as_ptr(),
child.raw()); NonNull::new(child.raw()));
members.push(m); members.push(m);
strings.push(name); strings.push(name);
} }

View file

@ -26,6 +26,7 @@ use std::borrow::Cow;
use std::ffi::CString; use std::ffi::CString;
use std::ops::Range; use std::ops::Range;
use std::ptr; use std::ptr;
use std::ptr::NonNull;
use syntax_pos::Span; use syntax_pos::Span;
// All Builders must have an llfn associated with them // All Builders must have an llfn associated with them
@ -211,7 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.join(", ")); .join(", "));
let args = self.check_call("invoke", llfn, args); 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 { unsafe {
llvm::LLVMRustBuildInvoke(self.llbuilder, llvm::LLVMRustBuildInvoke(self.llbuilder,
@ -909,7 +910,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.join(", ")); .join(", "));
let args = self.check_call("call", llfn, args); 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 { unsafe {
llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(), llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(),
@ -1196,7 +1197,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
parent: Option<ValueRef>, parent: Option<ValueRef>,
args: &[ValueRef]) -> ValueRef { args: &[ValueRef]) -> ValueRef {
self.count_insn("cleanuppad"); 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 name = CString::new("cleanuppad").unwrap();
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCleanupPad(self.llbuilder, llvm::LLVMRustBuildCleanupPad(self.llbuilder,
@ -1212,7 +1213,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn cleanup_ret(&self, cleanup: ValueRef, pub fn cleanup_ret(&self, cleanup: ValueRef,
unwind: Option<BasicBlockRef>) -> ValueRef { unwind: Option<BasicBlockRef>) -> ValueRef {
self.count_insn("cleanupret"); self.count_insn("cleanupret");
let unwind = unwind.unwrap_or(ptr::null_mut()); let unwind = unwind.and_then(NonNull::new);
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind) llvm::LLVMRustBuildCleanupRet(self.llbuilder, cleanup, unwind)
}; };
@ -1248,8 +1249,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
unwind: Option<BasicBlockRef>, unwind: Option<BasicBlockRef>,
num_handlers: usize) -> ValueRef { num_handlers: usize) -> ValueRef {
self.count_insn("catchswitch"); self.count_insn("catchswitch");
let parent = parent.unwrap_or(ptr::null_mut()); let parent = parent.and_then(NonNull::new);
let unwind = unwind.unwrap_or(ptr::null_mut()); let unwind = unwind.and_then(NonNull::new);
let name = CString::new("catchswitch").unwrap(); let name = CString::new("catchswitch").unwrap();
let ret = unsafe { let ret = unsafe {
llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind, llvm::LLVMRustBuildCatchSwitch(self.llbuilder, parent, unwind,

View file

@ -35,7 +35,6 @@ use rustc_target::spec::{HasTargetSpec, Target};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::ptr;
use std::iter; use std::iter;
use std::str; use std::str;
use std::sync::Arc; use std::sync::Arc;
@ -280,7 +279,9 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
None None
}; };
let mut cx = CodegenCx { let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
CodegenCx {
tcx, tcx,
check_overflow, check_overflow,
use_dll_storage_attrs, use_dll_storage_attrs,
@ -300,16 +301,14 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
lltypes: RefCell::new(FxHashMap()), lltypes: RefCell::new(FxHashMap()),
scalar_lltypes: RefCell::new(FxHashMap()), scalar_lltypes: RefCell::new(FxHashMap()),
pointee_infos: RefCell::new(FxHashMap()), pointee_infos: RefCell::new(FxHashMap()),
isize_ty: Type::from_ref(ptr::null_mut()), isize_ty,
dbg_cx, dbg_cx,
eh_personality: Cell::new(None), eh_personality: Cell::new(None),
eh_unwind_resume: Cell::new(None), eh_unwind_resume: Cell::new(None),
rust_try_fn: Cell::new(None), rust_try_fn: Cell::new(None),
intrinsics: RefCell::new(FxHashMap()), intrinsics: RefCell::new(FxHashMap()),
local_gen_sym_counter: Cell::new(0), local_gen_sym_counter: Cell::new(0),
}; }
cx.isize_ty = Type::isize(&cx);
cx
} }
} }

View file

@ -13,12 +13,12 @@ use super::metadata::file_metadata;
use super::utils::{DIB, span_start}; use super::utils::{DIB, span_start};
use llvm; use llvm;
use llvm::debuginfo::DIScope; use llvm::debuginfo::DIScope_opaque;
use common::CodegenCx; use common::CodegenCx;
use rustc::mir::{Mir, SourceScope}; use rustc::mir::{Mir, SourceScope};
use std::ptr::NonNull;
use libc::c_uint; use libc::c_uint;
use std::ptr;
use syntax_pos::Pos; use syntax_pos::Pos;
@ -29,7 +29,7 @@ use syntax_pos::BytePos;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct MirDebugScope { 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. // 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. // These are used to quickly determine whether some span refers to the same file.
pub file_start_pos: BytePos, pub file_start_pos: BytePos,
@ -38,7 +38,7 @@ pub struct MirDebugScope {
impl MirDebugScope { impl MirDebugScope {
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
!self.scope_metadata.is_null() !self.scope_metadata.is_none()
} }
} }
@ -47,7 +47,7 @@ impl MirDebugScope {
pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext) pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebugContext)
-> IndexVec<SourceScope, MirDebugScope> { -> IndexVec<SourceScope, MirDebugScope> {
let null_scope = MirDebugScope { let null_scope = MirDebugScope {
scope_metadata: ptr::null_mut(), scope_metadata: None,
file_start_pos: BytePos(0), file_start_pos: BytePos(0),
file_end_pos: BytePos(0) file_end_pos: BytePos(0)
}; };
@ -95,7 +95,7 @@ fn make_mir_scope(cx: &CodegenCx,
// The root is the function itself. // The root is the function itself.
let loc = span_start(cx, mir.span); let loc = span_start(cx, mir.span);
scopes[scope] = MirDebugScope { 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_start_pos: loc.file.start_pos,
file_end_pos: loc.file.end_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 // However, we don't skip creating a nested scope if
// our parent is the root, because we might want to // our parent is the root, because we might want to
// put arguments in the root and not have shadowing. // 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; scopes[scope] = parent_scope;
return; return;
} }
@ -121,12 +121,12 @@ fn make_mir_scope(cx: &CodegenCx,
debug_context.defining_crate); debug_context.defining_crate);
let scope_metadata = unsafe { let scope_metadata = unsafe {
llvm::LLVMRustDIBuilderCreateLexicalBlock( NonNull::new(llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx), DIB(cx),
parent_scope.scope_metadata, parent_scope.scope_metadata.unwrap().as_ptr(),
file_metadata, file_metadata,
loc.line as c_uint, loc.line as c_uint,
loc.col.to_usize() as c_uint) loc.col.to_usize() as c_uint))
}; };
scopes[scope] = MirDebugScope { scopes[scope] = MirDebugScope {
scope_metadata, scope_metadata,

View file

@ -18,7 +18,6 @@ use declare;
use type_::Type; use type_::Type;
use rustc::session::config::NoDebugInfo; use rustc::session::config::NoDebugInfo;
use std::ptr;
use syntax::attr; 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 _) 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_name = b".debug_gdb_scripts\0";
let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0"; let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0";

View file

@ -20,7 +20,7 @@ use super::{CrateDebugContext};
use abi; use abi;
use llvm::{self, ValueRef}; use llvm::{self, ValueRef};
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, use llvm::debuginfo::{DIType, DIFile, DIScope_opaque, DIScope, DIDescriptor,
DICompositeType, DILexicalBlock, DIFlags}; DICompositeType, DILexicalBlock, DIFlags};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@ -41,6 +41,7 @@ use std::ffi::CString;
use std::fmt::Write; use std::fmt::Write;
use std::iter; use std::iter;
use std::ptr; use std::ptr;
use std::ptr::NonNull;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use syntax::ast; use syntax::ast;
use syntax::symbol::{Interner, InternedString, Symbol}; use syntax::symbol::{Interner, InternedString, Symbol};
@ -64,8 +65,7 @@ const DW_ATE_unsigned_char: c_uint = 0x08;
pub const UNKNOWN_LINE_NUMBER: c_uint = 0; pub const UNKNOWN_LINE_NUMBER: c_uint = 0;
pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0; pub const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
// ptr::null() doesn't work :( pub const NO_SCOPE_METADATA: Option<NonNull<DIScope_opaque>> = None;
pub const NO_SCOPE_METADATA: DIScope = (0 as DIScope);
#[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)] #[derive(Copy, Debug, Hash, Eq, PartialEq, Clone)]
pub struct UniqueTypeId(ast::Name); pub struct UniqueTypeId(ast::Name);
@ -289,7 +289,7 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
}; };
let subrange = unsafe { 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]); let subscripts = create_DIArray(DIB(cx), &[subrange]);
@ -365,15 +365,17 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
&signature, &signature,
); );
let signature_metadata: Vec<DIType> = iter::once( let signature_metadata: Vec<_> = iter::once(
// return type // return type
match signature.output().sty { match signature.output().sty {
ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(), ty::TyTuple(ref tys) if tys.is_empty() => None,
_ => type_metadata(cx, signature.output(), span) _ => NonNull::new(type_metadata(cx, signature.output(), span))
} }
).chain( ).chain(
// regular arguments // 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(); ).collect();
return_if_metadata_created_in_meantime!(cx, unique_type_id); 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 { let containing_scope = match trait_type.sty {
ty::TyDynamic(ref data, ..) => if let Some(principal) = data.principal() { ty::TyDynamic(ref data, ..) => if let Some(principal) = data.principal() {
let def_id = principal.def_id(); let def_id = principal.def_id();
get_namespace_for_item(cx, def_id) NonNull::new(get_namespace_for_item(cx, def_id))
} else { } else {
NO_SCOPE_METADATA NO_SCOPE_METADATA
}, },
@ -985,7 +987,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
struct_type, struct_type,
&struct_name, &struct_name,
unique_type_id, unique_type_id,
containing_scope); NonNull::new(containing_scope));
create_and_register_recursive_type_forward_declaration( create_and_register_recursive_type_forward_declaration(
cx, cx,
@ -1317,7 +1319,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
layout.ty, layout.ty,
&variant_name, &variant_name,
unique_type_id, unique_type_id,
containing_scope); NonNull::new(containing_scope));
// If this is not a univariant enum, there is also the discriminant field. // If this is not a univariant enum, there is also the discriminant field.
let (discr_offset, discr_arg) = match discriminant_info { 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 file_metadata = unknown_file_metadata(cx);
let def = enum_type.ty_adt_def().unwrap(); 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) .zip(&def.variants)
.map(|(discr, v)| { .map(|(discr, v)| {
let token = v.name.as_str(); let token = v.name.as_str();
let name = CString::new(token.as_bytes()).unwrap(); let name = CString::new(token.as_bytes()).unwrap();
unsafe { unsafe {
llvm::LLVMRustDIBuilderCreateEnumerator( NonNull::new(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx), DIB(cx),
name.as_ptr(), name.as_ptr(),
// FIXME: what if enumeration has i128 discriminant? // FIXME: what if enumeration has i128 discriminant?
discr.val as u64) discr.val as u64))
} }
}) })
.collect(); .collect();
@ -1459,7 +1461,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
enum_type_size.bits(), enum_type_size.bits(),
enum_type_align.abi_bits() as u32, enum_type_align.abi_bits() as u32,
DIFlags::FlagZero, DIFlags::FlagZero,
ptr::null_mut(), None,
0, // RuntimeLang 0, // RuntimeLang
unique_type_id_str.as_ptr()) 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_name: &str,
composite_type_unique_id: UniqueTypeId, composite_type_unique_id: UniqueTypeId,
member_descriptions: &[MemberDescription], member_descriptions: &[MemberDescription],
containing_scope: DIScope, containing_scope: Option<NonNull<DIScope_opaque>>,
// Ignore source location information as long as it // Ignore source location information as long as it
// can't be reconstructed for non-local crates. // 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() .iter()
.map(|member_description| { .map(|member_description| {
let member_name = member_description.name.as_bytes(); let member_name = member_description.name.as_bytes();
let member_name = CString::new(member_name).unwrap(); let member_name = CString::new(member_name).unwrap();
unsafe { unsafe {
llvm::LLVMRustDIBuilderCreateMemberType( NonNull::new(llvm::LLVMRustDIBuilderCreateMemberType(
DIB(cx), DIB(cx),
composite_type_metadata, composite_type_metadata,
member_name.as_ptr(), 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.align.abi_bits() as u32,
member_description.offset.bits(), member_description.offset.bits(),
member_description.flags, member_description.flags,
member_description.type_metadata) member_description.type_metadata))
} }
}) })
.collect(); .collect();
@ -1570,7 +1572,7 @@ fn create_struct_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
struct_type: Ty<'tcx>, struct_type: Ty<'tcx>,
struct_type_name: &str, struct_type_name: &str,
unique_type_id: UniqueTypeId, unique_type_id: UniqueTypeId,
containing_scope: DIScope) containing_scope: Option<NonNull<DIScope_opaque>>)
-> DICompositeType { -> DICompositeType {
let (struct_size, struct_align) = cx.size_and_align_of(struct_type); 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_size.bits(),
struct_align.abi_bits() as u32, struct_align.abi_bits() as u32,
DIFlags::FlagZero, DIFlags::FlagZero,
ptr::null_mut(), None,
empty_array, empty_array,
0, 0,
ptr::null_mut(), None,
unique_type_id.as_ptr()) unique_type_id.as_ptr())
}; };
@ -1630,7 +1632,7 @@ fn create_union_stub<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
union_size.bits(), union_size.bits(),
union_align.abi_bits() as u32, union_align.abi_bits() as u32,
DIFlags::FlagZero, DIFlags::FlagZero,
empty_array, NonNull::new(empty_array),
0, // RuntimeLang 0, // RuntimeLang
unique_type_id.as_ptr()) unique_type_id.as_ptr())
}; };
@ -1684,7 +1686,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
unsafe { unsafe {
llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx), llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
var_scope, NonNull::new(var_scope),
var_name.as_ptr(), var_name.as_ptr(),
// If null, linkage_name field is omitted, // If null, linkage_name field is omitted,
// which is what we want for no_mangle statics // which is what we want for no_mangle statics
@ -1695,7 +1697,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
type_metadata, type_metadata,
is_local_to_unit, is_local_to_unit,
global, global,
ptr::null_mut(), None,
global_align.abi() as u32, global_align.abi() as u32,
); );
} }
@ -1749,10 +1751,10 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
Size::ZERO.bits(), Size::ZERO.bits(),
cx.tcx.data_layout.pointer_align.abi_bits() as u32, cx.tcx.data_layout.pointer_align.abi_bits() as u32,
DIFlags::FlagArtificial, DIFlags::FlagArtificial,
ptr::null_mut(), None,
empty_array, empty_array,
0, 0,
type_metadata, NonNull::new(type_metadata),
name.as_ptr() name.as_ptr()
); );
@ -1771,7 +1773,7 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
vtable_type, vtable_type,
true, true,
vtable, vtable,
ptr::null_mut(), None,
0); 0);
} }
} }

View file

@ -39,7 +39,7 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
use libc::c_uint; use libc::c_uint;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::ffi::CString; use std::ffi::CString;
use std::ptr; use std::ptr::NonNull;
use syntax_pos::{self, Span, Pos}; use syntax_pos::{self, Span, Pos};
use syntax::ast; 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, cx.sess().opts.optimize != config::OptLevel::No,
llfn, llfn,
template_parameters, template_parameters,
ptr::null_mut()) None)
}; };
// Initialize fn debug context (including scope map and namespace map) // Initialize fn debug context (including scope map and namespace map)
@ -312,8 +312,8 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
// Return type -- llvm::DIBuilder wants this at index 0 // Return type -- llvm::DIBuilder wants this at index 0
signature.push(match sig.output().sty { signature.push(match sig.output().sty {
ty::TyTuple(ref tys) if tys.is_empty() => ptr::null_mut(), ty::TyTuple(ref tys) if tys.is_empty() => None,
_ => type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP) _ => NonNull::new(type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP))
}); });
let inputs = if sig.abi == Abi::RustCall { let inputs = if sig.abi == Abi::RustCall {
@ -342,19 +342,20 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
} }
_ => t _ => t
}; };
type_metadata(cx, t, syntax_pos::DUMMY_SP) NonNull::new(type_metadata(cx, t, syntax_pos::DUMMY_SP))
})); }));
} else { } else {
signature.extend(inputs.iter().map(|t| { 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 sig.abi == Abi::RustCall && !sig.inputs().is_empty() {
if let ty::TyTuple(args) = sig.inputs()[sig.inputs().len() - 1].sty { if let ty::TyTuple(args) = sig.inputs()[sig.inputs().len() - 1].sty {
signature.extend( signature.extend(
args.iter().map(|argument_type| args.iter().map(|argument_type| {
type_metadata(cx, argument_type, syntax_pos::DUMMY_SP)) NonNull::new(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP))
})
); );
} }
} }
@ -398,14 +399,14 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
type_metadata(cx, actual_type, syntax_pos::DUMMY_SP); type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(name.as_str().as_bytes()).unwrap(); let name = CString::new(name.as_str().as_bytes()).unwrap();
Some(unsafe { Some(unsafe {
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter( NonNull::new(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
DIB(cx), DIB(cx),
ptr::null_mut(), None,
name.as_ptr(), name.as_ptr(),
actual_type_metadata, actual_type_metadata,
file_metadata, file_metadata,
0, 0,
0) 0))
}) })
} else { } else {
None None

View file

@ -22,7 +22,7 @@ use rustc::hir::map::DefPathData;
use common::CodegenCx; use common::CodegenCx;
use std::ffi::CString; use std::ffi::CString;
use std::ptr; use std::ptr::NonNull;
pub fn mangled_name_of_instance<'a, 'tcx>( pub fn mangled_name_of_instance<'a, 'tcx>(
cx: &CodegenCx<'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 def_key = cx.tcx.def_key(def_id);
let parent_scope = def_key.parent.map_or(ptr::null_mut(), |parent| { let parent_scope = def_key.parent.and_then(|parent| {
item_namespace(cx, DefId { NonNull::new(item_namespace(cx, DefId {
krate: def_id.krate, krate: def_id.krate,
index: parent index: parent
}) }))
}); });
let namespace_name = match def_key.disambiguated_data.data { let namespace_name = match def_key.disambiguated_data.data {

View file

@ -15,18 +15,18 @@ use super::metadata::UNKNOWN_COLUMN_NUMBER;
use super::FunctionDebugContext; use super::FunctionDebugContext;
use llvm; use llvm;
use llvm::debuginfo::DIScope; use llvm::debuginfo::{DIScope_opaque, DIScope};
use builder::Builder; use builder::Builder;
use libc::c_uint; use libc::c_uint;
use std::ptr; use std::ptr::NonNull;
use syntax_pos::{Span, Pos}; use syntax_pos::{Span, Pos};
/// Sets the current debug location at the beginning of the span. /// Sets the current debug location at the beginning of the span.
/// ///
/// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...). /// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...).
pub fn set_source_location( 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 { let function_debug_context = match *debug_context {
FunctionDebugContext::DebugInfoDisabled => return, FunctionDebugContext::DebugInfoDisabled => return,
@ -40,7 +40,7 @@ pub fn set_source_location(
let dbg_loc = if function_debug_context.source_locations_enabled.get() { let dbg_loc = if function_debug_context.source_locations_enabled.get() {
debug!("set_source_location: {}", bx.sess().codemap().span_to_string(span)); debug!("set_source_location: {}", bx.sess().codemap().span_to_string(span));
let loc = span_start(bx.cx, 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 { } else {
UnknownLocation UnknownLocation
}; };
@ -93,17 +93,17 @@ pub fn set_debug_location(bx: &Builder, debug_location: InternalDebugLocation) {
debug!("setting debug location to {} {}", line, col); debug!("setting debug location to {} {}", line, col);
unsafe { unsafe {
llvm::LLVMRustDIBuilderCreateDebugLocation( NonNull::new(llvm::LLVMRustDIBuilderCreateDebugLocation(
debug_context(bx.cx).llcontext, debug_context(bx.cx).llcontext,
line as c_uint, line as c_uint,
col_used, col_used,
scope, scope,
ptr::null_mut()) None))
} }
} }
UnknownLocation => { UnknownLocation => {
debug!("clearing debug location "); debug!("clearing debug location ");
ptr::null_mut() None
} }
}; };

View file

@ -17,9 +17,10 @@ use rustc::hir::def_id::DefId;
use rustc::ty::DefIdTree; use rustc::ty::DefIdTree;
use llvm; use llvm;
use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray}; use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor_opaque, DIArray};
use common::{CodegenCx}; use common::{CodegenCx};
use std::ptr::NonNull;
use syntax_pos::{self, Span}; use syntax_pos::{self, Span};
pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool 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)] #[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 { return unsafe {
llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
}; };

View file

@ -21,6 +21,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(custom_attribute)] #![feature(custom_attribute)]
#![feature(extern_types)]
#![feature(fs_read_write)] #![feature(fs_read_write)]
#![allow(unused_attributes)] #![allow(unused_attributes)]
#![feature(libc)] #![feature(libc)]

View file

@ -14,7 +14,6 @@ pub use self::OptimizationDiagnosticKind::*;
pub use self::Diagnostic::*; pub use self::Diagnostic::*;
use libc::c_uint; use libc::c_uint;
use std::ptr;
use super::{DiagnosticInfoRef, TwineRef, ValueRef}; use super::{DiagnosticInfoRef, TwineRef, ValueRef};
@ -56,7 +55,7 @@ impl OptimizationDiagnostic {
unsafe fn unpack(kind: OptimizationDiagnosticKind, unsafe fn unpack(kind: OptimizationDiagnosticKind,
di: DiagnosticInfoRef) di: DiagnosticInfoRef)
-> OptimizationDiagnostic { -> OptimizationDiagnostic {
let mut function = ptr::null_mut(); let mut function = 0 as *mut _;
let mut line = 0; let mut line = 0;
let mut column = 0; let mut column = 0;
@ -105,8 +104,8 @@ impl InlineAsmDiagnostic {
let mut opt = InlineAsmDiagnostic { let mut opt = InlineAsmDiagnostic {
cookie: 0, cookie: 0,
message: ptr::null_mut(), message: 0 as *mut _,
instruction: ptr::null_mut(), instruction: 0 as *mut _,
}; };
super::LLVMRustUnpackInlineAsmDiagnostic(di, super::LLVMRustUnpackInlineAsmDiagnostic(di,

View file

@ -15,15 +15,17 @@
// https://reviews.llvm.org/D26769 // https://reviews.llvm.org/D26769
use super::debuginfo::{ use super::debuginfo::{
DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType, DIBuilderRef, DIDescriptor_opaque, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType_opaque,
DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable, DIType, DIBasicType, DIDerivedType, DICompositeType, DIScope_opaque, DIScope, DIVariable,
DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator, DIGlobalVariable, DIArray_opaque, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
DINameSpace, DIFlags, DINameSpace, DIFlags,
}; };
use libc::{c_uint, c_int, size_t, c_char}; use libc::{c_uint, c_int, size_t, c_char};
use libc::{c_longlong, c_ulonglong, c_void}; use libc::{c_longlong, c_ulonglong, c_void};
use std::ptr::NonNull;
use super::RustStringRef; use super::RustStringRef;
pub type Opcode = u32; pub type Opcode = u32;
@ -348,10 +350,10 @@ pub enum PassKind {
} }
/// LLVMRustThinLTOData /// LLVMRustThinLTOData
pub enum ThinLTOData {} extern { pub type ThinLTOData; }
/// LLVMRustThinLTOBuffer /// LLVMRustThinLTOBuffer
pub enum ThinLTOBuffer {} extern { pub type ThinLTOBuffer; }
/// LLVMRustThinLTOModule /// LLVMRustThinLTOModule
#[repr(C)] #[repr(C)]
@ -373,83 +375,59 @@ pub enum ThreadLocalMode {
} }
// Opaque pointer types // Opaque pointer types
#[allow(missing_copy_implementations)] extern { pub type Module_opaque; }
pub enum Module_opaque {}
pub type ModuleRef = *mut Module_opaque; pub type ModuleRef = *mut Module_opaque;
#[allow(missing_copy_implementations)] extern { pub type Context_opaque; }
pub enum Context_opaque {}
pub type ContextRef = *mut Context_opaque; pub type ContextRef = *mut Context_opaque;
#[allow(missing_copy_implementations)] extern { pub type Type_opaque; }
pub enum Type_opaque {}
pub type TypeRef = *mut Type_opaque; pub type TypeRef = *mut Type_opaque;
#[allow(missing_copy_implementations)] extern { pub type Value_opaque; }
pub enum Value_opaque {}
pub type ValueRef = *mut Value_opaque; pub type ValueRef = *mut Value_opaque;
#[allow(missing_copy_implementations)] extern { pub type Metadata_opaque; }
pub enum Metadata_opaque {}
pub type MetadataRef = *mut Metadata_opaque; pub type MetadataRef = *mut Metadata_opaque;
#[allow(missing_copy_implementations)] extern { pub type BasicBlock_opaque; }
pub enum BasicBlock_opaque {}
pub type BasicBlockRef = *mut BasicBlock_opaque; pub type BasicBlockRef = *mut BasicBlock_opaque;
#[allow(missing_copy_implementations)] extern { pub type Builder_opaque; }
pub enum Builder_opaque {}
pub type BuilderRef = *mut Builder_opaque; pub type BuilderRef = *mut Builder_opaque;
#[allow(missing_copy_implementations)] extern { pub type ExecutionEngine_opaque; }
pub enum ExecutionEngine_opaque {}
pub type ExecutionEngineRef = *mut ExecutionEngine_opaque; pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
#[allow(missing_copy_implementations)] extern { pub type MemoryBuffer_opaque; }
pub enum MemoryBuffer_opaque {}
pub type MemoryBufferRef = *mut MemoryBuffer_opaque; pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
#[allow(missing_copy_implementations)] extern { pub type PassManager_opaque; }
pub enum PassManager_opaque {}
pub type PassManagerRef = *mut PassManager_opaque; pub type PassManagerRef = *mut PassManager_opaque;
#[allow(missing_copy_implementations)] extern { pub type PassManagerBuilder_opaque; }
pub enum PassManagerBuilder_opaque {}
pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque; pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
#[allow(missing_copy_implementations)] extern { pub type Use_opaque; }
pub enum Use_opaque {}
pub type UseRef = *mut Use_opaque; pub type UseRef = *mut Use_opaque;
#[allow(missing_copy_implementations)] extern { pub type TargetData_opaque; }
pub enum TargetData_opaque {}
pub type TargetDataRef = *mut TargetData_opaque; pub type TargetDataRef = *mut TargetData_opaque;
#[allow(missing_copy_implementations)] extern { pub type ObjectFile_opaque; }
pub enum ObjectFile_opaque {}
pub type ObjectFileRef = *mut ObjectFile_opaque; pub type ObjectFileRef = *mut ObjectFile_opaque;
#[allow(missing_copy_implementations)] extern { pub type SectionIterator_opaque; }
pub enum SectionIterator_opaque {}
pub type SectionIteratorRef = *mut SectionIterator_opaque; pub type SectionIteratorRef = *mut SectionIterator_opaque;
#[allow(missing_copy_implementations)] extern { pub type Pass_opaque; }
pub enum Pass_opaque {}
pub type PassRef = *mut Pass_opaque; pub type PassRef = *mut Pass_opaque;
#[allow(missing_copy_implementations)] extern { pub type TargetMachine_opaque; }
pub enum TargetMachine_opaque {}
pub type TargetMachineRef = *mut TargetMachine_opaque; pub type TargetMachineRef = *mut TargetMachine_opaque;
pub enum Archive_opaque {} extern { pub type Archive_opaque; }
pub type ArchiveRef = *mut Archive_opaque; pub type ArchiveRef = *mut Archive_opaque;
pub enum ArchiveIterator_opaque {} extern { pub type ArchiveIterator_opaque; }
pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque; pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
pub enum ArchiveChild_opaque {} extern { pub type ArchiveChild_opaque; }
pub type ArchiveChildRef = *mut ArchiveChild_opaque; pub type ArchiveChildRef = *mut ArchiveChild_opaque;
#[allow(missing_copy_implementations)] extern { pub type Twine_opaque; }
pub enum Twine_opaque {}
pub type TwineRef = *mut Twine_opaque; pub type TwineRef = *mut Twine_opaque;
#[allow(missing_copy_implementations)] extern { pub type DiagnosticInfo_opaque; }
pub enum DiagnosticInfo_opaque {}
pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque; pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
#[allow(missing_copy_implementations)] extern { pub type DebugLoc_opaque; }
pub enum DebugLoc_opaque {}
pub type DebugLocRef = *mut DebugLoc_opaque; pub type DebugLocRef = *mut DebugLoc_opaque;
#[allow(missing_copy_implementations)] extern { pub type SMDiagnostic_opaque; }
pub enum SMDiagnostic_opaque {}
pub type SMDiagnosticRef = *mut SMDiagnostic_opaque; pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
#[allow(missing_copy_implementations)] extern { pub type RustArchiveMember_opaque; }
pub enum RustArchiveMember_opaque {}
pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque; pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
#[allow(missing_copy_implementations)] extern { pub type OperandBundleDef_opaque; }
pub enum OperandBundleDef_opaque {}
pub type OperandBundleDefRef = *mut OperandBundleDef_opaque; pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
#[allow(missing_copy_implementations)] extern { pub type Linker_opaque; }
pub enum Linker_opaque {}
pub type LinkerRef = *mut Linker_opaque; pub type LinkerRef = *mut Linker_opaque;
pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void); pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
@ -457,26 +435,29 @@ pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_v
pub mod debuginfo { pub mod debuginfo {
use super::MetadataRef; use super::Metadata_opaque;
#[allow(missing_copy_implementations)] extern { pub type DIBuilder_opaque; }
pub enum DIBuilder_opaque {}
pub type DIBuilderRef = *mut DIBuilder_opaque; pub type DIBuilderRef = *mut DIBuilder_opaque;
pub type DIDescriptor = MetadataRef; pub type DIDescriptor_opaque = Metadata_opaque;
pub type DIScope = DIDescriptor; pub type DIDescriptor = *mut DIDescriptor_opaque;
pub type DIScope_opaque = DIDescriptor_opaque;
pub type DIScope = *mut DIScope_opaque;
pub type DILocation = DIDescriptor; pub type DILocation = DIDescriptor;
pub type DIFile = DIScope; pub type DIFile = DIScope;
pub type DILexicalBlock = DIScope; pub type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope; pub type DISubprogram = DIScope;
pub type DINameSpace = 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 DIBasicType = DIType;
pub type DIDerivedType = DIType; pub type DIDerivedType = DIType;
pub type DICompositeType = DIDerivedType; pub type DICompositeType = DIDerivedType;
pub type DIVariable = DIDescriptor; pub type DIVariable = DIDescriptor;
pub type DIGlobalVariable = 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 DISubrange = DIDescriptor;
pub type DIEnumerator = DIDescriptor; pub type DIEnumerator = DIDescriptor;
pub type DITemplateTypeParameter = DIDescriptor; pub type DITemplateTypeParameter = DIDescriptor;
@ -512,8 +493,9 @@ pub mod debuginfo {
} }
} }
pub enum ModuleBuffer {} extern { pub type ModuleBuffer; }
#[allow(improper_ctypes)] // TODO remove this (use for NonNull)
extern "C" { extern "C" {
// Create and destroy contexts. // Create and destroy contexts.
pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> ContextRef; pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> ContextRef;
@ -793,7 +775,7 @@ extern "C" {
pub fn LLVMDisposeBuilder(Builder: BuilderRef); pub fn LLVMDisposeBuilder(Builder: BuilderRef);
// Metadata // 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 LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef); pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
@ -819,7 +801,7 @@ extern "C" {
NumArgs: c_uint, NumArgs: c_uint,
Then: BasicBlockRef, Then: BasicBlockRef,
Catch: BasicBlockRef, Catch: BasicBlockRef,
Bundle: OperandBundleDefRef, Bundle: Option<NonNull<OperandBundleDef_opaque>>,
Name: *const c_char) Name: *const c_char)
-> ValueRef; -> ValueRef;
pub fn LLVMBuildLandingPad(B: BuilderRef, pub fn LLVMBuildLandingPad(B: BuilderRef,
@ -832,14 +814,14 @@ extern "C" {
pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef; pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
pub fn LLVMRustBuildCleanupPad(B: BuilderRef, pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
ParentPad: ValueRef, ParentPad: Option<NonNull<Value_opaque>>,
ArgCnt: c_uint, ArgCnt: c_uint,
Args: *const ValueRef, Args: *const ValueRef,
Name: *const c_char) Name: *const c_char)
-> ValueRef; -> ValueRef;
pub fn LLVMRustBuildCleanupRet(B: BuilderRef, pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
CleanupPad: ValueRef, CleanupPad: ValueRef,
UnwindBB: BasicBlockRef) UnwindBB: Option<NonNull<BasicBlock_opaque>>)
-> ValueRef; -> ValueRef;
pub fn LLVMRustBuildCatchPad(B: BuilderRef, pub fn LLVMRustBuildCatchPad(B: BuilderRef,
ParentPad: ValueRef, ParentPad: ValueRef,
@ -849,8 +831,8 @@ extern "C" {
-> ValueRef; -> ValueRef;
pub fn LLVMRustBuildCatchRet(B: BuilderRef, Pad: ValueRef, BB: BasicBlockRef) -> ValueRef; pub fn LLVMRustBuildCatchRet(B: BuilderRef, Pad: ValueRef, BB: BasicBlockRef) -> ValueRef;
pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef, pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
ParentPad: ValueRef, ParentPad: Option<NonNull<Value_opaque>>,
BB: BasicBlockRef, BB: Option<NonNull<BasicBlock_opaque>>,
NumHandlers: c_uint, NumHandlers: c_uint,
Name: *const c_char) Name: *const c_char)
-> ValueRef; -> ValueRef;
@ -1161,7 +1143,7 @@ extern "C" {
Fn: ValueRef, Fn: ValueRef,
Args: *const ValueRef, Args: *const ValueRef,
NumArgs: c_uint, NumArgs: c_uint,
Bundle: OperandBundleDefRef, Bundle: Option<NonNull<OperandBundleDef_opaque>>,
Name: *const c_char) Name: *const c_char)
-> ValueRef; -> ValueRef;
pub fn LLVMBuildSelect(B: BuilderRef, pub fn LLVMBuildSelect(B: BuilderRef,
@ -1433,7 +1415,7 @@ extern "C" {
isOptimized: bool, isOptimized: bool,
Fn: ValueRef, Fn: ValueRef,
TParam: DIArray, TParam: DIArray,
Decl: DIDescriptor) Decl: Option<NonNull<DIDescriptor_opaque>>)
-> DISubprogram; -> DISubprogram;
pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef,
@ -1451,17 +1433,17 @@ extern "C" {
-> DIDerivedType; -> DIDerivedType;
pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef,
Scope: DIDescriptor, Scope: Option<NonNull<DIDescriptor_opaque>>,
Name: *const c_char, Name: *const c_char,
File: DIFile, File: DIFile,
LineNumber: c_uint, LineNumber: c_uint,
SizeInBits: u64, SizeInBits: u64,
AlignInBits: u32, AlignInBits: u32,
Flags: DIFlags, Flags: DIFlags,
DerivedFrom: DIType, DerivedFrom: Option<NonNull<DIType_opaque>>,
Elements: DIArray, Elements: DIArray,
RunTimeLang: c_uint, RunTimeLang: c_uint,
VTableHolder: DIType, VTableHolder: Option<NonNull<DIType_opaque>>,
UniqueId: *const c_char) UniqueId: *const c_char)
-> DICompositeType; -> DICompositeType;
@ -1490,7 +1472,7 @@ extern "C" {
-> DILexicalBlock; -> DILexicalBlock;
pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
Context: DIScope, Context: Option<NonNull<DIScope_opaque>>,
Name: *const c_char, Name: *const c_char,
LinkageName: *const c_char, LinkageName: *const c_char,
File: DIFile, File: DIFile,
@ -1498,7 +1480,7 @@ extern "C" {
Ty: DIType, Ty: DIType,
isLocalToUnit: bool, isLocalToUnit: bool,
Val: ValueRef, Val: ValueRef,
Decl: DIDescriptor, Decl: Option<NonNull<DIDescriptor_opaque>>,
AlignInBits: u32) AlignInBits: u32)
-> DIGlobalVariable; -> DIGlobalVariable;
@ -1535,7 +1517,7 @@ extern "C" {
-> DISubrange; -> DISubrange;
pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
Ptr: *const DIDescriptor, Ptr: *const Option<NonNull<DIDescriptor_opaque>>,
Count: c_uint) Count: c_uint)
-> DIArray; -> DIArray;
@ -1572,7 +1554,7 @@ extern "C" {
SizeInBits: u64, SizeInBits: u64,
AlignInBits: u32, AlignInBits: u32,
Flags: DIFlags, Flags: DIFlags,
Elements: DIArray, Elements: Option<NonNull<DIArray_opaque>>,
RunTimeLang: c_uint, RunTimeLang: c_uint,
UniqueId: *const c_char) UniqueId: *const c_char)
-> DIType; -> DIType;
@ -1580,7 +1562,7 @@ extern "C" {
pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool); pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
Scope: DIScope, Scope: Option<NonNull<DIScope_opaque>>,
Name: *const c_char, Name: *const c_char,
Ty: DIType, Ty: DIType,
File: DIFile, File: DIFile,
@ -1590,7 +1572,7 @@ extern "C" {
pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
Scope: DIScope, Scope: Option<NonNull<DIScope_opaque>>,
Name: *const c_char, Name: *const c_char,
File: DIFile, File: DIFile,
LineNo: c_uint) LineNo: c_uint)
@ -1604,7 +1586,7 @@ extern "C" {
Line: c_uint, Line: c_uint,
Column: c_uint, Column: c_uint,
Scope: DIScope, Scope: DIScope,
InlinedAt: MetadataRef) InlinedAt: Option<NonNull<Metadata_opaque>>)
-> ValueRef; -> ValueRef;
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64; pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64; pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
@ -1720,7 +1702,7 @@ extern "C" {
-> LLVMRustResult; -> LLVMRustResult;
pub fn LLVMRustArchiveMemberNew(Filename: *const c_char, pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
Name: *const c_char, Name: *const c_char,
Child: ArchiveChildRef) Child: Option<NonNull<ArchiveChild_opaque>>)
-> RustArchiveMemberRef; -> RustArchiveMemberRef;
pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef); pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);

View file

@ -11,7 +11,7 @@
use common::{C_i32, C_null}; use common::{C_i32, C_null};
use libc::c_uint; use libc::c_uint;
use llvm::{self, ValueRef, BasicBlockRef}; use llvm::{self, ValueRef, BasicBlockRef};
use llvm::debuginfo::DIScope; use llvm::debuginfo::DIScope_opaque;
use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts}; use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts};
use rustc::ty::layout::{LayoutOf, TyLayout}; use rustc::ty::layout::{LayoutOf, TyLayout};
use rustc::mir::{self, Mir}; use rustc::mir::{self, Mir};
@ -29,6 +29,7 @@ use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
use syntax::symbol::keywords; use syntax::symbol::keywords;
use std::iter; use std::iter;
use std::ptr::NonNull;
use rustc_data_structures::bitvec::BitVector; use rustc_data_structures::bitvec::BitVector;
use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use rustc_data_structures::indexed_vec::{IndexVec, Idx};
@ -121,7 +122,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
debuginfo::set_source_location(&self.debug_context, bx, scope, span); 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. // Bail out if debug info emission is not enabled.
match self.debug_context { match self.debug_context {
FunctionDebugContext::DebugInfoDisabled | FunctionDebugContext::DebugInfoDisabled |
@ -161,16 +162,16 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
// corresponding to span's containing source scope. If so, we need to create a DIScope // corresponding to span's containing source scope. If so, we need to create a DIScope
// "extension" into that file. // "extension" into that file.
fn scope_metadata_for_loc(&self, scope_id: mir::SourceScope, pos: BytePos) 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; let scope_metadata = self.scopes[scope_id].scope_metadata;
if pos < self.scopes[scope_id].file_start_pos || if pos < self.scopes[scope_id].file_start_pos ||
pos >= self.scopes[scope_id].file_end_pos { pos >= self.scopes[scope_id].file_end_pos {
let cm = self.cx.sess().codemap(); let cm = self.cx.sess().codemap();
let defining_crate = self.debug_context.get_ref(DUMMY_SP).defining_crate; let defining_crate = self.debug_context.get_ref(DUMMY_SP).defining_crate;
debuginfo::extend_scope_to_file(self.cx, NonNull::new(debuginfo::extend_scope_to_file(self.cx,
scope_metadata, scope_metadata.unwrap().as_ptr(),
&cm.lookup_char_pos(pos).file, &cm.lookup_char_pos(pos).file,
defining_crate) defining_crate))
} else { } else {
scope_metadata scope_metadata
} }
@ -280,7 +281,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
span: decl.source_info.span, span: decl.source_info.span,
scope: decl.visibility_scope, 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 }, VariableAccess::DirectVariable { alloca: place.llval },
VariableKind::LocalVariable, span); 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. // Get the argument scope, if it exists and if we need it.
let arg_scope = scopes[mir::OUTERMOST_SOURCE_SCOPE]; let arg_scope = scopes[mir::OUTERMOST_SOURCE_SCOPE];
let arg_scope = if arg_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo { let arg_scope = if bx.sess().opts.debuginfo == FullDebugInfo {
Some(arg_scope.scope_metadata) arg_scope.scope_metadata
} else { } else {
None None
}; };
@ -471,7 +472,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
bx, bx,
&fx.debug_context, &fx.debug_context,
arg_decl.name.unwrap_or(keywords::Invalid.name()), arg_decl.name.unwrap_or(keywords::Invalid.name()),
arg_ty, scope, arg_ty, scope.as_ptr(),
variable_access, variable_access,
VariableKind::ArgumentVariable(arg_index + 1), VariableKind::ArgumentVariable(arg_index + 1),
DUMMY_SP DUMMY_SP
@ -550,7 +551,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
&fx.debug_context, &fx.debug_context,
arg_decl.name.unwrap_or(keywords::Invalid.name()), arg_decl.name.unwrap_or(keywords::Invalid.name()),
arg.layout.ty, arg.layout.ty,
scope, scope.as_ptr(),
variable_access, variable_access,
VariableKind::ArgumentVariable(arg_index + 1), VariableKind::ArgumentVariable(arg_index + 1),
DUMMY_SP DUMMY_SP
@ -601,7 +602,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
&fx.debug_context, &fx.debug_context,
decl.debug_name, decl.debug_name,
ty, ty,
scope, scope.as_ptr(),
variable_access, variable_access,
VariableKind::LocalVariable, VariableKind::LocalVariable,
DUMMY_SP DUMMY_SP

View file

@ -24,7 +24,6 @@ use value::Value;
use type_of::LayoutLlvmExt; use type_of::LayoutLlvmExt;
use std::fmt; use std::fmt;
use std::ptr;
use super::{FunctionCx, LocalRef}; use super::{FunctionCx, LocalRef};
use super::constant::scalar_to_llvm; use super::constant::scalar_to_llvm;
@ -160,7 +159,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
let projected_ty = self.layout.ty.builtin_deref(true) let projected_ty = self.layout.ty.builtin_deref(true)
.unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty; .unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)).ty;
let (llptr, llextra) = match self.val { 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::Pair(llptr, llextra) => (llptr, llextra),
OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self) OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self)
}; };

View file

@ -24,8 +24,6 @@ use value::Value;
use glue; use glue;
use mir::constant::const_alloc_to_llvm; use mir::constant::const_alloc_to_llvm;
use std::ptr;
use super::{FunctionCx, LocalRef}; use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue}; use super::operand::{OperandRef, OperandValue};
@ -51,7 +49,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
-> PlaceRef<'tcx> { -> PlaceRef<'tcx> {
PlaceRef { PlaceRef {
llval, llval,
llextra: ptr::null_mut(), llextra: 0 as *mut _,
layout, layout,
align align
} }
@ -126,7 +124,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
}; };
let val = if self.layout.is_llvm_immediate() { let val = if self.layout.is_llvm_immediate() {
let mut const_llval = ptr::null_mut(); let mut const_llval = 0 as *mut _;
unsafe { unsafe {
let global = llvm::LLVMIsAGlobalVariable(self.llval); let global = llvm::LLVMIsAGlobalVariable(self.llval);
if !global.is_null() && llvm::LLVMIsGlobalConstant(global) == llvm::True { if !global.is_null() && llvm::LLVMIsGlobalConstant(global) == llvm::True {
@ -187,7 +185,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
llextra: if cx.type_has_metadata(field.ty) { llextra: if cx.type_has_metadata(field.ty) {
self.llextra self.llextra
} else { } else {
ptr::null_mut() 0 as *mut _
}, },
layout: field, layout: field,
align, align,
@ -390,7 +388,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
-> PlaceRef<'tcx> { -> PlaceRef<'tcx> {
PlaceRef { PlaceRef {
llval: bx.inbounds_gep(self.llval, &[C_usize(bx.cx, 0), llindex]), 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), layout: self.layout.field(bx.cx, 0),
align: self.align align: self.align
} }

View file

@ -22,7 +22,6 @@ use rustc::ty::layout::{self, Align, Size};
use std::ffi::CString; use std::ffi::CString;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ptr;
use libc::c_uint; use libc::c_uint;
@ -103,6 +102,11 @@ impl Type {
ty!(llvm::LLVMIntTypeInContext(cx.llcx, num_bits as c_uint)) 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 { pub fn f32(cx: &CodegenCx) -> Type {
ty!(llvm::LLVMFloatTypeInContext(cx.llcx)) ty!(llvm::LLVMFloatTypeInContext(cx.llcx))
} }
@ -128,12 +132,7 @@ impl Type {
} }
pub fn isize(cx: &CodegenCx) -> Type { pub fn isize(cx: &CodegenCx) -> Type {
match &cx.tcx.sess.target.target.target_pointer_width[..] { cx.isize_ty
"16" => Type::i16(cx),
"32" => Type::i32(cx),
"64" => Type::i64(cx),
tws => bug!("Unsupported target word size for int: {}", tws),
}
} }
pub fn c_int(cx: &CodegenCx) -> Type { pub fn c_int(cx: &CodegenCx) -> Type {
@ -241,7 +240,7 @@ impl Type {
pub fn func_params(&self) -> Vec<Type> { pub fn func_params(&self) -> Vec<Type> {
unsafe { unsafe {
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as usize; 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(), llvm::LLVMGetParamTypes(self.to_ref(),
args.as_mut_ptr() as *mut TypeRef); args.as_mut_ptr() as *mut TypeRef);
args args