Index: bindings/go/llvm/ir.go =================================================================== --- bindings/go/llvm/ir.go +++ bindings/go/llvm/ir.go @@ -1040,6 +1040,20 @@ C.LLVMAddTargetDependentFunctionAttr(v.C, cattr, cvalue) } +func (v Value) AddFunctionReturnAttr(a Attribute) { + if a >= 1<<32 { + panic("attribute value currently unsupported") + } + C.LLVMAddFunctionReturnAttr(v.C, C.LLVMAttribute(a)) +} +func (v Value) RemoveFunctionReturnAttr(a Attribute) { + if a >= 1<<32 { + panic("attribute value currently unsupported") + } + C.LLVMRemoveFunctionReturnAttr(v.C, C.LLVMAttribute(a)) +} +func (v Value) FunctionReturnAttr() Attribute { return Attribute(C.LLVMGetFunctionReturnAttr(v.C)) } + // Operations on parameters func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) } func (v Value) Params() []Value { Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -1946,6 +1946,25 @@ void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); /** + * Add an attribute to the return value of a function. + * + * @see llvm::Function::addAttribute() + */ +void LLVMAddFunctionReturnAttr(LLVMValueRef Fn, LLVMAttribute PA); + +/** + * Obtain an attribute from the return value of a function. + * + * @see llvm::Function::getAttributes() + */ +LLVMAttribute LLVMGetFunctionReturnAttr(LLVMValueRef Fn); + +/** + * Remove an attribute from the return value of a function. + */ +void LLVMRemoveFunctionReturnAttr(LLVMValueRef Fn, LLVMAttribute PA); + +/** * @defgroup LLVMCCoreValueFunctionParameters Function Parameters * * Functions in this group relate to arguments/parameters on functions. Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -1662,6 +1662,34 @@ return (LLVMAttribute)PAL.Raw(AttributeSet::FunctionIndex); } +void LLVMAddFunctionReturnAttr(LLVMValueRef Fn, LLVMAttribute PA) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + AttrBuilder B(PA); + const AttributeSet PALnew = + PAL.addAttributes(Func->getContext(), AttributeSet::ReturnIndex, + AttributeSet::get(Func->getContext(), + AttributeSet::ReturnIndex, B)); + Func->setAttributes(PALnew); +} + +void LLVMRemoveFunctionReturnAttr(LLVMValueRef Fn, LLVMAttribute PA) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + AttrBuilder B(PA); + const AttributeSet PALnew = + PAL.removeAttributes(Func->getContext(), AttributeSet::ReturnIndex, + AttributeSet::get(Func->getContext(), + AttributeSet::ReturnIndex, B)); + Func->setAttributes(PALnew); +} + +LLVMAttribute LLVMGetFunctionReturnAttr(LLVMValueRef Fn) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + return (LLVMAttribute)PAL.Raw(AttributeSet::ReturnIndex); +} + /*--.. Operations on parameters ............................................--*/ unsigned LLVMCountParams(LLVMValueRef FnRef) {