This is an archive of the discontinued LLVM Phabricator instance.

[clang-diff] Fix some errors and inconsistencies
ClosedPublic

Authored by johannes on Aug 1 2017, 1:45 PM.

Details

Summary

Fix to the computation of the rightmost descendant. Prevents root
nodes from being mapped if they are already mapped. This only makes a
difference when we compare AST Nodes other than entire translation units, a
feature which still has to be tested.

Diff Detail

Repository
rL LLVM

Event Timeline

johannes created this revision.Aug 1 2017, 1:45 PM
arphaman edited edge metadata.Aug 2 2017, 4:27 AM

Is this an NFC patch or does it have an impact on the produced results? If yes, can you come up with a test that ensures that the new results are verified?

include/clang/Tooling/ASTDiff/ASTDiff.h
96 ↗(On Diff #109198)

It might be better to add a move constructor which would disable copy constructors.

johannes added inline comments.Aug 2 2017, 5:10 AM
include/clang/Tooling/ASTDiff/ASTDiff.h
96 ↗(On Diff #109198)

ASTDiff::getMapped internally uses the address of the SyntaxTree that is passed as parameter.
So the tree must be exactly the same as the one that is passed to the constructor of ASTDiff.

This is quite bad. I will change ASTDiff::getMapped to accept a boolean or split it into two methods
Should I still add a move constructor?

arphaman added inline comments.Aug 2 2017, 5:16 AM
include/clang/Tooling/ASTDiff/ASTDiff.h
96 ↗(On Diff #109198)

Can't you just use the TreeImpl pointer value? That should be the same even after you've moved SyntaxTree with the move constructor.

johannes updated this revision to Diff 109414.Aug 2 2017, 1:32 PM

move most functional changes to other commits
move constructor for Syntaxtree

johannes added inline comments.Aug 2 2017, 1:51 PM
include/clang/Tooling/ASTDiff/ASTDiff.h
96 ↗(On Diff #109198)

ok perfect

LGTM. Although I'm not 100% sure it's fully NFC, so if you can't come up with a test please justify why.

LGTM. Although I'm not 100% sure it's fully NFC, so if you can't come up with a test please justify why.

There are changes that affect the output.
Firstly the computation of the rightmost descendant; the added assertion fails every time with the old version.
Secondly, the change around line 811 prevents root nodes from being mapped if they are already mapped. When comparing translation units this happens only if the two trees are identical (in this case the output would not change). Otherwise, it would require some change in the client to demonstrate how the behaviour changed. One needs to compare AST Nodes other than entire translation units. At some point there will be something that uses this feature so we cover it too (or remove the feature). So I'd keep it like this

Ok, please include this info in the commit message.

johannes updated this revision to Diff 109536.Aug 3 2017, 6:32 AM
johannes edited the summary of this revision. (Show Details)

update commit message

This revision was automatically updated to reflect the committed changes.