convert a char * to a value

Hi all,

Please i need help, I have a method that takes 2 arguments with type char *:
void branchPredict(char *b1, char *b2){

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 under the Download link). I think it is similar to what you want to do. – John T.

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

2011/5/20 John Criswell <criswell@illinois.edu>

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.

i couldn’t use that sollution because i repeat the process in each basic bloc in a function.
the globalvariable could be initiallized with constants that have the same array type but in my case the constants i get in each basic bloc haven’t the same array type

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.

ok , i will use this.

i have seen it and here is what i did

std::string fbname =i->getNameStr();
std::string tbname = i->getPrevNode()->getNameStr();
Constant * tname = ConstantArray::get(Context, tbname);
Constant * fname = ConstantArray::get(Context, fbname);
Value * TBloc, FBloc;
TBloc = new GlobalVariable(M,
tname->getType(),
true,
GlobalValue::InternalLinkage,
tname,
“tBloc”);
FBloc = new GlobalVariable(M,
fname->getType(),
true,
GlobalValue::InternalLinkage,
fname,
“fBloc”);
std::vector<Value
> void_43_params;
void_43_params.push_back(TBloc);
void_43_params.push_back(FBloc);
CallInst* void_43 = CallInst::Create(func_branchPredict, void_43_params.begin(), void_43_params.end(), “”, i->getTerminator());

but i have error :

Call parameter type does not match function signature!
[3 x i8]* @tBloc
i8* call void @branchPredict([3 x i8]* @tBloc, [3 x i8]* @fBloc)
Call parameter type does not match function signature!
[4 x i8]* @tBloc3
i8* call void @branchPredict([4 x i8]* @tBloc3, [4 x i8]* @fBloc4)
Broken module found, compilation aborted!
0 libLLVM-2.8.so.1 0x014c7628
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 ‘’.
  2. Running pass ‘Module Verifier’ on function ‘@main
    Aborted