[LLVMdev] Size of structs & arrays

Fraser Cormack
Wed, 22 Feb 2012 23:54:49 -0000

I'm trying this:

llvm::Constant* one
llvm::Constant::getNullValue(llvm::IntegerType::get(mod->getContext(), 64));
llvm::ConstantInt* two = llvm::ConstantInt::get(mod->getContext(),
llvm::APInt(32, llvm::StringRef("1"), 10));

std::vector<llvm::Value*> indices;
indices.push_back(one);  indices.push_back(two);

llvm::Value* size = builder->CreateGEP(struct_ptr, indices);
llvm::Value* size_int = builder->CreatePtrToInt(size,
llvm::IntegerType::get(mod->getContext(), 64))

And I'm getting the assertion error "Invalid GetElementPtrInst indices
for
type!"'. 'struct_ptr' is a pointer to the struct I'm trying
to size. I've
also tried using getNullValue on the struct's own type.

Sorry to ask so directly, but I'd quite like to get this sorted.

--
View this message in context: