[LLVMdev] convert a char * to a value

John Criswell criswell at illinois.edu
Fri May 20 15:54:39 PDT 2011


On 5/20/11 5:46 PM, Nabila ABDESSAIED 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:

The problem is that you are passing arrays to the function instead of 
passing pointers to arrays.  Instead of making tbname and pbname 
arguments to the function, you need to create GlobalVariable's that 
have, as their initializer, the Constant's tbname and pbname.

You may also have to take the GlobalVariables and insert a cast 
instruction (bitcast) to cast them from pointers to arrays to pointers 
of i8.  However, that is easy to do.

See line 138 of lib/DebugInstrumentation/DebugInstrumentation.cpp in the 
SAFECode source tree (directions for getting it from SVN are at 
http://safecode.cs.illinois.edu under the Download link).  I think it is 
similar to what you want to do.

-- John T.

>
> //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
>
> Any help
> thanks
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110520/f12775d4/attachment.html>


More information about the llvm-dev mailing list