[PATCH] D16942: Add C binding for AllocaInst::getAllocatedType

Amaury SECHET via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 14:55:17 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL260313: Add C binding for AllocaInst::getAllocatedType (authored by deadalnix).

Changed prior to commit:
  http://reviews.llvm.org/D16942?vs=47079&id=47373#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16942

Files:
  llvm/trunk/include/llvm-c/Core.h
  llvm/trunk/lib/IR/Core.cpp
  llvm/trunk/tools/llvm-c-test/echo.cpp

Index: llvm/trunk/include/llvm-c/Core.h
===================================================================
--- llvm/trunk/include/llvm-c/Core.h
+++ llvm/trunk/include/llvm-c/Core.h
@@ -2506,6 +2506,24 @@
  */
 
 /**
+ * @defgroup LLVMCCoreValueInstructionAlloca Allocas
+ *
+ * Functions in this group only apply to instructions that map to
+ * llvm::AllocaInst instances.
+ *
+ * @{
+ */
+
+/**
+ * Obtain the type that is being allocated by the alloca instruction.
+ */
+LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
+
+/**
+ * @}
+ */
+
+/**
  * @defgroup LLVMCCoreValueInstructionPHINode PHI Nodes
  *
  * Functions in this group only apply to instructions that map to
Index: llvm/trunk/lib/IR/Core.cpp
===================================================================
--- llvm/trunk/lib/IR/Core.cpp
+++ llvm/trunk/lib/IR/Core.cpp
@@ -2134,6 +2134,12 @@
   return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
 }
 
+/*--.. Operations on alloca instructions (only) ............................--*/
+
+LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca) {
+  return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
+}
+
 /*--.. Operations on phi nodes .............................................--*/
 
 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
Index: llvm/trunk/tools/llvm-c-test/echo.cpp
===================================================================
--- llvm/trunk/tools/llvm-c-test/echo.cpp
+++ llvm/trunk/tools/llvm-c-test/echo.cpp
@@ -306,7 +306,8 @@
         break;
       }
       case LLVMAlloca: {
-        LLVMTypeRef Ty = LLVMGetElementType(LLVMTypeOf(Src));
+        LLVMContextRef Ctx = LLVMGetModuleContext(get_module(Builder));
+        LLVMTypeRef Ty = clone_type(LLVMGetAllocatedType(Src), Ctx);
         Dst = LLVMBuildAlloca(Builder, Ty, Name);
         break;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16942.47373.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160209/74d1e039/attachment.bin>


More information about the llvm-commits mailing list