[cfe-dev] Dataflow analysis with Libtooling and LiveVariables

Saheel Godhane srgodhane at ucdavis.edu
Thu Dec 4 16:39:11 PST 2014


Hello everyone!

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 discussion
<http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-November/039938.html> 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:

1. Implementation question

I have been trying to use the Libtooling clang interface (based on this
<http://clang.llvm.org/docs/RAVFrontendAction.html> 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?)

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.

Here is my code for VisitFunctionDecl. Pastebin version here
<http://pastebin.com/bvgP3iy4>. Full cpp file for my clang tool here
<http://pastebin.com/BPfY1Q5e>.

virtual bool VisitFunctionDecl(FunctionDecl *func) {
    errs() << "Inside " << ++numFunctions << " " <<
func->getNameInfo().getName().getAsString() << "\n";

    clang::AnalysisDeclContextManager *ADCM = new
clang::AnalysisDeclContextManager(false, true, true, true, true, true);
    clang::AnalysisDeclContext *func_ADC = ADCM->getContext(func);
    clang::LiveVariables *func_LV =
clang::LiveVariables::computeLiveness(*func_ADC, false);
    clang::LiveVariables::Observer *obs = new
clang::LiveVariables::Observer();

    func_LV->runOnAllBlocks(*obs);

func_LV->dumpBlockLiveness((func_ADC->getASTContext()).getSourceManager());

    return true;
}

Surely I am missing something here but I am not able to figure out. Perhaps
my instantiation of AnalysisDeclContextManager is incorrect?
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().

Any help on how to get this working, or whether I should just switch over
to writing a Checker, will be greatly appreciated! :)

Sincerely,
Saheel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141204/a55328b5/attachment.html>


More information about the cfe-dev mailing list