<div dir="ltr"><div>Hi,<br></div><div>Could you please tell me what the idea behind the <b>canonical</b> form in general is? <br></div><div>Basically when I profile the statement with the canonical boolean set, It is internally calling <br>
<br></div><div>if(Canonical) <br></div><div>   T = Context.getCanonicalType(T)<br><br></div><div>and while profilling,<br></div><div>ID.ADDPointer(T.getAsOpaquePtr())<br></div><div>is being done, which gives out different results for both the versions of the same function. <br>
<br></div><div>Also, in VisitDecl(), the profiler is adding :<br></div><div>ID.AddPointer(D->getCanonicalDecl()); <br></div><div>which is again different for each version of the same function. <br><br></div><div>Thanks,<br>
Pavan<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 17, 2013 at 5:54 PM, Pavan Pattanada <span dir="ltr"><<a href="mailto:pattanad@uci.edu" target="_blank">pattanad@uci.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thats pretty cool :) I will check what could be done. Thanks a lot!! <br><span class="HOEnZb"><font color="#888888"><br>
</font></span></div><span class="HOEnZb"><font color="#888888">~Pavan <br></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 17, 2013 at 5:44 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Wed, Jul 17, 2013 at 5:20 PM, Pavan Pattanada <span dir="ltr"><<a href="mailto:pattanad@uci.edu" target="_blank">pattanad@uci.edu</a>></span> wrote:<br>

</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div>Yes, What you have mentioned is exactly what I want. So does it mean that Stmt::Profile would generate unique ID (llvm::FoldingSetNodeID) irrespective of it being a compound statement or not? If so, could I use it to compare the two functions using the IDs that are generated using<br>



</div>FunctionDecl::getBody()::profile() ? <br></div></div></div></blockquote><div><br></div></div><div>Yes, you can Stmt::Profile to compare two function bodies. But as noted below, it won't quite do what you want, because it doesn't consider variables declared within the statement to be "the same". You could fix this by teaching StmtProfiler to map declarations to some kind of declaration index if they are declared within the statement being profiled. You'd need similar treatment for LabelDecls. I don't see a good reason why we wouldn't accept such a patch for upstream Clang.</div>

<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><div></div>Thanks,<br></div>Pavan <font face="times new roman,serif"><cite> </cite></font><cite><br>


</cite></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 17, 2013 at 5:01 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Wed, Jul 17, 2013 at 4:18 PM, Pavan Pattanada <span dir="ltr"><<a href="mailto:pattanad@uci.edu" target="_blank">pattanad@uci.edu</a>></span> wrote:<br>



</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>By "same", I mean, their ASTs to be the same to start with. I am working on a tool,  which is used to syntactic/semantic similarity between two versions of the code base. So far, I have been able to get the FunctionDecls of both versions of a function into memory. But I am not sure how to compare them.</div>




</div></blockquote><div><br></div></div><div>This is still a little imprecise. Should functions compare equal if variables have been renamed between them? What if an expression has been rewritten into a trivially equivalent form (for instance, parentheses were added or removed, or p->x was changed to (*p).x)?</div>




<div><br></div><div>Stmt::Profile does nearly what you want (it's the mechanism we use to determine if two dependent expressions are equivalent for the purposes of template redeclaration matching), but it will treat</div>




<div><br></div><div>  void f() { int n; }</div><div>  void g() { int n; }</div><div><br></div><div>as having different bodies, because they do not declare the same variable. That's probably not very hard to fix.</div>



<div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span><font color="#888888"><div class="gmail_extra">~Pavan<br></div></font></span><div class="gmail_extra">




<br><br><div class="gmail_quote"><div>On Wed, Jul 17, 2013 at 3:42 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>
</div><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Wed, Jul 17, 2013 at 10:10 AM, Pavan Pattanada <span dir="ltr"><<a href="mailto:pattanad@uci.edu" target="_blank">pattanad@uci.edu</a>></span> wrote:<br>





</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>Hi, <br></div>I need to compare two versions of the same clang::FunctionDecl function body(a function in C). I would need to compare them statement by statement and say if the two versions are the same. Is there a neat way to do this in the clang framework? </div>






</div></blockquote><div><br></div></div><div>This question is too vague to answer: what do you mean by "the same"? Same source text, same tokens, same tokens other than variable naming, something else?</div></div>






</blockquote></div></div></div><br></div></div>
</blockquote></div></div><br>
</blockquote></div><br></div>
</div></div></blockquote></div></div><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>