[llvm-dev] Problems with GEP and CallInst

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Sun Apr 17 07:47:14 PDT 2016


On 17 April 2016 at 05:52, Lorenzo Laneve via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>     return builder->CreateInBoundsGEP(arty, strcst,
> llvm::ConstantInt::get(llvm::Type::getInt8Ty(container->getContext()), 0));

@strcst has type "[N x i8]*" so this "getelemntptr @strcst, i8 0" has
type "[N x i8]*" too (the first index is sort of special in GEPs. What
you want is "getelemntptr @strcst, i32 0, i32 0" which has type i8*.
Something like "builder->CreateInBoundsGEP2_32(arty, strcst, 0, 0)" is
probably the simplest way to get it.

If you haven't seen it already,
http://llvm.org/docs/GetElementPtr.html is a good introduction to GEP.
The other usual advice is to check what Clang outputs for something
equivalent in C or C++. It's also often easier to fiddle around with
tiny .ll test-cases than implement everything in C++ from the start.

Cheers.

Tim.


More information about the llvm-dev mailing list