[all-commits] [llvm/llvm-project] b859c3: [clang-tidy] Add a Standalone diagnostics mode to ...
Nathan James via All-commits
all-commits at lists.llvm.org
Sat Apr 16 01:53:54 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b859c39c40a79ff74033f67d807a18130b9afe30
https://github.com/llvm/llvm-project/commit/b859c39c40a79ff74033f67d807a18130b9afe30
Author: Nathan James <n.james93 at hotmail.co.uk>
Date: 2022-04-16 (Sat, 16 Apr 2022)
Changed paths:
M clang-tools-extra/clang-tidy/ClangTidyCheck.h
M clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
M clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
M clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
M clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
M clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
M clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
M clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
M clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
M clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
M clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
M clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
M clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
M clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
M clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
M clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
M clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
M clang-tools-extra/clang-tidy/utils/IncludeInserter.h
M clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
M clang-tools-extra/clangd/ParsedAST.cpp
M clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
M clang-tools-extra/docs/ReleaseNotes.rst
M clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
Log Message:
-----------
[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
More information about the All-commits
mailing list