[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 3 09:17:01 PST 2025


steakhal wrote:

> > Could you please run this with `--enable-check-profile` to see how heavy it is?
> 
> I plan to re-run it on clang soon, and share the results.


I've picked a heavy TU of clang for the test: `clang/lib/Sema/SemaExpr.cpp`
```
===-------------------------------------------------------------------------===
                          clang-tidy checks profiling
===-------------------------------------------------------------------------===
  Total Execution Time: 12.6394 seconds (12.6125 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   1.3723 ( 19.8%)   1.3141 ( 23.0%)   2.6865 ( 21.3%)   2.6692 ( 21.2%)  misc-unused-using-decls
   0.7283 ( 10.5%)   0.6586 ( 11.5%)   1.3869 ( 11.0%)   1.3875 ( 11.0%)  llvm-prefer-isa-or-dyn-cast-in-conditionals
   0.9165 ( 13.2%)   0.2823 (  4.9%)   1.1987 (  9.5%)   1.1982 (  9.5%)  llvm-qualified-auto
   0.5424 (  7.8%)   0.4717 (  8.3%)   1.0141 (  8.0%)   1.0058 (  8.0%)  misc-unconventional-assign-operator
   0.4127 (  6.0%)   0.3865 (  6.8%)   0.7991 (  6.3%)   0.7982 (  6.3%)  misc-misleading-identifier
   0.4212 (  6.1%)   0.3571 (  6.2%)   0.7783 (  6.2%)   0.7810 (  6.2%)  misc-confusable-identifiers
   0.4033 (  5.8%)   0.3750 (  6.6%)   0.7784 (  6.2%)   0.7775 (  6.2%)  misc-definitions-in-headers
   0.3977 (  5.7%)   0.3700 (  6.5%)   0.7677 (  6.1%)   0.7658 (  6.1%)  misc-non-copyable-objects
   0.2984 (  4.3%)   0.2572 (  4.5%)   0.5556 (  4.4%)   0.5532 (  4.4%)  misc-redundant-expression
   0.2539 (  3.7%)   0.2164 (  3.8%)   0.4703 (  3.7%)   0.4691 (  3.7%)  performance-redundant-lookup
   0.2140 (  3.1%)   0.1966 (  3.4%)   0.4107 (  3.2%)   0.4092 (  3.2%)  misc-misplaced-const
   0.2021 (  2.9%)   0.1826 (  3.2%)   0.3846 (  3.0%)   0.3911 (  3.1%)  misc-use-internal-linkage
   0.1293 (  1.9%)   0.1195 (  2.1%)   0.2488 (  2.0%)   0.2495 (  2.0%)  misc-new-delete-overloads
   0.1141 (  1.6%)   0.1046 (  1.8%)   0.2187 (  1.7%)   0.2189 (  1.7%)  llvm-prefer-register-over-unsigned
   0.1209 (  1.7%)   0.0911 (  1.6%)   0.2120 (  1.7%)   0.2112 (  1.7%)  misc-static-assert
   0.1081 (  1.6%)   0.0989 (  1.7%)   0.2070 (  1.6%)   0.2093 (  1.7%)  llvm-twine-local
   0.0673 (  1.0%)   0.0670 (  1.2%)   0.1343 (  1.1%)   0.1325 (  1.1%)  misc-unused-alias-decls
   0.0693 (  1.0%)   0.0633 (  1.1%)   0.1326 (  1.0%)   0.1309 (  1.0%)  misc-uniqueptr-reset-release
   0.0699 (  1.0%)   0.0567 (  1.0%)   0.1266 (  1.0%)   0.1261 (  1.0%)  llvm-else-after-return
   0.0736 (  1.1%)   0.0358 (  0.6%)   0.1094 (  0.9%)   0.1093 (  0.9%)  llvm-namespace-comment
   0.0100 (  0.1%)   0.0091 (  0.2%)   0.0191 (  0.2%)   0.0190 (  0.2%)  misc-misleading-bidirectional
   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)  misc-throw-by-value-catch-by-reference
   6.9252 (100.0%)   5.7142 (100.0%)  12.6394 (100.0%)  12.6125 (100.0%)  Total
```
   
The check `performance-redundant-lookup` had a single hit at line 5353 for that TU, which was a TP:
```c++
  if (Param->hasUnparsedDefaultArg()) {
    assert(!RewrittenInit && "Should not have a rewritten init expression yet");
    // If we've already cleared out the location for the default argument,
    // that means we're parsing it right now.
    if (!UnparsedDefaultArgLocs.count(Param)) { // <---------------------- first lookup
      Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
      Diag(CallLoc, diag::note_recursive_default_argument_used_here);
      Param->setInvalidDecl();
      return true;
    }

    Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later)
        << FD << cast<CXXRecordDecl>(FD->getDeclContext());
    Diag(UnparsedDefaultArgLocs[Param], // <------------------------- second lookup
         diag::note_default_argument_declared_here);
    return true;
  }
```

https://github.com/llvm/llvm-project/pull/125420


More information about the cfe-commits mailing list