<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 15, 2014, at 5:01 AM, Manuel Klimek <<a href="mailto:klimek@google.com" class="">klimek@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Fri Dec 05 2014 at 1:44:04 AM Saheel Godhane <<a href="mailto:srgodhane@ucdavis.edu" class="">srgodhane@ucdavis.edu</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class="">Hello everyone!</div><div class=""><br class=""></div><div class="">I am a PhD student and have been working with Clang with the aim to do an intra-procedural dataflow analysis. I am aware of a recent<span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-November/039938.html" target="_blank" class="">discussion</a> on this mailing list regarding the same but my questions are slightly more specific. Pardon me if this is the wrong forum to ask them, but anyway, here they are:</div><div class=""><br class=""></div><div class="">1. Implementation question</div><div class=""><br class=""></div><div class="">I have been trying to use the Libtooling clang interface (based on<span class="Apple-converted-space"> </span><a href="http://clang.llvm.org/docs/RAVFrontendAction.html" target="_blank" class="">this</a><span class="Apple-converted-space"> </span>tutorial) and the existing LiveVariables analysis. My goal is to answer the question: given a VarDecl, is it live at a particular SourceLocation? (is this even possible with LiveVariables, which somehow looks like block-level liveness analysis?)</div></div></blockquote><div class=""><br class=""></div><div class="">+Anna for the LiveVariables question.<br class=""></div></div></div></blockquote><div><br class=""></div>LiveVariables operates on the front-end CFG, which contains the references to the AST nodes in its basic blocks. You should be getting precise liveness information for every statement. </div><div><br class=""></div><div>LiveVariables is currently used by the DeadStoresChecker, so that would be a good point of reference. DeadStoresChecker talks to the LiveVariables through the Observer.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class="">So far, although I have been able to get some code on a LiveVariables analysis working, it is not displaying the expected result. Specifically, I have overridden VisitFunctionDecl() so as to calculate a LiveVariables analysis on every function. When I dump the live values, it shows correctly all the blocks in my function but it doesn't show any of the live variables. I tried using "clang -cc1 -analyze -analyzer-checker=debug.DumpLiveVars test.c" which works as expected, displaying all the variables live in different blocks.</div><div class=""><br class=""></div><div class="">Here is my code for VisitFunctionDecl. Pastebin version <a href="http://pastebin.com/bvgP3iy4" target="_blank" class="">here</a>. Full cpp file for my clang tool<span class="Apple-converted-space"> </span><a href="http://pastebin.com/BPfY1Q5e" target="_blank" class="">here</a>.</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace" class="">virtual bool VisitFunctionDecl(FunctionDecl *func) {</font></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>errs() << "Inside " << ++numFunctions << " " << func->getNameInfo().getName().getAsString() << "\n";</font></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><span style="font-family: monospace;" class=""> <span class="Apple-converted-space"> </span>clang::AnalysisDeclContextManager *ADCM = new clang::AnalysisDeclContextManager(false, true, true, true, true, true);</span><br class=""></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>clang::AnalysisDeclContext *func_ADC = ADCM->getContext(func);</font></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>clang::LiveVariables *func_LV = clang::LiveVariables::computeLiveness(*func_ADC, false);</font></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>clang::LiveVariables::Observer *obs = new clang::LiveVariables::Observer();</font></div></div></div></blockquote></div></div></blockquote><div><br class=""></div><div>In order to use the observer, you need to implement your own observer here which will get notified on observeStmt. </div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class=""><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>func_LV->runOnAllBlocks(*obs);</font></div><div class=""><font face="monospace" class=""> <span class="Apple-converted-space"> </span>func_LV->dumpBlockLiveness((func_ADC->getASTContext()).getSourceManager());</font></div></div></div></blockquote></div></div></blockquote><div><br class=""></div>I am not sure why liveness information is not dumped... I would try to debug this as well as the analyzer's version to see what's missing.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class=""><div class=""><span style="font-family: monospace;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace;" class=""> <span class="Apple-converted-space"> </span>return true;</span><br class=""></div><div class=""><font face="monospace" class="">}</font></div></div><div class=""><br class=""></div><div class="">Surely I am missing something here but I am not able to figure out. Perhaps my instantiation of AnalysisDeclContextManager is incorrect?</div><div class="">I started out with overriding VisitVarDecl() in the RecursiveASTVisitor but then realized that to call LiveVariables::computeLiveness() I need an AnalysisDeclContext object which works only with block-level declarations (am I correct?), so switched to VisitFunctionDecl().</div><div class=""><br class=""></div><div class="">Any help on how to get this working, or whether I should just switch over to writing a Checker, will be greatly appreciated! :)</div></div></blockquote><div class=""><br class=""></div><div class="">That depends:</div><div class="">If what you want in the end is a static analysis check, then yes, write a checker. If you want to drive refactorings from the results, then the right approach is libTooling; but as you discovered libTooling is not integrated well with the CFG yet (that needs some work)</div></div></div></blockquote><div><br class=""></div><div>+1</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""></div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Sincerely,</div><div class="">Saheel.</div><div class=""><br class=""></div></div>______________________________<u class=""></u>_________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank" class="">cfe-dev@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank" class="">http://lists.cs.uiuc.edu/<u class=""></u>mailman/listinfo/cfe-dev</a></blockquote></div></div></blockquote></div><br class=""></body></html>