// except according to those terms.
use std::ffi::CString;
-use std::ptr;
use attributes;
use libc::c_uint;
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() {
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;
let name = CString::new(child_name)?;
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(),
- child.raw()));
+ NonNull::new(child.raw())));
strings.push(name);
}
}
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);
}
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);
}
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
.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,
.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(),
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,
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)
};
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,
use std::ffi::{CStr, CString};
use std::cell::{Cell, RefCell};
-use std::ptr;
use std::iter;
use std::str;
use std::sync::Arc;
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,
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
+ }
}
}
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;
#[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,
impl MirDebugScope {
pub fn is_valid(&self) -> bool {
- !self.scope_metadata.is_null()
+ !self.scope_metadata.is_none()
}
}
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)
};
// 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,
};
// 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;
}
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,
use type_::Type;
use rustc::session::config::NoDebugInfo;
-use std::ptr;
use syntax::attr;
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";
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};
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};
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);
};
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]);
&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);
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
},
struct_type,
&struct_name,
unique_type_id,
- containing_scope);
+ NonNull::new(containing_scope));
create_and_register_recursive_type_forward_declaration(
cx,
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 {
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();
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())
};
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.
}
}
- 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(),
member_description.align.abi_bits() as u32,
member_description.offset.bits(),
member_description.flags,
- member_description.type_metadata)
+ member_description.type_metadata))
}
})
.collect();
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);
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())
};
union_size.bits(),
union_align.abi_bits() as u32,
DIFlags::FlagZero,
- empty_array,
+ NonNull::new(empty_array),
0, // RuntimeLang
unique_type_id.as_ptr())
};
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
type_metadata,
is_local_to_unit,
global,
- ptr::null_mut(),
+ None,
global_align.abi() as u32,
);
}
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()
);
vtable_type,
true,
vtable,
- ptr::null_mut(),
+ None,
0);
}
}
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;
cx.sess().opts.optimize != config::OptLevel::No,
llfn,
template_parameters,
- ptr::null_mut())
+ None)
};
// Initialize fn debug context (including scope map and namespace map)
// 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 {
}
_ => 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))
+ })
);
}
}
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
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>,
}
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 {
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,
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
};
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
}
};
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
}
#[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)
};
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(custom_attribute)]
+#![feature(extern_types)]
#![feature(fs_read_write)]
#![allow(unused_attributes)]
#![feature(libc)]
pub use self::Diagnostic::*;
use libc::c_uint;
-use std::ptr;
use super::{DiagnosticInfoRef, TwineRef, ValueRef};
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;
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,
// 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;
}
/// LLVMRustThinLTOData
-pub enum ThinLTOData {}
+extern { pub type ThinLTOData; }
/// LLVMRustThinLTOBuffer
-pub enum ThinLTOBuffer {}
+extern { pub type ThinLTOBuffer; }
/// LLVMRustThinLTOModule
#[repr(C)]
}
// 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);
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;
}
}
-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;
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);
NumArgs: c_uint,
Then: BasicBlockRef,
Catch: BasicBlockRef,
- Bundle: OperandBundleDefRef,
+ Bundle: Option<NonNull<OperandBundleDef_opaque>>,
Name: *const c_char)
-> ValueRef;
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,
-> 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;
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,
isOptimized: bool,
Fn: ValueRef,
TParam: DIArray,
- Decl: DIDescriptor)
+ Decl: Option<NonNull<DIDescriptor_opaque>>)
-> DISubprogram;
pub fn LLVMRustDIBuilderCreateBasicType(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;
-> DILexicalBlock;
pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
- Context: DIScope,
+ Context: Option<NonNull<DIScope_opaque>>,
Name: *const c_char,
LinkageName: *const c_char,
File: DIFile,
Ty: DIType,
isLocalToUnit: bool,
Val: ValueRef,
- Decl: DIDescriptor,
+ Decl: Option<NonNull<DIDescriptor_opaque>>,
AlignInBits: u32)
-> DIGlobalVariable;
-> DISubrange;
pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
- Ptr: *const DIDescriptor,
+ Ptr: *const Option<NonNull<DIDescriptor_opaque>>,
Count: c_uint)
-> DIArray;
SizeInBits: u64,
AlignInBits: u32,
Flags: DIFlags,
- Elements: DIArray,
+ Elements: Option<NonNull<DIArray_opaque>>,
RunTimeLang: c_uint,
UniqueId: *const c_char)
-> DIType;
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,
pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
- Scope: DIScope,
+ Scope: Option<NonNull<DIScope_opaque>>,
Name: *const c_char,
File: DIFile,
LineNo: c_uint)
Line: c_uint,
Column: c_uint,
Scope: DIScope,
- InlinedAt: MetadataRef)
+ InlinedAt: Option<NonNull<Metadata_opaque>>)
-> ValueRef;
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
-> 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);
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};
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};
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 |
// 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
}
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);
}
// 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
};
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
&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
&fx.debug_context,
decl.debug_name,
ty,
- scope,
+ scope.as_ptr(),
variable_access,
VariableKind::LocalVariable,
DUMMY_SP
use type_of::LayoutLlvmExt;
use std::fmt;
-use std::ptr;
use super::{FunctionCx, LocalRef};
use super::constant::scalar_to_llvm;
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)
};
use glue;
use mir::constant::const_alloc_to_llvm;
-use std::ptr;
-
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};
-> PlaceRef<'tcx> {
PlaceRef {
llval,
- llextra: ptr::null_mut(),
+ llextra: 0 as *mut _,
layout,
align
}
};
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 {
llextra: if cx.type_has_metadata(field.ty) {
self.llextra
} else {
- ptr::null_mut()
+ 0 as *mut _
},
layout: field,
align,
-> 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
}
use std::ffi::CString;
use std::fmt;
use std::mem;
-use std::ptr;
use libc::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 {
ty!(llvm::LLVMFloatTypeInContext(cx.llcx))
}
}
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 {
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