Skip to content

Commit c45f3de

Browse files
committedNov 21, 2016
Restore compatibility with LLVM 3.7 and 3.8
1 parent fc2373c commit c45f3de

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed
 

‎src/librustc_llvm/ffi.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,6 @@ pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
395395
#[allow(missing_copy_implementations)]
396396
pub enum OperandBundleDef_opaque {}
397397
pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
398-
#[allow(missing_copy_implementations)]
399-
pub enum Attribute_opaque {}
400-
pub type AttributeRef = *mut Attribute_opaque;
401398

402399
pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
403400
pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
@@ -770,8 +767,6 @@ extern "C" {
770767
Name: *const c_char)
771768
-> ValueRef;
772769

773-
pub fn LLVMRustCreateAttribute(C: ContextRef, kind: Attribute, val: u64) -> AttributeRef;
774-
775770
// Operations on functions
776771
pub fn LLVMAddFunction(M: ModuleRef, Name: *const c_char, FunctionTy: TypeRef) -> ValueRef;
777772
pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
@@ -790,12 +785,12 @@ extern "C" {
790785
pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
791786
pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
792787
pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: u64);
793-
pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: AttributeRef);
788+
pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: Attribute);
794789
pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef,
795790
index: c_uint,
796791
Name: *const c_char,
797792
Value: *const c_char);
798-
pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: AttributeRef);
793+
pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: Attribute);
799794

800795
// Operations on parameters
801796
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
@@ -806,8 +801,6 @@ extern "C" {
806801
pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
807802
pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
808803
pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
809-
pub fn LLVMAddAttribute(Arg: ValueRef, attr: AttributeRef);
810-
pub fn LLVMRemoveAttribute(Arg: ValueRef, attr: AttributeRef);
811804
pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
812805

813806
// Operations on basic blocks
@@ -851,7 +844,7 @@ extern "C" {
851844
pub fn LLVMAddInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint);
852845
pub fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint);
853846
pub fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint, align: c_uint);
854-
pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: AttributeRef);
847+
pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: Attribute);
855848
pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef, index: c_uint, bytes: u64);
856849

857850
// Operations on call instructions (only)

‎src/librustc_llvm/lib.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,16 @@ pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
176176
}
177177

178178
impl Attribute {
179-
fn as_object(&self, value: ValueRef) -> AttributeRef {
180-
unsafe { LLVMRustCreateAttribute(LLVMRustGetValueContext(value), *self, 0) }
181-
}
182-
183179
pub fn apply_llfn(&self, idx: AttributePlace, llfn: ValueRef) {
184-
unsafe { LLVMRustAddFunctionAttribute(llfn, idx.as_uint(), self.as_object(llfn)) }
180+
unsafe { LLVMRustAddFunctionAttribute(llfn, idx.as_uint(), *self) }
185181
}
186182

187183
pub fn apply_callsite(&self, idx: AttributePlace, callsite: ValueRef) {
188-
unsafe { LLVMRustAddCallSiteAttribute(callsite, idx.as_uint(), self.as_object(callsite)) }
184+
unsafe { LLVMRustAddCallSiteAttribute(callsite, idx.as_uint(), *self) }
189185
}
190186

191187
pub fn unapply_llfn(&self, idx: AttributePlace, llfn: ValueRef) {
192-
unsafe { LLVMRustRemoveFunctionAttributes(llfn, idx.as_uint(), self.as_object(llfn)) }
188+
unsafe { LLVMRustRemoveFunctionAttributes(llfn, idx.as_uint(), *self) }
193189
}
194190

195191
pub fn toggle_llfn(&self, idx: AttributePlace, llfn: ValueRef, set: bool) {

‎src/rustllvm/RustWrapper.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ from_rust(LLVMRustAttribute kind) {
155155
}
156156
}
157157

158-
extern "C" LLVMAttributeRef LLVMRustCreateAttribute(LLVMContextRef C, LLVMRustAttribute Kind, uint64_t Val) {
159-
return wrap(Attribute::get(*unwrap(C), from_rust(Kind), Val));
160-
}
161-
162-
extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, LLVMAttributeRef attr) {
158+
extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, LLVMRustAttribute attr) {
163159
CallSite Call = CallSite(unwrap<Instruction>(Instr));
164-
AttrBuilder B(unwrap(attr));
160+
Attribute Attr = Attribute::get(Call->getContext(), from_rust(attr));
161+
AttrBuilder B(Attr);
165162
Call.setAttributes(
166163
Call.getAttributes().addAttributes(Call->getContext(), index,
167164
AttributeSet::get(Call->getContext(),
@@ -183,10 +180,11 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
183180

184181
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn,
185182
unsigned index,
186-
LLVMAttributeRef attr)
183+
LLVMRustAttribute attr)
187184
{
188185
Function *A = unwrap<Function>(Fn);
189-
AttrBuilder B(unwrap(attr));
186+
Attribute Attr = Attribute::get(A->getContext(), from_rust(attr));
187+
AttrBuilder B(Attr);
190188
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
191189
}
192190

@@ -212,11 +210,12 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
212210

213211
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
214212
unsigned index,
215-
LLVMAttributeRef attr)
213+
LLVMRustAttribute attr)
216214
{
217215
Function *F = unwrap<Function>(Fn);
218216
const AttributeSet PAL = F->getAttributes();
219-
AttrBuilder B(unwrap(attr));
217+
Attribute Attr = Attribute::get(F->getContext(), from_rust(attr));
218+
AttrBuilder B(Attr);
220219
const AttributeSet PALnew =
221220
PAL.removeAttributes(F->getContext(), index,
222221
AttributeSet::get(F->getContext(), index, B));

0 commit comments

Comments
 (0)
Please sign in to comment.