<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 4/4/2011 6:26 PM, George Baah wrote:
<blockquote
cite="mid:BANLkTinx5Z1T0z8rO=8GBcNjO2h7ssJ2Hw@mail.gmail.com"
type="cite"><span class="Apple-style-span" style="font-family:
arial,sans-serif; font-size: 13px; border-collapse: collapse;">
<div>
<div>Hi Everyone,</div>
<div> I am trying to construct the print statement :
printf("value:%d\n", value); </div>
<div>This is my llvm code. It is seg faulting at
builder.CreateGlobalStringPtr(str,"").</div>
</div>
</span></blockquote>
<br>
This might be easier to debug with a stack trace. Use a debugger to
see the call stack when the segfault occurs. Also try to isolate
which pointer value is bad.<br>
<br>
As a guess, did you give the builder object all the information it
needs to insert IR (e.g., which LLVM Module * it is modifying, which
BasicBlock or Instruction it is to use when inserting instructions,
etc)?<br>
<br>
-- John T.<br>
<br>
<blockquote
cite="mid:BANLkTinx5Z1T0z8rO=8GBcNjO2h7ssJ2Hw@mail.gmail.com"
type="cite"><span class="Apple-style-span" style="font-family:
arial,sans-serif; font-size: 13px; border-collapse: collapse;">
<div>
<div>Thanks.</div>
<div><br>
</div>
<div>George</div>
<div><br>
</div>
<div>vector<const Type *> params;</div>
<div>params.push_back(Type::getInt8PtrTy(M.getContext()));</div>
<div>FunctionType *fType =
FunctionType::get(Type::getInt32Ty(M.getContext()), params,
true);</div>
<div>Constant *temp = M.getOrInsertFunction("printf",fType);</div>
<div>if(!temp){</div>
<div> errs() << "printf function not in symbol
table\n";</div>
<div> exit(1);</div>
<div>}</div>
<div>Function *f = cast<Function>(temp);</div>
<div>f->setCallingConv(CallingConv::C);</div>
</div>
<div><br>
</div>
<div>const char *str = "value: %d\n";</div>
<div>Value *intparam = ...</div>
<div>
<div>Value *strPtr = builder.CreateGlobalStringPtr(str,"");</div>
</div>
<div>
<div>builder.CreateCall2(PrintF, strPtr, intparam,"tmp6");</div>
</div>
</span>
</blockquote>
<br>
</body>
</html>