[LLVMdev] How to cast an integer array to an integer pointer? (user question)

Renato Golin rengolin at systemcall.org
Thu May 6 01:32:57 PDT 2010


On 6 May 2010 00:05, Yuri <yuri at tsoft.com> wrote:
>  GetElementPtrInst *gepi = GetElementPtrInst::CreateInBounds(
>    GGV,
>    ConstantInt::get(Type::getInt32Ty(Context), 0),
>    "zzz",
>    BB
>    );

Try using the IRBuilder:

IRBuilder<> irb(BB);
Value* gepi = irb.CreateInBoundsGEP(GGV,
ConstantInt::get(Type::getInt32Ty(Context), 0), "zzz");

Keeping your pointers as Value* makes it easier to deal with using (or
returning) them later.


>  // func call
>  CallInst::Create(PutsF, (Value* const*)&gepi, (Value*
> const*)(&gepi)+1, "", BB);

Since the return type is void, you can't use Twine, since you only
have one argument, IRBuilder makes it easier for you just to call:

irb.CreateCall(PutsF, gepi);

You can still pass args via pointer/offset, vector or use the helpers
CreateCall[2-4]().

See include/llvm/Support/IRBuilder.h for more info.

cheers,
--renato

http://systemcall.org/

Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm




More information about the llvm-dev mailing list