[PATCH] Add C bindings for manipulating function return value attributes

Peter Collingbourne peter at pcc.me.uk
Sat Apr 26 23:51:48 PDT 2014


http://reviews.llvm.org/D3522

Files:
  include/llvm-c/Core.h
  lib/IR/Core.cpp

Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h
+++ include/llvm-c/Core.h
@@ -1893,6 +1893,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
@@ -1600,6 +1600,34 @@
   return (LLVMAttribute)PAL.Raw(AttributeSet::FunctionIndex);
 }
 
+void LLVMAddFunctionReturnAttr(LLVMValueRef Fn, LLVMAttribute PA) {
+  Function *Func = unwrap<Function>(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<Function>(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<Function>(Fn);
+  const AttributeSet PAL = Func->getAttributes();
+  return (LLVMAttribute)PAL.Raw(AttributeSet::ReturnIndex);
+}
+
 /*--.. Operations on parameters ............................................--*/
 
 unsigned LLVMCountParams(LLVMValueRef FnRef) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3522.8869.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140427/96fdcde0/attachment.bin>


More information about the llvm-commits mailing list