c++ - LLVM: Creating a CallInst with a null pointer operand -
i'm trying use llvm c++ bindings write pass generates following ir
%1 = call i64 @time(i64* null) #3
@time
here c standard library time()
function.
here's code i've written
void pass::insert(basicblock *bb, type *timety, module *m) { type *timetype[1]; timetype[0] = timety; arrayref<type *> timetypearef(timetype, 1); value *args[1]; args[0] = constantint::get(timety, 0, false); arrayref<value *> argsref(args, 1); functiontype *signature = functiontype::get(timety, false); function *timefunc = function::create(signature, function::externallinkage, "time", m); irbuilder<> builder(&*(bb->getfirstinsertionpt())); allocainst *a1 = builder.createalloca(timety, nullptr, twine("a1")); callinst *c1 = builder.createcall(timefunc, args, twine("time")); }
this compiles, results in following error when run
incorrect number of arguments passed called function! %time = call i64 @time(i64 0)
as understand this, need pass int64 pointer deferences nullptr
, i'm unable figure out how that.
llvm provides constantpointernull
class want - returns null pointer of required type.
all needs changed line beginning args[0] = ...
args[0] = constantpointernull::get(pointertype::get(timety, 0));
.
Comments
Post a Comment