[all-commits] [llvm/llvm-project] 94ca85: [clang-tidy] Add support for determining constness...

Clement Courbet via All-commits all-commits at lists.llvm.org
Mon Feb 26 00:55:19 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 94ca854d3c874322b1d4b5606c5762adcd3b8e05
      https://github.com/llvm/llvm-project/commit/94ca854d3c874322b1d4b5606c5762adcd3b8e05
  Author: Clement Courbet <courbet at google.com>
  Date:   2024-02-26 (Mon, 26 Feb 2024)

  Changed paths:
    M clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
    M clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
    M clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
    M clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

  Log Message:
  -----------
  [clang-tidy] Add support for determining constness of more expressions. (#82617)

This uses a more systematic approach for determining whcich
`DeclRefExpr`s mutate the underlying object: Instead of using a few
matchers, we walk up the AST until we find a parent that we can prove
cannot change the underlying object.

This allows us to handle most address taking and dereference, bindings
to value and const& variables, and track constness of pointee (see
changes in DeclRefExprUtilsTest.cpp).

This allows supporting more patterns in
`performance-unnecessary-copy-initialization`.

Those two patterns are relatively common:

```
const auto e = (*vector_ptr)[i]
```

and

```
const auto e = vector_ptr->at(i);
```

In our codebase, we have around 25% additional findings from
`performance-unnecessary-copy-initialization` with this change. I did
not see any additional false positives.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list