[LLVMdev] create two Twine object
Eugene Toder
eltoder at gmail.com
Sun Apr 18 04:36:11 PDT 2010
According to documentation Twines should be used only for temporary
values and not stored, so allocating the in heap sounds wrong.
I think all you need here is
static int varNum;
++varNum;
Instruction *sstatusInst = new AllocaInst(StatusTy, Twine("status") +
Twine(varNum), entry_inst);
Instruction *sreqInst = new AllocaInst(ReqTy, Twine("request") +
Twine(varNum), entry_inst);
btw, your getVarNum() leaks.
Eugene
On Sun, Apr 18, 2010 at 5:55 AM, Yuanfang Chen <tabloid.adroit at gmail.com> wrote:
> I need to generate variables like
> status1, status2, status3, ......
> request1, request2, request3, ......
> this is my code, other unrelated detail are eliminated.
> static int varNum;
> static const char *getVarNum() {
> ++varNum;
> std::stringstream ss;
> ss << varNum;
> std::string *varname = new std::string(ss.str());
> return varname->c_str();
> }
> const char *VarNum = getVarNum();
> Twine *x1 = new Twine(StringRef("status"), VarNum); // 1
> Twine *x2 = new Twine(StringRef("request"), VarNum); // 2
> Instruction *sstatusInst = new AllocaInst(StatusTy, *x1, entry_inst); //
> 3
> Instruction *sreqInst = new AllocaInst(ReqTy, *x2, entry_inst); //
> 4
> with only 1&3, my code works well, I can have status1, status2, status3,
> ......
> with 1&2&3&4 exists at the same time, it compiles without problem, but
> segmentation fault happens.
> Instruction *sreqInst = new AllocaInst(ReqTy, "request", entry_inst); //
> 5
> with 1&2&3&5, everything work, but that's not what I want.
> I really can't figure out what is broken. I create everything new on the
> heap.
> Each alloca inst with its own Twine object on the heap. Could anyone help me
> out? Thanks a lot.
> yuanfang
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
More information about the llvm-dev
mailing list