[cfe-dev] Missing edges in analysis call graph

Anna Zaks ganna at apple.com
Fri Nov 21 15:48:06 PST 2014

> On Nov 21, 2014, at 3:35 PM, Daniel DeFreez <dcdefreez at ucdavis.edu> wrote:
>>  I believe with your patch, the node will get added, but the definition used will not have the body attached to it, so the analyzer will not process the body. 
>> Hmm, doesn't the analyzer itself use getBody() to access the body, thereby walking the list of redeclarations? It seems like it is still processing the body of the function, but maybe I don't know what to look for.
> This is a good point. We might not be gaining anything by replacing the decl with the one that has a body since getBody is guaranteed to search the redeclarations regardless.
> How about just removing both calls to isThisDeclarationADefinition() (from includeInGraph) and replacing the call to getBody with hasBody (to avoid the unnecessary AST de-serialization of the body)? That should work and would simplify the function greatly. What do you think?
> I think replacing getBody() with hasBody() is a good idea regardless of the approach taken to fix the missing edges. And avoiding node replacement would make it cleaner.
> I am not sure why some of the checks in your first patch were necessary (like this one).
> +    // Skip definitions with previous declarations
> +    if (FD->getPreviousDecl())
> +      return false;
> +
> The reason I put that in was to avoid inserting redundant nodes. Just removing isThisDeclarationADefinition() yields:

Oh, I see! getOrInsertNode() would not insert an existing declaration, but it does not check for re-declarations.

But would your approach work for this set?
void a();
void a() { }
void b() { a(); } // Here, a call to "a()" might not be added since "a()" has a previous declaration.

Sounds like we would want to store canonical declarations, which brings us back to the suggestion of using "hasBody(Definition)" and only store the definitions that have bodies. Changing the signature of "includeInGraph" so that it mutates the Decl is fine; though, you might want to rename it as well.


> void a();
> void b() { a(); }
> void a() { }
>  --- Call graph Dump --- 
>   Function: < root > calls: a b a 
>   Function: a calls: 
>   Function: b calls: a 
>   Function: a calls: 
> Since call expressions seem to reference the first declaration, I followed suit. I still need to verify this is always the case.
> The other check for templates is unnecessary.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141121/b50641d4/attachment.html>

More information about the cfe-dev mailing list