<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.3821.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Times New Roman">Hi,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">I got a problem when I am trying to insert a
call function with pointer arguments.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">The function C proto-type is the
following,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">void stat_func(char *);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">>ConstantArray *Cstr =
dyn_cast<ConstantArray>(gI->getInitializer());</FONT></DIV>
<DIV><FONT face="Times New Roman" size=2>......</FONT></DIV>
<DIV><FONT face="Times New Roman">>Function *exFunc =
M->getOrInsertFunction("stat_func", Type::VoidTy,
PointerType::get(Type::SByteTy),0);</FONT></DIV>
<DIV><FONT face="Times New Roman">>std::vector<Value*>
Args(1);</FONT></DIV>
<DIV><FONT face="Times New Roman">>Args[0] =
constantArray::get(Cstr->getAsString()); </FONT></DIV>
<DIV><FONT face="Times New Roman">>CallInst *call = new CallInst(exFunc,
Args,"",InsertPos);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">If the code look like the above, it could
compile successfully. But once I run this pass, finally, I got errors as the
following.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">" Call parameter type does not match function
signature!"</FONT></DIV>
<DIV><FONT face="Times New Roman">[21 x sbyte] c"This a
example\00\00\00\00\00\00"</FONT></DIV>
<DIV><FONT face="Times New Roman"> sbyte* call void %stat_func( [21 x
sbyte] c "this a example\00\00\00\00"</FONT></DIV>
<DIV><FONT face="Times New Roman">...........</FONT></DIV>
<DIV><FONT face="Times New Roman">Broken module found, comilation
aborted!</FONT></DIV>
<DIV><FONT face="Times New Roman">........</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">The information comes from verifier.cpp which
mean the type of parameter of the function differ with the type of parameter the
code passed. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">I knew that the constantarry differ from sbyte
pointer ( sbyte*), but I tried to change the code to</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">
<DIV><FONT face="Times New Roman">>Function *exFunc =
M->getOrInsertFunction("stat_func", Type::VoidTy,
Cstr->getType(),0);</FONT></DIV>
<DIV>or</DIV>
<DIV>
<DIV><FONT face="Times New Roman">>Function *exFunc =
M->getOrInsertFunction("stat_func", Type::VoidTy, Type::ArrayTyID,0);
</FONT></DIV>
<DIV> </DIV>
<DIV>and once I run the pass, it is worse than the above. the error information
is </DIV>
<DIV> </DIV>
<DIV>" llvm::FunctionType::FunctionType(const llvm::Type*, const
std::vector<const llvm::Type*, std::allocator<const
llvm::Type::>>&,bool): Assertion ..............Function arguments must
be value types!"</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Finally, I tried to change the code of arguments like this</DIV>
<DIV> </DIV>
<DIV>
<DIV><FONT face="Times New Roman">>Function *exFunc =
M->getOrInsertFunction("stat_func", Type::VoidTy,
PointerType::get(Type::SByteTy),0);</FONT></DIV>
<DIV><FONT face="Times New Roman">>std::vector<Value*>
Args(1);</FONT></DIV>
<DIV><FONT face="Times New Roman">>Args[0] =
constantExpr::getGetElementPtr(constantArray::get(Cstr->getAsString()),
0);</FONT></DIV>
<DIV> </DIV>
<DIV>But I failed to pass the compilation. How could I fix this
problem?</DIV>
<DIV> </DIV>
<DIV>Thanks so much.</DIV>
<DIV>Qiuyu</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"> </FONT></DIV></BODY></HTML>