<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>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-</div><div><br></div><div><pre style="margin-top: 0px; margin-bottom: 0px; "><pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*castFP(<span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*i,<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Type</span><span style=" color:#c0c0c0;"> </span>*ty)<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span>{<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">b</span>->CreateFPCast(i,<span style=" color:#c0c0c0;"> </span>ty,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">n</span>);<span style=" color:#c0c0c0;"> </span>} <a href="smb://b">\\b</a> is an IRBuilder and TheModule is an llvm::Module</pre></pre></div><div><br></div><div><pre style="margin-top: 0px; margin-bottom: 0px; "><pre style="margin-top: 0px; margin-bottom: 0px; "><!--StartFragment--><span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*intrinsic(<span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*i,<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Intrinsic</span>::<span style=" color:#800080;">ID</span><span style=" color:#c0c0c0;"> </span>id)<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span>{<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">vector</span><<span style=" color:#800080;">Type</span>*><span style=" color:#c0c0c0;"> </span>args;<span style=" color:#c0c0c0;"> </span>args.push_back(i->getType());<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Function</span><span style=" color:#c0c0c0;"> </span>*intrinsic<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Intrinsic</span>::getDeclaration(TheModule,<span style=" color:#c0c0c0;"> </span>id,<span style=" color:#c0c0c0;"> </span>args);<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">b</span>->CreateCall(intrinsic,<span style=" color:#c0c0c0;"> </span>i,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">n</span>);<span style=" color:#c0c0c0;"> </span>}</pre><pre style="margin-top: 0px; margin-bottom: 0px; "><span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*log(<span style=" color:#800080;">Value</span><span style=" color:#c0c0c0;"> </span>*i)<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span>{<span style=" color:#c0c0c0;"> </span>i<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>castFP(i,<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Type</span>::getDoubleTy(getGlobalContext()));<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span><span style=" color:#c0c0c0;"> </span>intrinsic(i,<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">Intrinsic</span>::log);<span style=" color:#c0c0c0;"> </span>}<!--EndFragment--></pre><div><br></div></pre><pre style="margin-top: 0px; margin-bottom: 0px; "><!--EndFragment--></pre><div>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-</div><div><br></div><div><div>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.</div><div>Illegal instruction: 4</div></div><div><br></div><div>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!</div><div><br></div><div>Thanks,</div><div>Jordan</div>
<br></div></body></html>