Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -2506,6 +2506,24 @@ */ /** + * @defgroup LLVMCCoreValueInstructionAlloca Allocas + * + * Functions in this group only apply to instructions that map to + * llvm::Alloca 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: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -2134,6 +2134,12 @@ return wrap(unwrap(Switch)->getDefaultDest()); } +/*--.. Operations on alloca instructions (only) ............................--*/ + +LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca) { + return wrap(unwrap(Alloca)->getAllocatedType()); +} + /*--.. Operations on phi nodes .............................................--*/ void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, Index: tools/llvm-c-test/echo.cpp =================================================================== --- tools/llvm-c-test/echo.cpp +++ 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; }