llvm/clang-tools-extra/clang-tidy/performance
Nathan James b859c39c40
[clang-tidy] Add a Standalone diagnostics mode to clang-tidy
Adds a flag to `ClangTidyContext` that is used to indicate to checks that fixes will only be applied one at a time.
This is to indicate to checks that each fix emitted should not depend on any other fixes emitted across the translation unit.
I've currently implemented the `IncludeInserter`, `LoopConvertCheck` and `PreferMemberInitializerCheck` to use these support these modes.

Reasoning behind this is in use cases like `clangd` it's only possible to apply one fix at a time.
For include inserter checks, the include is only added once for the first diagnostic that requires it, this will result in subsequent fixes not having the included needed.

A similar issue is seen in the `PreferMemberInitializerCheck` where the `:` will only be added for the first member that needs fixing.

Fixes emitted in `StandaloneDiagsMode` will likely result in malformed code if they are applied all together, conversely fixes currently emitted may result in malformed code if they are applied one at a time.
For this reason invoking `clang-tidy` from the binary will always with `StandaloneDiagsMode` disabled, However using it as a library its possible to select the mode you wish to use, `clangd` always selects `StandaloneDiagsMode`.

This is an example of the current behaviour failing
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) {
    A = D;
    B = E; // Fix Here
  }
};
```
Incorrectly transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E), B(E) {
    A = D;
     // Fix Here
  }
};
```
In `StandaloneDiagsMode`, it gets transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) : B(E) {
    A = D;
     // Fix Here
  }
};
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D97121
2022-04-16 09:53:35 +01:00
..
CMakeLists.txt
FasterStringFindCheck.cpp
FasterStringFindCheck.h
ForRangeCopyCheck.cpp
ForRangeCopyCheck.h
ImplicitConversionInLoopCheck.cpp
ImplicitConversionInLoopCheck.h
InefficientAlgorithmCheck.cpp
InefficientAlgorithmCheck.h
InefficientStringConcatenationCheck.cpp
InefficientStringConcatenationCheck.h
InefficientVectorOperationCheck.cpp [clang-tidy] Make performance-inefficient-vector-operation work on members 2022-04-08 14:17:41 +01:00
InefficientVectorOperationCheck.h
MoveConstArgCheck.cpp [clang-tidy] add option performance-move-const-arg.CheckMoveToConstRef 2022-02-10 13:31:07 +00:00
MoveConstArgCheck.h [clang-tidy] add option performance-move-const-arg.CheckMoveToConstRef 2022-02-10 13:31:07 +00:00
MoveConstructorInitCheck.cpp
MoveConstructorInitCheck.h
NoAutomaticMoveCheck.cpp
NoAutomaticMoveCheck.h
NoexceptMoveConstructorCheck.cpp [clang-tidy] NoexceptMoveConstructorCheck::check - use castAs<> instead of getAs<> to avoid dereference of nullptr 2022-02-12 10:57:09 +00:00
NoexceptMoveConstructorCheck.h
NoIntToPtrCheck.cpp
NoIntToPtrCheck.h
PerformanceTidyModule.cpp
TriviallyDestructibleCheck.cpp
TriviallyDestructibleCheck.h
TypePromotionInMathFnCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
TypePromotionInMathFnCheck.h
UnnecessaryCopyInitialization.cpp
UnnecessaryCopyInitialization.h
UnnecessaryValueParamCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
UnnecessaryValueParamCheck.h