<div>I need to generate variables like </div><div><br><div>status1, status2, status3, ......</div><div>request1, request2, request3, ......</div><div><br></div><div>this is my code, other unrelated detail are eliminated.</div>
<div><br></div><div>static int varNum;</div><div><div>static const char *getVarNum() {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>++varNum;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::stringstream ss;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>ss << varNum;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>std::string *varname = new std::string(ss.str());</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return varname->c_str();</div>
<div>}</div></div><div><br></div><div>const char *VarNum = getVarNum();</div><div><div>Twine *x1 = new Twine(StringRef("status"), VarNum); // 1</div><div>Twine *x2 = new Twine(StringRef("request"), VarNum); // 2</div>
<div><br></div><div>Instruction *sstatusInst = new AllocaInst(StatusTy, *x1, entry_inst); // 3</div><div>Instruction *sreqInst = new AllocaInst(ReqTy, *x2, entry_inst); // 4</div></div><div><br></div></div>
<div>with only 1&3, my code works well, I can have status1, status2, status3, ......</div><div><br></div><div>with 1&2&3&4 exists at the same time, it compiles without problem, but</div><div>segmentation fault happens. </div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>Instruction *sreqInst = new AllocaInst(ReqTy, "request", entry_inst); // 5</div><div>with 1&2&3&5, everything work, but that's not what I want. </div>
<div><br></div><div>I really can't figure out what is broken. I create everything new on the heap. </div><div>Each alloca inst with its own Twine object on the heap. Could anyone help me</div><div>out? Thanks a lot.</div>
<div><br></div><div>yuanfang</div>