@@ -203,56 +203,57 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
203203 report_fatal_error (" bad AttributeKind" );
204204}
205205
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+
206214extern " C" void LLVMRustAddCallSiteAttribute (LLVMValueRef Instr, unsigned Index,
207215 LLVMRustAttribute RustAttr) {
208216 CallBase *Call = unwrap<CallBase>(Instr);
209217 Attribute Attr = Attribute::get (Call->getContext (), fromRust (RustAttr));
210- Call-> addAttribute ( Index, Attr);
218+ AddAttribute (Call, Index, Attr);
211219}
212220
213221extern " C" void LLVMRustAddCallSiteAttrString (LLVMValueRef Instr, unsigned Index,
214222 const char *Name) {
215223 CallBase *Call = unwrap<CallBase>(Instr);
216224 Attribute Attr = Attribute::get (Call->getContext (), Name);
217- Call-> addAttribute ( Index, Attr);
225+ AddAttribute (Call, Index, Attr);
218226}
219227
220-
221228extern " C" void LLVMRustAddAlignmentCallSiteAttr (LLVMValueRef Instr,
222229 unsigned Index,
223230 uint32_t Bytes) {
224231 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);
229234}
230235
231236extern " C" void LLVMRustAddDereferenceableCallSiteAttr (LLVMValueRef Instr,
232237 unsigned Index,
233238 uint64_t Bytes) {
234239 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);
239242}
240243
241244extern " C" void LLVMRustAddDereferenceableOrNullCallSiteAttr (LLVMValueRef Instr,
242245 unsigned Index,
243246 uint64_t Bytes) {
244247 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);
249250}
250251
251252extern " C" void LLVMRustAddByValCallSiteAttr (LLVMValueRef Instr, unsigned Index,
252253 LLVMTypeRef Ty) {
253254 CallBase *Call = unwrap<CallBase>(Instr);
254255 Attribute Attr = Attribute::getWithByValType (Call->getContext (), unwrap (Ty));
255- Call-> addAttribute ( Index, Attr);
256+ AddAttribute (Call, Index, Attr);
256257}
257258
258259extern " C" void LLVMRustAddStructRetCallSiteAttr (LLVMValueRef Instr, unsigned Index,
@@ -263,44 +264,44 @@ extern "C" void LLVMRustAddStructRetCallSiteAttr(LLVMValueRef Instr, unsigned In
263264#else
264265 Attribute Attr = Attribute::get (Call->getContext (), Attribute::StructRet);
265266#endif
266- Call-> addAttribute ( Index, Attr);
267+ AddAttribute (Call, Index, Attr);
267268}
268269
269270extern " C" void LLVMRustAddFunctionAttribute (LLVMValueRef Fn, unsigned Index,
270271 LLVMRustAttribute RustAttr) {
271272 Function *A = unwrap<Function>(Fn);
272273 Attribute Attr = Attribute::get (A->getContext (), fromRust (RustAttr));
273- A-> addAttribute ( Index, Attr);
274+ AddAttribute (A, Index, Attr);
274275}
275276
276277extern " C" void LLVMRustAddAlignmentAttr (LLVMValueRef Fn,
277278 unsigned Index,
278279 uint32_t Bytes) {
279280 Function *A = unwrap<Function>(Fn);
280- A-> addAttribute ( Index, Attribute::getWithAlignment (
281+ AddAttribute (A, Index, Attribute::getWithAlignment (
281282 A->getContext (), llvm::Align (Bytes)));
282283}
283284
284285extern " C" void LLVMRustAddDereferenceableAttr (LLVMValueRef Fn, unsigned Index,
285286 uint64_t Bytes) {
286287 Function *A = unwrap<Function>(Fn);
287- A-> addAttribute ( Index, Attribute::getWithDereferenceableBytes (A->getContext (),
288+ AddAttribute (A, Index, Attribute::getWithDereferenceableBytes (A->getContext (),
288289 Bytes));
289290}
290291
291292extern " C" void LLVMRustAddDereferenceableOrNullAttr (LLVMValueRef Fn,
292293 unsigned Index,
293294 uint64_t Bytes) {
294295 Function *A = unwrap<Function>(Fn);
295- A-> addAttribute ( Index, Attribute::getWithDereferenceableOrNullBytes (
296+ AddAttribute (A, Index, Attribute::getWithDereferenceableOrNullBytes (
296297 A->getContext (), Bytes));
297298}
298299
299300extern " C" void LLVMRustAddByValAttr (LLVMValueRef Fn, unsigned Index,
300301 LLVMTypeRef Ty) {
301302 Function *F = unwrap<Function>(Fn);
302303 Attribute Attr = Attribute::getWithByValType (F->getContext (), unwrap (Ty));
303- F-> addAttribute ( Index, Attr);
304+ AddAttribute (F, Index, Attr);
304305}
305306
306307extern " C" void LLVMRustAddStructRetAttr (LLVMValueRef Fn, unsigned Index,
@@ -311,15 +312,15 @@ extern "C" void LLVMRustAddStructRetAttr(LLVMValueRef Fn, unsigned Index,
311312#else
312313 Attribute Attr = Attribute::get (F->getContext (), Attribute::StructRet);
313314#endif
314- F-> addAttribute ( Index, Attr);
315+ AddAttribute (F, Index, Attr);
315316}
316317
317318extern " C" void LLVMRustAddFunctionAttrStringValue (LLVMValueRef Fn,
318319 unsigned Index,
319320 const char *Name,
320321 const char *Value) {
321322 Function *F = unwrap<Function>(Fn);
322- F-> addAttribute ( Index, Attribute::get (
323+ AddAttribute (F, Index, Attribute::get (
323324 F->getContext (), StringRef (Name), StringRef (Value)));
324325}
325326
@@ -330,7 +331,12 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
330331 Attribute Attr = Attribute::get (F->getContext (), fromRust (RustAttr));
331332 AttrBuilder B (Attr);
332333 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
334340 F->setAttributes (PALNew);
335341}
336342
0 commit comments