[cfe-dev] Way to compare two Function bodies.

Pavan Pattanada pattanad at uci.edu
Wed Jul 17 17:20:30 PDT 2013


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
FunctionDecl::getBody()::profile() ?

Thanks,
Pavan


On Wed, Jul 17, 2013 at 5:01 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Wed, Jul 17, 2013 at 4:18 PM, Pavan Pattanada <pattanad at uci.edu> wrote:
>
>> 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.
>>
>
> 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)?
>
> 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
>
>   void f() { int n; }
>   void g() { int n; }
>
> as having different bodies, because they do not declare the same variable.
> That's probably not very hard to fix.
>
>
>> ~Pavan
>>
>>
>> On Wed, Jul 17, 2013 at 3:42 PM, Richard Smith <richard at metafoo.co.uk>wrote:
>>
>>> On Wed, Jul 17, 2013 at 10:10 AM, Pavan Pattanada <pattanad at uci.edu>wrote:
>>>
>>>> Hi,
>>>> 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?
>>>>
>>>
>>> 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?
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130717/c1822227/attachment.html>


More information about the cfe-dev mailing list