@@ -203,56 +203,57 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
203
203
report_fatal_error (" bad AttributeKind" );
204
204
}
205
205
206
+ template <typename T> static inline void AddAttribute (T *t, unsigned Index, Attribute Attr) {
207
+ #if LLVM_VERSION_LT(14, 0)
208
+ t->addAttribute (Index, Attr);
209
+ #else
210
+ t->addAttributeAtIndex (Index, Attr);
211
+ #endif
212
+ }
213
+
206
214
extern " C" void LLVMRustAddCallSiteAttribute (LLVMValueRef Instr, unsigned Index,
207
215
LLVMRustAttribute RustAttr) {
208
216
CallBase *Call = unwrap<CallBase>(Instr);
209
217
Attribute Attr = Attribute::get (Call->getContext (), fromRust (RustAttr));
210
- Call-> addAttribute ( Index, Attr);
218
+ AddAttribute (Call, Index, Attr);
211
219
}
212
220
213
221
extern " C" void LLVMRustAddCallSiteAttrString (LLVMValueRef Instr, unsigned Index,
214
222
const char *Name) {
215
223
CallBase *Call = unwrap<CallBase>(Instr);
216
224
Attribute Attr = Attribute::get (Call->getContext (), Name);
217
- Call-> addAttribute ( Index, Attr);
225
+ AddAttribute (Call, Index, Attr);
218
226
}
219
227
220
-
221
228
extern " C" void LLVMRustAddAlignmentCallSiteAttr (LLVMValueRef Instr,
222
229
unsigned Index,
223
230
uint32_t Bytes) {
224
231
CallBase *Call = unwrap<CallBase>(Instr);
225
- AttrBuilder B;
226
- B.addAlignmentAttr (Bytes);
227
- Call->setAttributes (Call->getAttributes ().addAttributes (
228
- Call->getContext (), Index, B));
232
+ Attribute Attr = Attribute::getWithAlignment (Call->getContext (), Align (Bytes));
233
+ AddAttribute (Call, Index, Attr);
229
234
}
230
235
231
236
extern " C" void LLVMRustAddDereferenceableCallSiteAttr (LLVMValueRef Instr,
232
237
unsigned Index,
233
238
uint64_t Bytes) {
234
239
CallBase *Call = unwrap<CallBase>(Instr);
235
- AttrBuilder B;
236
- B.addDereferenceableAttr (Bytes);
237
- Call->setAttributes (Call->getAttributes ().addAttributes (
238
- Call->getContext (), Index, B));
240
+ Attribute Attr = Attribute::getWithDereferenceableBytes (Call->getContext (), Bytes);
241
+ AddAttribute (Call, Index, Attr);
239
242
}
240
243
241
244
extern " C" void LLVMRustAddDereferenceableOrNullCallSiteAttr (LLVMValueRef Instr,
242
245
unsigned Index,
243
246
uint64_t Bytes) {
244
247
CallBase *Call = unwrap<CallBase>(Instr);
245
- AttrBuilder B;
246
- B.addDereferenceableOrNullAttr (Bytes);
247
- Call->setAttributes (Call->getAttributes ().addAttributes (
248
- Call->getContext (), Index, B));
248
+ Attribute Attr = Attribute::getWithDereferenceableOrNullBytes (Call->getContext (), Bytes);
249
+ AddAttribute (Call, Index, Attr);
249
250
}
250
251
251
252
extern " C" void LLVMRustAddByValCallSiteAttr (LLVMValueRef Instr, unsigned Index,
252
253
LLVMTypeRef Ty) {
253
254
CallBase *Call = unwrap<CallBase>(Instr);
254
255
Attribute Attr = Attribute::getWithByValType (Call->getContext (), unwrap (Ty));
255
- Call-> addAttribute ( Index, Attr);
256
+ AddAttribute (Call, Index, Attr);
256
257
}
257
258
258
259
extern " C" void LLVMRustAddStructRetCallSiteAttr (LLVMValueRef Instr, unsigned Index,
@@ -263,44 +264,44 @@ extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned In
263
264
#else
264
265
Attribute Attr = Attribute::get (Call->getContext (), Attribute::StructRet);
265
266
#endif
266
- Call-> addAttribute ( Index, Attr);
267
+ AddAttribute (Call, Index, Attr);
267
268
}
268
269
269
270
extern " C" void LLVMRustAddFunctionAttribute (LLVMValueRef Fn, unsigned Index,
270
271
LLVMRustAttribute RustAttr) {
271
272
Function *A = unwrap<Function>(Fn);
272
273
Attribute Attr = Attribute::get (A->getContext (), fromRust (RustAttr));
273
- A-> addAttribute ( Index, Attr);
274
+ AddAttribute (A, Index, Attr);
274
275
}
275
276
276
277
extern " C" void LLVMRustAddAlignmentAttr (LLVMValueRef Fn,
277
278
unsigned Index,
278
279
uint32_t Bytes) {
279
280
Function *A = unwrap<Function>(Fn);
280
- A-> addAttribute ( Index, Attribute::getWithAlignment (
281
+ AddAttribute (A, Index, Attribute::getWithAlignment (
281
282
A->getContext (), llvm::Align (Bytes)));
282
283
}
283
284
284
285
extern " C" void LLVMRustAddDereferenceableAttr (LLVMValueRef Fn, unsigned Index,
285
286
uint64_t Bytes) {
286
287
Function *A = unwrap<Function>(Fn);
287
- A-> addAttribute ( Index, Attribute::getWithDereferenceableBytes (A->getContext (),
288
+ AddAttribute (A, Index, Attribute::getWithDereferenceableBytes (A->getContext (),
288
289
Bytes));
289
290
}
290
291
291
292
extern " C" void LLVMRustAddDereferenceableOrNullAttr (LLVMValueRef Fn,
292
293
unsigned Index,
293
294
uint64_t Bytes) {
294
295
Function *A = unwrap<Function>(Fn);
295
- A-> addAttribute ( Index, Attribute::getWithDereferenceableOrNullBytes (
296
+ AddAttribute (A, Index, Attribute::getWithDereferenceableOrNullBytes (
296
297
A->getContext (), Bytes));
297
298
}
298
299
299
300
extern " C" void LLVMRustAddByValAttr (LLVMValueRef Fn, unsigned Index,
300
301
LLVMTypeRef Ty) {
301
302
Function *F = unwrap<Function>(Fn);
302
303
Attribute Attr = Attribute::getWithByValType (F->getContext (), unwrap (Ty));
303
- F-> addAttribute ( Index, Attr);
304
+ AddAttribute (F, Index, Attr);
304
305
}
305
306
306
307
extern " C" void LLVMRustAddStructRetAttr (LLVMValueRef Fn, unsigned Index,
@@ -311,15 +312,15 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
311
312
#else
312
313
Attribute Attr = Attribute::get (F->getContext (), Attribute::StructRet);
313
314
#endif
314
- F-> addAttribute ( Index, Attr);
315
+ AddAttribute (F, Index, Attr);
315
316
}
316
317
317
318
extern " C" void LLVMRustAddFunctionAttrStringValue (LLVMValueRef Fn,
318
319
unsigned Index,
319
320
const char *Name,
320
321
const char *Value) {
321
322
Function *F = unwrap<Function>(Fn);
322
- F-> addAttribute ( Index, Attribute::get (
323
+ AddAttribute (F, Index, Attribute::get (
323
324
F->getContext (), StringRef (Name), StringRef (Value)));
324
325
}
325
326
@@ -330,7 +331,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
330
331
Attribute Attr = Attribute::get (F->getContext (), fromRust (RustAttr));
331
332
AttrBuilder B (Attr);
332
333
auto PAL = F->getAttributes ();
333
- auto PALNew = PAL.removeAttributes (F->getContext (), Index, B);
334
+ AttributeList PALNew;
335
+ #if LLVM_VERSION_LT(14, 0)
336
+ PALNew = PAL.removeAttributes (F->getContext (), Index, B);
337
+ #else
338
+ PALNew = PAL.removeAttributesAtIndex (F->getContext (), Index, B);
339
+ #endif
334
340
F->setAttributes (PALNew);
335
341
}
336
342
0 commit comments