diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index ebd75be7bba0b..470e8d1fd4578 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -395,9 +395,6 @@ pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque; #[allow(missing_copy_implementations)] pub enum OperandBundleDef_opaque {} pub type OperandBundleDefRef = *mut OperandBundleDef_opaque; -#[allow(missing_copy_implementations)] -pub enum Attribute_opaque {} -pub type AttributeRef = *mut Attribute_opaque; pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void); pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint); @@ -770,8 +767,6 @@ extern "C" { Name: *const c_char) -> ValueRef; - pub fn LLVMRustCreateAttribute(C: ContextRef, kind: Attribute, val: u64) -> AttributeRef; - // Operations on functions pub fn LLVMAddFunction(M: ModuleRef, Name: *const c_char, FunctionTy: TypeRef) -> ValueRef; pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef; @@ -790,12 +785,12 @@ extern "C" { pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char; pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char); pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: u64); - pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: AttributeRef); + pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: Attribute); pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint, Name: *const c_char, Value: *const c_char); - pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: AttributeRef); + pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: Attribute); // Operations on parameters pub fn LLVMCountParams(Fn: ValueRef) -> c_uint; @@ -806,8 +801,6 @@ extern "C" { pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef; pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef; pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef; - pub fn LLVMAddAttribute(Arg: ValueRef, attr: AttributeRef); - pub fn LLVMRemoveAttribute(Arg: ValueRef, attr: AttributeRef); pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint); // Operations on basic blocks @@ -851,7 +844,7 @@ extern "C" { pub fn LLVMAddInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint); pub fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint); pub fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint, align: c_uint); - pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: AttributeRef); + pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: Attribute); pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef, index: c_uint, bytes: u64); // Operations on call instructions (only) diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index c81d3b48aa969..c4ec418f224b5 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -176,20 +176,16 @@ pub fn set_thread_local(global: ValueRef, is_thread_local: bool) { } impl Attribute { - fn as_object(&self, value: ValueRef) -> AttributeRef { - unsafe { LLVMRustCreateAttribute(LLVMRustGetValueContext(value), *self, 0) } - } - pub fn apply_llfn(&self, idx: AttributePlace, llfn: ValueRef) { - unsafe { LLVMRustAddFunctionAttribute(llfn, idx.as_uint(), self.as_object(llfn)) } + unsafe { LLVMRustAddFunctionAttribute(llfn, idx.as_uint(), *self) } } pub fn apply_callsite(&self, idx: AttributePlace, callsite: ValueRef) { - unsafe { LLVMRustAddCallSiteAttribute(callsite, idx.as_uint(), self.as_object(callsite)) } + unsafe { LLVMRustAddCallSiteAttribute(callsite, idx.as_uint(), *self) } } pub fn unapply_llfn(&self, idx: AttributePlace, llfn: ValueRef) { - unsafe { LLVMRustRemoveFunctionAttributes(llfn, idx.as_uint(), self.as_object(llfn)) } + unsafe { LLVMRustRemoveFunctionAttributes(llfn, idx.as_uint(), *self) } } pub fn toggle_llfn(&self, idx: AttributePlace, llfn: ValueRef, set: bool) { diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 7f0c7e2e5c9fa..b035e134e37d5 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -155,13 +155,10 @@ from_rust(LLVMRustAttribute kind) { } } -extern "C" LLVMAttributeRef LLVMRustCreateAttribute(LLVMContextRef C, LLVMRustAttribute Kind, uint64_t Val) { - return wrap(Attribute::get(*unwrap(C), from_rust(Kind), Val)); -} - -extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, LLVMAttributeRef attr) { +extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, LLVMRustAttribute attr) { CallSite Call = CallSite(unwrap(Instr)); - AttrBuilder B(unwrap(attr)); + Attribute Attr = Attribute::get(Call->getContext(), from_rust(attr)); + AttrBuilder B(Attr); Call.setAttributes( Call.getAttributes().addAttributes(Call->getContext(), index, AttributeSet::get(Call->getContext(), @@ -183,10 +180,11 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned index, - LLVMAttributeRef attr) + LLVMRustAttribute attr) { Function *A = unwrap(Fn); - AttrBuilder B(unwrap(attr)); + Attribute Attr = Attribute::get(A->getContext(), from_rust(attr)); + AttrBuilder B(Attr); A->addAttributes(index, AttributeSet::get(A->getContext(), index, B)); } @@ -212,11 +210,12 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, - LLVMAttributeRef attr) + LLVMRustAttribute attr) { Function *F = unwrap(Fn); const AttributeSet PAL = F->getAttributes(); - AttrBuilder B(unwrap(attr)); + Attribute Attr = Attribute::get(F->getContext(), from_rust(attr)); + AttrBuilder B(Attr); const AttributeSet PALnew = PAL.removeAttributes(F->getContext(), index, AttributeSet::get(F->getContext(), index, B));