[LLVMdev] size of const_ptr for array index

Alexander Poddey alexander.poddey at gmx.net
Mon Mar 16 12:44:46 PDT 2015

Hi all,

when e.g. accessing a global variable residing in a structure, the c++API 
code looks like:

std::vector<Constant*> const_ptr_183_indices;
Constant* const_ptr_183 = ConstantExpr::getGetElementPtr(gvar_struct_foo, 

the struct could be 

 struct stest {
    double age;
   double darray[3];

The indices for accessing 'age' would be 
0 (32bit)
0 (32bit).

For an element of the darray, one however needs 
0 (32bit) 
1 (32bit)
0-2 (64bit)

The same for indices of vectors.

The question:
Can I at runtime determine (how?) which size I have to use per case?
I made some tests but could not figure it out.

So for now (at my architecture) it seems hardcoding 32 bit as default, and 
64bit for indices (of arrays and vectors) works. But this is not portable.


More information about the llvm-dev mailing list