OSDN Git Service

Add C binding for AllocaInst::getAllocatedType
authorAmaury Sechet <deadalnix@gmail.com>
Tue, 9 Feb 2016 22:50:53 +0000 (22:50 +0000)
committerAmaury Sechet <deadalnix@gmail.com>
Tue, 9 Feb 2016 22:50:53 +0000 (22:50 +0000)
Summary:
Comes with an awesome test.

Depends on D16912

Reviewers: bogner, chandlerc, echristo, dblaikie, joker.eph, Wallbraker

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D16942

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260313 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8e644c3..27eb7ae 100644 (file)
@@ -2506,6 +2506,24 @@ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef SwitchInstr);
  */
 
 /**
+ * @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 7488abb..cf23a28 100644 (file)
@@ -2134,6 +2134,12 @@ LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
   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 7850830..9788386 100644 (file)
@@ -306,7 +306,8 @@ struct FunCloner {
         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;
       }