[LLVMdev] Casting and intrinsic function calls

Óscar Fuentes ofv at wanadoo.es
Wed Aug 28 15:42:58 PDT 2013


Jordan Cheney <jordan.cheney at gmail.com> writes:

> I am attempting to use llvm casting and intrinsic functions to do
> basic operations on Value pointers. I have read the online
> documentation and relevant portions of the source code and wrote the
> following code to do a Float to Double cast and then a log operation-
>
> Value *castFP(Value *i, Type *ty) const { return b->CreateFPCast(i, ty, n); } \\b is an IRBuilder and TheModule is an llvm::Module
>
> Value *intrinsic(Value *i, Intrinsic::ID id) const { vector<Type*>
> args; args.push_back(i->getType()); Function *intrinsic =
> Intrinsic::getDeclaration(TheModule, id, args); return
> b->CreateCall(intrinsic, i, n); }
> Value *log(Value *i) const { i = castFP(i, Type::getDoubleTy(getGlobalContext())); return intrinsic(i, Intrinsic::log); }
>
> In this example the initial type of i on the log function call is a Float (tested and confirmed) but when I run the code I get-
>
> Assertion failed: (getOperand(0)->getType() ==
> cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr
> must be a pointer to Val type!"), function AssertOK, file
> ../llvm/lib/IR/Instructions.cpp, line 1086.
> Illegal instruction: 4
>
> The error occurs in the CreateCall portion of the intrinsic function.
> Does anyone know why or of a better way to go about this seemingly
> simple task? This is my first time using llvm so apologies is
> something is very wrong. Any help would be greatly appreciated!

Assuming that you are using LLVM from SVN, that assert is in
StoreInst::AssertOK and I see no StoreInst in your code sample.

Run your code under a debugger and take a backtrace on the assert. My
guess is that the problem is elsewhere.




More information about the llvm-dev mailing list