[LLVMdev] convert a char * to a value

Eli Friedman eli.friedman at gmail.com
Fri May 20 15:55:46 PDT 2011


On Fri, May 20, 2011 at 3:46 PM, Nabila ABDESSAIED
<nabila.abdessaied at gmail.com> wrote:
> Hi all,
> Please i need help, I have a method that takes 2 arguments with type char *:
> void branchPredict(char *b1, char *b2){
> ---
> --
> }
> i'm supposed to add this method, in an IR basic bloc:
> to add it into a basic bloc i do:
> //i: is the basic bloc
> std::vector<Value*> void_43_params;
> Constant* tbname = ConstantArray::get(M.getContext(),i->getNameStr() ,
> true);
> Constant* pbname = ConstantArray::get(M.getContext(),
>  i->getPrevNode()->getNameStr(), true);
> void_43_params.push_back(tbname);
> void_43_params.push_back(pbname);
> CallInst* void_43 = CallInst::Create(func_branchPredict,
> void_43_params.begin(), void_43_params.end(), "", i->getTerminator());
> when i execute the pass (opt -load ....)  i get an error:
>
> Call parameter type does not match function signature!
> [3 x i8] c"bb\00"
>  i8*  call void @branchPredict([3 x i8] c"bb\00", [4 x i8] c"bb1\00")
> Call parameter type does not match function signature!
> [4 x i8] c"bb5\00"
>  i8*  call void @branchPredict([4 x i8] c"bb5\00", [18 x i8]
> c"bb3.bb3_crit_edge\00")
> Broken module found, compilation aborted!
> 0  libLLVM-2.8.so.1 0x01421628
> Stack dump:
> 0. Program arguments: opt -load
> /home/inspiron/PhdWork/llvm-2.8/Release/lib/Example.so -Example6
> 1. Running pass 'Function Pass Manager' on module '<stdin>'.
> 2. Running pass 'Module Verifier' on function '@main'
> Aborted

You can't pass an array into a call expecting a pointer; try looking
at the output of http://llvm.org/demo/ for "void foo(char*); void
bar(void) { foo("asdf"); }".

-Eli




More information about the llvm-dev mailing list