Skip to content

Commit 4d04540

Browse files
committed
RustWrapper: remove some uses of AttrBuilder
Turns out we can also use Attribute::get*() methods here, and avoid the AttrBuilder and an extra helper method here.
1 parent 484b79b commit 4d04540

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -225,41 +225,28 @@ extern "C" void LLVMRustAddCallSiteAttrString(LLVMValueRef Instr, unsigned Index
225225
AddAttribute(Call, Index, Attr);
226226
}
227227

228-
static inline void AddCallAttributes(CallBase *Call, unsigned Index, const AttrBuilder& B) {
229-
AttributeList Attrs = Call->getAttributes();
230-
#if LLVM_VERSION_LT(14, 0)
231-
Attrs = Attrs.addAttributes(Call->getContext(), Index, B);
232-
#else
233-
Attrs = Attrs.addAttributesAtIndex(Call->getContext(), Index, B);
234-
#endif
235-
Call->setAttributes(Attrs);
236-
}
237-
238228
extern "C" void LLVMRustAddAlignmentCallSiteAttr(LLVMValueRef Instr,
239229
unsigned Index,
240230
uint32_t Bytes) {
241231
CallBase *Call = unwrap<CallBase>(Instr);
242-
AttrBuilder B;
243-
B.addAlignmentAttr(Bytes);
244-
AddCallAttributes(Call, Index, B);
232+
Attribute Attr = Attribute::getWithAlignment(Call->getContext(), Align(Bytes));
233+
AddAttribute(Call, Index, Attr);
245234
}
246235

247236
extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
248237
unsigned Index,
249238
uint64_t Bytes) {
250239
CallBase *Call = unwrap<CallBase>(Instr);
251-
AttrBuilder B;
252-
B.addDereferenceableAttr(Bytes);
253-
AddCallAttributes(Call, Index, B);
240+
Attribute Attr = Attribute::getWithDereferenceableBytes(Call->getContext(), Bytes);
241+
AddAttribute(Call, Index, Attr);
254242
}
255243

256244
extern "C" void LLVMRustAddDereferenceableOrNullCallSiteAttr(LLVMValueRef Instr,
257245
unsigned Index,
258246
uint64_t Bytes) {
259247
CallBase *Call = unwrap<CallBase>(Instr);
260-
AttrBuilder B;
261-
B.addDereferenceableOrNullAttr(Bytes);
262-
AddCallAttributes(Call, Index, B);
248+
Attribute Attr = Attribute::getWithDereferenceableOrNullBytes(Call->getContext(), Bytes);
249+
AddAttribute(Call, Index, Attr);
263250
}
264251

265252
extern "C" void LLVMRustAddByValCallSiteAttr(LLVMValueRef Instr, unsigned Index,

0 commit comments

Comments
 (0)