[LLVMdev] GetElementPtrConstantExpr

Alessio Giovanni Baroni alessiogiovanni.baroni at gmail.com
Wed Dec 19 01:25:40 PST 2012


Ok, now it's arising another problem. IR code that I obtain is the
following:

i8* bitcast ([5 x i8] c"hello\00" to i8*)

generated from instructions:

ConstantExpr::getBitCast (ConstantDataArray::getString (getGlobalContext
(), "hello"), PointerType::get (Type::getInt8Ty (getGlobalContext ()), 0))

but the LLC tool says: invalid cast opcode for cast from '[5 x i8]' to
'i8*'.

Any help?


2012/12/18 Óscar Fuentes <ofv at wanadoo.es>

> Alessio Giovanni Baroni <alessiogiovanni.baroni at gmail.com> writes:
>
> > Because I need to convert an [4 x i8] type to i8* in the instantiation
> of a
> > GlobalVariable.
> > I have the follow declaration: %xxx = type { i8* } and I must emit the
> > following variable:
> > @yyy = linkonce_odr constant %xxx { [4 x i8] c"hello\00" }, but it's
> wrong.
> >
> > How do I do?
>
> You can use the ConstantExpr::getBitCast static member function:
>
>
> http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html#aba93ec4079f8d709a1d5b4745310782e
>
> This is a common idiom on LLVM: a base class has static methods for
> creating instances of derived classes.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121219/a998104a/attachment.html>


More information about the llvm-dev mailing list