<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Dear all,</p>
<p>I am trying to build a pass which compares the output of all
function calls with a predefined value. I encountered two issues.</p>
<p>For example, the following IR</p>
<p>.....<br>
%before = alloca i32, i32 55<br>
%fooRet = call i32 @foo(i32 10)<br>
.....<br>
</p>
<p>should be transformed to the following IR after the pass<br>
</p>
<p>....<br>
%before = alloca i32, i32 55<br>
%fooRet = call i32 @foo(i32 10)<br>
%check = icmp eq i32 %call, i32 %before<br>
br i1 %check label %3, label %4<br>
...</p>
<p>1) I am not able to add icmp instruction using IRbuilder after
the function call instruction (I was able to add icmp instruction
using IRbuilder after other instructions, e.g. mul instruction): I
wrote a pass(snippet below) to do the above instrumentation which
also adds other new instructions, running the pass with opt does
not throw any error when there is a CreateIcmpEQ with two constant
operands, but only the icmp instruction after the function call is
not present in the instrumented IR. <br>
</p>
2) How to pass the output of a function call to CreateIcmpEQ() as a
argument? I understand that fooRet is the return value of my call
instruction. When I use check = builder.CreateICmpEQ(call, newConst,
"check"), I get a Type mismatch assert. <i>[ICmpInst::AssertOK():
Assertion 'getOperand(0)->getType() ==
getOperand(1)->getType() && "Both operands to Icmp
instruction are not of the same type!"]</i>. I guess if I can make
the types match, I will be able to pass the return value as
argument. How can I achieve that? <br>
<p>A snippet of the pass:<br>
if(CallInst *call = dyn_cast<CallInst>(&I))<br>
{<br>
call->setName("fooRet");<br>
IRBuilder<> builder(call);<br>
Value* newConst = ConstantInt::get(Int32Ty,55);<br>
Value* before = builder.CreateAlloca(Int32Ty,
newConst,"before");<br>
builder.SetInsertPoint(&bb, ++builder.GetInsertPoint());<br>
<b>Value* check = builder.CreateICmpEQ(call, newConst,
"check");</b><br>
auto * branch = builder.CreateCondBr(check, true, false);<br>
</p>
<p>}</p>
<p>Any help is appreciated. Thank you. <br>
</p>
<p>Regards,<br>
Archanaa<br>
</p>
</body>
</html>