[LLVMdev] Question about insert call func with pionter parameter

Zhang Qiuyu qiuyu at ucla.edu
Wed Dec 8 23:27:30 PST 2004


Hi,

I got a problem when I am trying to insert a call function with pointer arguments.

The function C proto-type is the following,

void stat_func(char *);

>ConstantArray *Cstr = dyn_cast<ConstantArray>(gI->getInitializer());
......
>Function *exFunc = M->getOrInsertFunction("stat_func", Type::VoidTy, PointerType::get(Type::SByteTy),0);
>std::vector<Value*> Args(1);
>Args[0] = constantArray::get(Cstr->getAsString()); 
>CallInst *call = new CallInst(exFunc, Args,"",InsertPos);

If the code look like the above, it could compile successfully. But once I run this pass, finally, I got errors as the following.

" Call parameter type does not match function signature!"
[21 x sbyte] c"This a example\00\00\00\00\00\00"
 sbyte* call void %stat_func( [21 x sbyte] c "this a example\00\00\00\00"
...........
Broken module found, comilation aborted!
........

The information comes from verifier.cpp which mean the type of parameter of the function differ with the type of parameter the code passed. 

I knew that the constantarry differ from sbyte pointer ( sbyte*), but I tried to change the code to

>Function *exFunc = M->getOrInsertFunction("stat_func", Type::VoidTy, Cstr->getType(),0);
or
>Function *exFunc = M->getOrInsertFunction("stat_func", Type::VoidTy, Type::ArrayTyID,0); 

and once I run the pass, it is worse than the above. the error information is 

" 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!"


Finally, I tried to change the code of arguments like this

>Function *exFunc = M->getOrInsertFunction("stat_func", Type::VoidTy, PointerType::get(Type::SByteTy),0);
>std::vector<Value*> Args(1);
>Args[0] = constantExpr::getGetElementPtr(constantArray::get(Cstr->getAsString()), 0);

But I failed to pass the compilation.  How could I fix this problem?

Thanks so much.
Qiuyu









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


More information about the llvm-dev mailing list