<div dir="ltr"><div>Hi everyone, </div><div><br></div><div>I have just got started with clang development. My first project would extract the return value from each path. I can get the return value quite easily, but have some problem with path representation. For example, given the following very simple function, </div><div><br></div><div><div>1: int jump(int x){</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">2: </span>int result = x;</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">4: </span>if (x < 5) {</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>result = -1;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">6: </span>goto out;</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">9: </span>result = 0;</div><div><br></div><div>out:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">12: </span>return result;</div><div>}</div></div><div><br></div><div>I would like to return two paths and their corresponding return values. I use line numbers to represent each path.</div><div><br></div><div>Path Return value</div><div>---------- --------------------</div><div>L6, L12 -1</div><div>L12 0</div><div><br></div><div>The problem I am having now is that I am not able to get line numbers of goto statements, although my checker writes callback functions for goto statements. My code is as follows. I have tried to add callback functions for PreStmt on both GotoStmt and IndirectGotoStmt and also PostStmt on them, but never got line numbers for goto statements. I can get line numbers for return statements with the following code. </div><div><br></div><div>Does anybody have any idea about why this happens?</div><div><br></div><div>Thank you for your help.</div><div>Sheng</div><div><br></div><div><div>namespace {</div><div>class CheckReturnValue : public Checker< check::PreStmt<ReturnStmt>, </div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span> check::PreStmt<IndirectGotoStmt>,</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span> check::PostStmt<GotoStmt>> {</div><div><br></div><div>public:</div><div> void checkPreStmt(const ReturnStmt *DS, CheckerContext &C) const;</div><div> void checkPreStmt(const IndirectGotoStmt *DS, CheckerContext &C) const;</div><div> void checkPostStmt(const GotoStmt *DS, CheckerContext &C) const;</div><div>private:</div><div> static bool isNegative(CheckerContext &C, const Expr *E);</div><div>};</div><div>} // end anonymous namespace</div><div><br></div><div>void CheckReturnValue::checkPostStmt(const GotoStmt *DS, CheckerContext &C) const{</div><div><br></div><div> llvm :: outs() << "Goto statement\t";</div><div> DS -> getLocStart().print(llvm::outs(),C.getSourceManager()) ;</div><div><br></div><div>}</div><div><br></div><div>void CheckReturnValue::checkPreStmt(const IndirectGotoStmt *DS, CheckerContext &C) const {</div><div> llvm :: outs() << "Indirect goto statement\t";</div><div> DS -> getLocStart().print(llvm::outs(),C.getSourceManager()) ;</div><div><br></div><div>}</div><div><br></div><div>void CheckReturnValue::checkPreStmt(const ReturnStmt *DS, CheckerContext &C) const {</div><div> const Expr* retExp = DS -> getRetValue() ;</div><div> retExp -> printPretty(llvm::outs(), NULL, PrintingPolicy(LangOptions())) ;</div><div><br></div><div><div> llvm :: outs() << "\tLocation\t";</div><div> DS -> getLocStart().print(llvm::outs(),C.getSourceManager()) ;</div></div><div>}</div></div><div><br></div><div><br></div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div><div dir="ltr"><div><div dir="ltr"><div><div><div><div><div><span style="color:rgb(102,102,102)">Dr. Sheng Chen<br></span></div><span style="color:rgb(102,102,102)">Assistant Professor<br></span></div><span style="color:rgb(102,102,102)">The Center for Advanced Computer Studies<br></span></div><span style="color:rgb(102,102,102)">UL Lafayette<br></span></div></div><span style="color:rgb(102,102,102)"><a href="http://www.ucs.louisiana.edu/%7Esxc2311/" target="_blank">http://www.ucs.louisiana.edu/~sxc2311/</a></span></div></div></div></div></div></div></div></div>
</div>