<div class="gmail_quote">On Fri Dec 05 2014 at 1:44:04 AM Saheel Godhane <<a href="mailto:srgodhane@ucdavis.edu">srgodhane@ucdavis.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello everyone!</div><div><br></div><div>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 <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-November/039938.html" target="_blank">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><br></div><div>1. Implementation question</div><div><br></div><div>I have been trying to use the Libtooling clang interface (based on <a href="http://clang.llvm.org/docs/RAVFrontendAction.html" target="_blank">this</a> 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><br></div><div>+Anna for the LiveVariables question.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>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><br></div><div>Here is my code for VisitFunctionDecl. Pastebin version <a href="http://pastebin.com/bvgP3iy4" target="_blank">here</a>. Full cpp file for my clang tool <a href="http://pastebin.com/BPfY1Q5e" target="_blank">here</a>.</div><div><br></div><div><div><font face="monospace">virtual bool VisitFunctionDecl(FunctionDecl *func) {</font></div><div><font face="monospace">    errs() << "Inside " << ++numFunctions << " " << func->getNameInfo().getName().getAsString() << "\n";</font></div><div><font face="monospace"><br></font></div><div><span style="font-family:monospace">    clang::AnalysisDeclContextManager *ADCM = new clang::AnalysisDeclContextManager(false, true, true, true, true, true);</span><br></div><div><font face="monospace">    clang::AnalysisDeclContext *func_ADC = ADCM->getContext(func);</font></div><div><font face="monospace">    clang::LiveVariables *func_LV = clang::LiveVariables::computeLiveness(*func_ADC, false);</font></div><div><font face="monospace">    clang::LiveVariables::Observer *obs = new clang::LiveVariables::Observer();</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">    func_LV->runOnAllBlocks(*obs);</font></div><div><font face="monospace">    func_LV->dumpBlockLiveness((func_ADC->getASTContext()).getSourceManager());</font></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">    return true;</span><br></div><div><font face="monospace">}</font></div></div><div><br></div><div>Surely I am missing something here but I am not able to figure out. Perhaps my instantiation of AnalysisDeclContextManager is incorrect?</div><div>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><br></div><div>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><br></div><div>That depends:</div><div>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><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Sincerely,</div><div>Saheel.</div><div><br></div></div>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div>