common type at compile time?

I'm trying to create a ConstantArray(whose contents will be of types
Function*, GlobalVariable *) so I can immediately create a new
GlobalVariable(that will be in its own section). I'm doing this so I
have these address stored. In order to create this ConstantArray I
need a valid ArrayType, but I'm not sure what to use for the element
type.

I want this to be done at compile time, so I cant use a BitCastInst to
make them all generic pointers. What else can I do?

In other words
* I built up a vector id like to eventually store as a GlobalVariable
array: vector<Constant *> v_elements;
* Turned it into something for the ConstantArray::get can use:
ArrayRef<Constant *> a_elements(v_elements);
* And now I need to come up with the ArrayType arg for the
ConstantArray::get() method where I only know: ArrayType::get(???, 4);

Thanks

I'm trying to create a ConstantArray(whose contents will be of types
Function*, GlobalVariable *) so I can immediately create a new
GlobalVariable(that will be in its own section). I'm doing this so I
have these address stored. In order to create this ConstantArray I
need a valid ArrayType, but I'm not sure what to use for the element
type.

I want this to be done at compile time, so I cant use a BitCastInst to
make them all generic pointers. What else can I do?

You can use a ConstantExpr (constant expression) for Function and GlobalVariable objects. The ArrayType can be an array of pointers to 8-byte characters (basically a void pointer type).

-- John T.

I want this to be done at compile time, so I cant use a BitCastInst to
make them all generic pointers. What else can I do?

Use a bitcast ConstantExpr.

Ciao, Duncan.

I'm a bit confused. For the Type did you mean something like:
        ArrayType *type = ArrayType::get(Type::getInt8PtrTy(M.getContext()), 4);
This does not work, it gives me ""Wrong type in array element
initializer" at runtime.

Also it doesn't look like ConstantExpr inherits ConstantArray, so I'm
not sure how I could use this instead.

Thanks

I'm a bit confused. For the Type did you mean something like:
         ArrayType *type = ArrayType::get(Type::getInt8PtrTy(M.getContext()), 4);

I assume that creates an ArrayType of 4 elements whose elements are pointers to 8-bit values. If so, then this is what I meant.

This does not work, it gives me ""Wrong type in array element
initializer" at runtime.

Also it doesn't look like ConstantExpr inherits ConstantArray, so I'm
not sure how I could use this instead.

What I meant here is that each element (Function *, GlobalVariable *) that you want to put into the ConstantArray will need to be casted to an i8 * type. To do the casting, you will need to use a bitcast ConstantExpr instead of a BitCastInst since you can't use instructions.

-- John T.

Awesome, that seems to have fixed my Type problem nicely.

Although now I have a mastery "Uses remain when a value is destroyed!"
assert being tripped and I cant seem to find much about it. This code
is still be ran in my runOnModule() method, so everything should still
be fine.

Thanks again