thank you guys. I see what the problem is now.<div><br></div><div>yuanfang<br><br><div class="gmail_quote">On Sun, Apr 18, 2010 at 12:16 PM, Daniel Dunbar <span dir="ltr"><<a href="mailto:daniel@zuster.org">daniel@zuster.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Sun, Apr 18, 2010 at 4:36 AM, Eugene Toder <<a href="mailto:eltoder@gmail.com">eltoder@gmail.com</a>> wrote:<br>
> According to documentation Twines should be used only for temporary<br>
> values and not stored, so allocating the in heap sounds wrong.<br>
<br>
</div>Yes, in general you should never be naming Twine directly, except in<br>
the case where you need to make a Twine for an integer. All other uses<br>
should be considered poor style, as they are dangerously subtle.<br>
<font color="#888888"><br>
- Daniel<br>
</font><div><div></div><div class="h5"><br>
> I think all you need here is<br>
><br>
> static int varNum;<br>
><br>
> ++varNum;<br>
> Instruction *sstatusInst = new AllocaInst(StatusTy, Twine("status") +<br>
> Twine(varNum), entry_inst);<br>
> Instruction *sreqInst = new AllocaInst(ReqTy, Twine("request") +<br>
> Twine(varNum), entry_inst);<br>
><br>
><br>
> btw, your getVarNum() leaks.<br>
><br>
> Eugene<br>
><br>
> On Sun, Apr 18, 2010 at 5:55 AM, Yuanfang Chen <<a href="mailto:tabloid.adroit@gmail.com">tabloid.adroit@gmail.com</a>> wrote:<br>
>> I need to generate variables like<br>
>> status1, status2, status3, ......<br>
>> request1, request2, request3, ......<br>
>> this is my code, other unrelated detail are eliminated.<br>
>> static int varNum;<br>
>> static const char *getVarNum() {<br>
>> ++varNum;<br>
>> std::stringstream ss;<br>
>> ss << varNum;<br>
>> std::string *varname = new std::string(ss.str());<br>
>> return varname->c_str();<br>
>> }<br>
>> const char *VarNum = getVarNum();<br>
>> Twine *x1 = new Twine(StringRef("status"), VarNum); // 1<br>
>> Twine *x2 = new Twine(StringRef("request"), VarNum); // 2<br>
>> Instruction *sstatusInst = new AllocaInst(StatusTy, *x1, entry_inst); //<br>
>> 3<br>
>> Instruction *sreqInst = new AllocaInst(ReqTy, *x2, entry_inst); //<br>
>> 4<br>
>> with only 1&3, my code works well, I can have status1, status2, status3,<br>
>> ......<br>
>> with 1&2&3&4 exists at the same time, it compiles without problem, but<br>
>> segmentation fault happens.<br>
>> Instruction *sreqInst = new AllocaInst(ReqTy, "request", entry_inst); //<br>
>> 5<br>
>> with 1&2&3&5, everything work, but that's not what I want.<br>
>> I really can't figure out what is broken. I create everything new on the<br>
>> heap.<br>
>> Each alloca inst with its own Twine object on the heap. Could anyone help me<br>
>> out? Thanks a lot.<br>
>> yuanfang<br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>><br>
>><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
</div></div></blockquote></div><br></div>