Skip to content

Commit b022d54

Browse files
alexcrichtonTimNN
authored andcommitted
update attributes API usage
1 parent 1ee87b3 commit b022d54

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/rustllvm/RustWrapper.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,14 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index,
167167
LLVMRustAttribute RustAttr) {
168168
CallSite Call = CallSite(unwrap<Instruction>(Instr));
169169
Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr));
170+
#if LLVM_VERSION_GE(5, 0)
171+
Call.addAttribute(Index, Attr);
172+
#else
170173
AttrBuilder B(Attr);
171174
Call.setAttributes(Call.getAttributes().addAttributes(
172175
Call->getContext(), Index,
173176
AttributeSet::get(Call->getContext(), Index, B)));
177+
#endif
174178
}
175179

176180
extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
@@ -179,25 +183,38 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
179183
CallSite Call = CallSite(unwrap<Instruction>(Instr));
180184
AttrBuilder B;
181185
B.addDereferenceableAttr(Bytes);
186+
#if LLVM_VERSION_GE(5, 0)
187+
Call.setAttributes(Call.getAttributes().addAttributes(
188+
Call->getContext(), Index, B));
189+
#else
182190
Call.setAttributes(Call.getAttributes().addAttributes(
183191
Call->getContext(), Index,
184192
AttributeSet::get(Call->getContext(), Index, B)));
193+
#endif
185194
}
186195

187196
extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index,
188197
LLVMRustAttribute RustAttr) {
189198
Function *A = unwrap<Function>(Fn);
190199
Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr));
191200
AttrBuilder B(Attr);
201+
#if LLVM_VERSION_GE(5, 0)
202+
A->addAttributes(Index, B);
203+
#else
192204
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
205+
#endif
193206
}
194207

195208
extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index,
196209
uint64_t Bytes) {
197210
Function *A = unwrap<Function>(Fn);
198211
AttrBuilder B;
199212
B.addDereferenceableAttr(Bytes);
213+
#if LLVM_VERSION_GE(5, 0)
214+
A->addAttributes(Index, B);
215+
#else
200216
A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B));
217+
#endif
201218
}
202219

203220
extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
@@ -207,18 +224,26 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
207224
Function *F = unwrap<Function>(Fn);
208225
AttrBuilder B;
209226
B.addAttribute(Name, Value);
227+
#if LLVM_VERSION_GE(5, 0)
228+
F->addAttributes(Index, B);
229+
#else
210230
F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B));
231+
#endif
211232
}
212233

213234
extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
214235
unsigned Index,
215236
LLVMRustAttribute RustAttr) {
216237
Function *F = unwrap<Function>(Fn);
217-
const AttributeSet PAL = F->getAttributes();
218238
Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr));
219239
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
220244
const AttributeSet PALNew = PAL.removeAttributes(
221245
F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B));
246+
#endif
222247
F->setAttributes(PALNew);
223248
}
224249

0 commit comments

Comments
 (0)