@@ -167,10 +167,14 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
167
167
LLVMRustAttribute RustAttr) {
168
168
CallSite Call = CallSite (unwrap<Instruction>(Instr));
169
169
Attribute Attr = Attribute::get (Call->getContext (), fromRust (RustAttr));
170
+ #if LLVM_VERSION_GE(5, 0)
171
+ Call.addAttribute (Index, Attr);
172
+ #else
170
173
AttrBuilder B (Attr);
171
174
Call.setAttributes (Call.getAttributes ().addAttributes (
172
175
Call->getContext (), Index,
173
176
AttributeSet::get (Call->getContext (), Index, B)));
177
+ #endif
174
178
}
175
179
176
180
extern " C" void LLVMRustAddDereferenceableCallSiteAttr (LLVMValueRef Instr,
@@ -179,25 +183,38 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
179
183
CallSite Call = CallSite (unwrap<Instruction>(Instr));
180
184
AttrBuilder B;
181
185
B.addDereferenceableAttr (Bytes);
186
+ #if LLVM_VERSION_GE(5, 0)
187
+ Call.setAttributes (Call.getAttributes ().addAttributes (
188
+ Call->getContext (), Index, B));
189
+ #else
182
190
Call.setAttributes (Call.getAttributes ().addAttributes (
183
191
Call->getContext (), Index,
184
192
AttributeSet::get (Call->getContext (), Index, B)));
193
+ #endif
185
194
}
186
195
187
196
extern " C" void LLVMRustAddFunctionAttribute (LLVMValueRef Fn, unsigned Index,
188
197
LLVMRustAttribute RustAttr) {
189
198
Function *A = unwrap<Function>(Fn);
190
199
Attribute Attr = Attribute::get (A->getContext (), fromRust (RustAttr));
191
200
AttrBuilder B (Attr);
201
+ #if LLVM_VERSION_GE(5, 0)
202
+ A->addAttributes (Index, B);
203
+ #else
192
204
A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
205
+ #endif
193
206
}
194
207
195
208
extern " C" void LLVMRustAddDereferenceableAttr (LLVMValueRef Fn, unsigned Index,
196
209
uint64_t Bytes) {
197
210
Function *A = unwrap<Function>(Fn);
198
211
AttrBuilder B;
199
212
B.addDereferenceableAttr (Bytes);
213
+ #if LLVM_VERSION_GE(5, 0)
214
+ A->addAttributes (Index, B);
215
+ #else
200
216
A->addAttributes (Index, AttributeSet::get (A->getContext (), Index, B));
217
+ #endif
201
218
}
202
219
203
220
extern " C" void LLVMRustAddFunctionAttrStringValue (LLVMValueRef Fn,
@@ -207,18 +224,26 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
207
224
Function *F = unwrap<Function>(Fn);
208
225
AttrBuilder B;
209
226
B.addAttribute (Name, Value);
227
+ #if LLVM_VERSION_GE(5, 0)
228
+ F->addAttributes (Index, B);
229
+ #else
210
230
F->addAttributes (Index, AttributeSet::get (F->getContext (), Index, B));
231
+ #endif
211
232
}
212
233
213
234
extern " C" void LLVMRustRemoveFunctionAttributes (LLVMValueRef Fn,
214
235
unsigned Index,
215
236
LLVMRustAttribute RustAttr) {
216
237
Function *F = unwrap<Function>(Fn);
217
- const AttributeSet PAL = F->getAttributes ();
218
238
Attribute Attr = Attribute::get (F->getContext (), fromRust (RustAttr));
219
239
AttrBuilder B (Attr);
240
+ auto PAL = F->getAttributes ();
241
+ #if LLVM_VERSION_GE(5, 0)
242
+ auto PALNew = PAL.removeAttributes (F->getContext (), Index, B);
243
+ #else
220
244
const AttributeSet PALNew = PAL.removeAttributes (
221
245
F->getContext (), Index, AttributeSet::get (F->getContext (), Index, B));
246
+ #endif
222
247
F->setAttributes (PALNew);
223
248
}
224
249
0 commit comments