Commit a80ab59
Carlos Gálvez
[clang][AST][clang-tidy] Do not set a reduced traversal scope in ASTMatchFinder
This was introduced here with the purpose of speed up clang-tidy,
making it not process system headers:
e4a8969
However it was later realized that this change is too aggressive:
the reduced traversal scope also impacts the ParentMapContext, which
in turn means that matchers like "hasParent" or "hasAncestor" are not
able to find parents in system headers, even if the declaration at
hand is in a user header. This causes regressions for downstream users
writing custom clang-tidy checks:
#128150 (comment)
This patch fixes this problem, as follows:
- Revert the changes to the clang-tidy unit tests.
- Revert setting the TraversalScope in MatchASTConsumer.
- Move the logic to MatchASTVisitor::TraverseDecl instead.
Pros:
- Leaves the ASTContext and ParentMapContext untouched, so hasParent
and similar matchers should work again.
- Keeps avoiding matching and checking decls outside of system headers.
- The broken unit test in readability now works, because we are no
longer processing only TopLevelDecls.
- The changes to the CERT test can be reverted.
- Most likely we don't lose any functionality or introduce false
negatives.
Cons:
- We still have to traverse decls in system headers. I did try to
return false; instead of return true; in the proposed code but that
made around 60 clang-tidy tests to fail.
- We still process many nodes (not Decls) that are in system headers.
As a benchmark, I tried running all clang-tidy checks on a .cpp file
that includes all the standard C++ headers. This leads to:
* Baseline (without any optimizations).
Suppressed 196093 warnings (196093 in non-user code)
10 seconds to run.
* Trunk (aggressive optimizations).
Suppressed 8050 warnings (8050 in non-user code).
1 second to run.
* This patch (conservative optimizations).
Suppressed 141779 warnings (141779 in non-user code).
3 seconds to run.
This patch thus gives some performance improvement while keeping
backwards compatibility. There's still room for improvement which
shall be tackled in a follow-up patch after unbreaking clang-tidy.
Fixes #1306181 parent 8a8e4cf commit a80ab59
File tree
5 files changed
+28
-73
lines changed- clang-tools-extra
- clang-tidy/cert
- docs
- test/clang-tidy/checkers/readability
- clang
- docs
- lib/ASTMatchers
5 files changed
+28
-73
lines changedLines changed: 5 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 38 | | |
63 | 39 | | |
64 | 40 | | |
65 | 41 | | |
66 | 42 | | |
67 | 43 | | |
68 | 44 | | |
69 | | - | |
| 45 | + | |
70 | 46 | | |
71 | | - | |
72 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
73 | 51 | | |
74 | 52 | | |
75 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
| |||
Lines changed: 8 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 36 | | |
42 | 37 | | |
43 | | - | |
44 | | - | |
| 38 | + | |
| 39 | + | |
45 | 40 | | |
46 | 41 | | |
47 | | - | |
48 | | - | |
| 42 | + | |
| 43 | + | |
49 | 44 | | |
50 | 45 | | |
51 | | - | |
52 | | - | |
| 46 | + | |
| 47 | + | |
53 | 48 | | |
54 | 49 | | |
55 | | - | |
56 | | - | |
| 50 | + | |
| 51 | + | |
57 | 52 | | |
58 | | - | |
59 | 53 | | |
60 | 54 | | |
61 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
463 | | - | |
464 | | - | |
465 | | - | |
| 463 | + | |
| 464 | + | |
466 | 465 | | |
467 | 466 | | |
468 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
1464 | 1463 | | |
1465 | 1464 | | |
1466 | 1465 | | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
1467 | 1472 | | |
1468 | 1473 | | |
1469 | 1474 | | |
1470 | 1475 | | |
1471 | 1476 | | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1472 | 1481 | | |
1473 | 1482 | | |
1474 | 1483 | | |
| |||
1574 | 1583 | | |
1575 | 1584 | | |
1576 | 1585 | | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
| 1586 | + | |
| 1587 | + | |
1580 | 1588 | | |
1581 | 1589 | | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | 1590 | | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | 1591 | | |
1597 | 1592 | | |
1598 | 1593 | | |
1599 | 1594 | | |
1600 | 1595 | | |
1601 | 1596 | | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
1605 | | - | |
1606 | | - | |
1607 | | - | |
1608 | 1597 | | |
1609 | 1598 | | |
1610 | | - | |
1611 | | - | |
1612 | 1599 | | |
1613 | 1600 | | |
1614 | 1601 | | |
| |||
1727 | 1714 | | |
1728 | 1715 | | |
1729 | 1716 | | |
1730 | | - | |
1731 | | - | |
| 1717 | + | |
1732 | 1718 | | |
1733 | 1719 | | |
1734 | 1720 | | |
| |||
0 commit comments