Skip to content

Restore compatibility with LLVM 3.7 and 3.8 #37912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 9 additions & 10 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction>(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(),
Expand All @@ -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<Function>(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));
}

Expand All @@ -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<Function>(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));
Expand Down