Stéphane Letz via llvm-dev
2015-Oct-01 10:01 UTC
[llvm-dev] How to generate IR code to dynamically compute object size ?
Hi, We are using the following kind code to compile the size of a dynamically allocated object, flowing the recommendation described here : http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt Our code was : Value* ptr_size = GetElementPtrInst::Create(ConstantPointerNull::get(dsp_type_ptr), genInt64(fModule, 1), "ptr_size", entry_func_llvm_create_dsp); CastInst* size_inst = new PtrToIntInst(ptr_size, fBuilder->getInt64Ty(), "size", entry_func_llvm_create_dsp); CallInst* call_inst1 = CallInst::Create(func_malloc, size_inst, "", entry_func_llvm_create_dsp); With LLVM 3.7 the prototype of GetElementPtrInst::Create has changed, so we tried : #if defined(LLVM_37) ConstantPointerNull* null_ptr = ConstantPointerNull::get(dsp_type_ptr); Value* ptr_size = GetElementPtrInst::Create(null_ptr->getType(), null_ptr, genInt64(fModule, 1), "ptr_size", entry_func_llvm_create_dsp); #else Value* ptr_size = GetElementPtrInst::Create(ConstantPointerNull::get(dsp_type_ptr), genInt64(fModule, 1), "ptr_size", entry_func_llvm_create_dsp); #endif CastInst* size_inst = new PtrToIntInst(ptr_size, fBuilder->getInt64Ty(), "size", entry_func_llvm_create_dsp); CallInst* call_inst1 = CallInst::Create(func_malloc, size_inst, "", entry_func_llvm_create_dsp); But we get the following error when running the code : Assertion failed: (PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()), function Create, file /opt/local/libexec/llvm-3.7/include/llvm/IR/Instructions.h, line 880. Is there a cleaner and more official way to generate code to compute the size of a dynamically allocated object with LLVM 3.7? Thanks. Stéphane Letz
Krzysztof Parzyszek via llvm-dev
2015-Oct-01 19:27 UTC
[llvm-dev] How to generate IR code to dynamically compute object size ?
On 10/1/2015 5:01 AM, Stéphane Letz via llvm-dev wrote:> > We are using the following kind code to compile the size of a dynamically allocated object, flowing the recommendation described here : > > http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt >Since you must know the type for the above to work, can't you use DataLayout::getTypeSizeInBits instead? -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation