[LLVMdev] Illegal BitCast assertion failed
Cristianno Martins
cristiannomartins at gmail.com
Thu Oct 10 07:44:16 PDT 2013
Hi there,
I'm having a bit of a problem while trying to create BitCast instructions.
Well, first, I have some very generic functions written in C, for which I
would like to make calls on another C file I'm playing with using an LLVM
Pass. The simplified signature of two of these functions can be seen below:
void write(void* data, unsigned b); // write b bytes starting, at address
"data", to an internal queue
void* read(unsigned b); // read and return b bytes from an internal queue
Since I would like to be able to use variables of any type as arguments for
these two functions, I thought I could create a BitCastInst, in order to
cast a pointer from any type to void*, and then back, and insert it before
calling write, or after calling read. And so I did like the example below
// Let Func be an llvm::Function* that represents read, CArgs contain an
integer constant, and
// typeInFrontOfTheStream be an llvm::Type* that represents the type of the
variable
// available as the next read from the stream
llvm::CallInst *consume = llvm::CallInst::Create(Func, CArgs);
llvm::BitCastInst *cbi = new llvm::BitCastInst(consume,
typeInFrontOfTheStream->getPointerTo());
For the first example when running this pass, the typeInFrontOfTheStream is
an i1, which means the result of typeInFrontOfTheStream->getPointerTo() is
an i1*. Remember that consume is a function that returns void*, which is
seen in LLVMIR as i8*. And, for a first execution like that, I'm getting
Assertion failed: (castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"),
function BitCastInst, file /Developer/llvm/lib/IR/Instructions.cpp, line
2842.
Does anyone have any suggestion about what I'm doing wrong?
Thanks in advance,
--
Cristianno Martins
PhD Student of Computer Science
University of Campinas
cmartins at ic.unicamp.br
<cristiannomartins at hotmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131010/919992a4/attachment.html>
More information about the llvm-dev
mailing list