llvm-project/clang/unittests
Raphael Isemann 7c4575e15f [ASTImporter] Refactor IsStructurallyEquivalent's Decl overloads to be more consistent
There are several `::IsStructurallyEquivalent` overloads for Decl subclasses
that are used for comparing declarations. There is also one overload that takes
just two Decl pointers which ends up queuing the passed Decls to be later
compared in `CheckKindSpecificEquivalence`.

`CheckKindSpecificEquivalence` implements the dispatch logic for the different
Decl subclasses. It is supposed to hand over the queued Decls to the
subclass-specific `::IsStructurallyEquivalent` overload that will actually
compare the Decl instance. It also seems to implement a few pieces of actual
node comparison logic inbetween the dispatch code.

This implementation causes that the different overloads of
`::IsStructurallyEquivalent` do different (and sometimes no) comparisons
depending on which overload of `::IsStructurallyEquivalent` ends up being
called.

For example, if I want to compare two FieldDecl instances, then I could either
call the `::IsStructurallyEquivalent` with `Decl *` or with `FieldDecl *`
parameters. The overload that takes FieldDecls is doing a correct comparison.
However, the `Decl *` overload just queues the Decl pair.
`CheckKindSpecificEquivalence` has no dispatch logic for `FieldDecl`, so it
always returns true and never does any actual comparison.

On the other hand, if I try to compare two FunctionDecl instances the two
possible overloads of `::IsStructurallyEquivalent` have the opposite behaviour:
The overload that takes `FunctionDecl` pointers isn't comparing the names of the
FunctionDecls while the overload taking a plain `Decl` ends up comparing the
function names (as the comparison logic for that is implemented in
`CheckKindSpecificEquivalence`).

This patch tries to make this set of functions more consistent by making
`CheckKindSpecificEquivalence` a pure dispatch function without any
subclass-specific comparison logic. Also the dispatch logic is now autogenerated
so it can no longer miss certain subclasses.

The comparison code from `CheckKindSpecificEquivalence` is moved to the
respective `::IsStructurallyEquivalent` overload so that the comparison result
no longer depends if one calls the `Decl *` overload or the overload for the
specific subclass. The only difference is now that the `Decl *` overload is
queuing the parameter while the subclass-specific overload is directly doing the
comparison.

`::IsStructurallyEquivalent` is an implementation detail and I don't think the
behaviour causes any bugs in the current implementation (as carefully calling
the right overload for the different classes works around the issue), so the
test for this change is that I added some new code for comparing `MemberExpr`.
The new comparison code always calls the dispatching overload and it previously
failed as the dispatch didn't support FieldDecls.

Reviewed By: martong, a_sidorin

Differential Revision: https://reviews.llvm.org/D87619
2020-09-21 16:41:00 +02:00
..
AST [ASTImporter] Refactor IsStructurallyEquivalent's Decl overloads to be more consistent 2020-09-21 16:41:00 +02:00
ASTMatchers [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl` 2020-09-16 13:16:51 +02:00
Analysis Assignment and Inc/Dec operators wouldn't register as a mutation when Implicit Paren Casts were present 2020-06-09 19:45:57 +01:00
Basic [ADT] Move FixedPoint.h from Clang to LLVM. 2020-08-20 10:29:45 +02:00
CodeGen [AIX] Static init frontend recovery and backend support 2020-08-10 10:10:49 -04:00
CrossTU [clang][NFC] Add a missing 'override' 2020-07-17 17:35:59 -07:00
DirectoryWatcher [DirectoryWatcher] Fix misuse of FSEvents API and data race 2020-02-11 09:25:38 -08:00
Driver [flang][driver] Add the new flang compiler and frontend drivers 2020-09-11 10:55:54 +01:00
Format Add -Wno-error=unknown flag to clang-format. 2020-09-19 10:17:57 +02:00
Frontend Correctly set CompilingPCH in PrecompilePreambleAction. 2020-08-10 17:49:23 +02:00
Index [clang] Do not consider the template arguments of bases to be bases themselves 2020-09-01 19:18:03 -04:00
Lex [clang] Make sure argument expansion locations are correct in presence of predefined buffer 2020-04-22 21:01:52 +02:00
Rename [OpenMP] "UnFix" layering problem with FrontendOpenMP 2020-04-07 14:41:18 -05:00
Rewrite [Rewrite][NFC] Add FIXMEs and tests for RemoveLineIfEmpty bug 2019-08-15 21:17:48 +00:00
Sema Use libClangTesting in the unittest for AST matchers 2020-06-04 17:40:39 +02:00
Serialization Revert "[modules] Do not cache invalid state for modules that we attempted to load." 2020-03-10 10:59:26 -07:00
StaticAnalyzer [analyzer] Fix out-of-tree only clang build by not relaying on private header 2020-07-31 10:28:14 +02:00
Tooling [SyntaxTree][Synthesis] Implement `deepCopy` 2020-09-21 09:27:15 +00:00
libclang [libclang] Add CXRewriter to libclang API 2020-09-04 14:17:03 -07:00
CMakeLists.txt Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest 2020-07-27 08:37:01 -07:00