Alexander Kornienko 271e181c78 [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.
Summary:
(Originally started as a clang-tidy check but there's already D45444 so shifted to just adding ExprMutationAnalyzer)

`ExprMutationAnalyzer` is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.)

This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization.

It should also be possible to construct checks like D45444 (suggest adding const to variable declaration) or https://bugs.llvm.org/show_bug.cgi?id=21981 (suggest adding const to member function) using this helper function.

This function is tested by itself and is intended to stay generally useful instead of tied to any particular check.

Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov, george.karpenkov

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, shuaiwang, rnkovacs, hokein, alexfh, aaron.ballman, a.sidorin, Eugene.Zelenko, xazax.hun, JonasToth, klimek, mgorny, cfe-commits

Tags: #clang-tools-extra

Patch by Shuai Wang.

Differential Revision: https://reviews.llvm.org/D45679

llvm-svn: 335736
2018-06-27 14:30:55 +00:00

39 lines
831 B
CMake

set(LLVM_LINK_COMPONENTS
support
)
get_filename_component(CLANG_LINT_SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/../../clang-tidy REALPATH)
include_directories(${CLANG_LINT_SOURCE_DIR})
add_extra_unittest(ClangTidyTests
ClangTidyDiagnosticConsumerTest.cpp
ClangTidyOptionsTest.cpp
ExprMutationAnalyzerTest.cpp
IncludeInserterTest.cpp
GoogleModuleTest.cpp
LLVMModuleTest.cpp
NamespaceAliaserTest.cpp
ObjCModuleTest.cpp
OverlappingReplacementsTest.cpp
UsingInserterTest.cpp
ReadabilityModuleTest.cpp)
target_link_libraries(ClangTidyTests
PRIVATE
clangAST
clangASTMatchers
clangBasic
clangFrontend
clangLex
clangTidy
clangTidyAndroidModule
clangTidyGoogleModule
clangTidyLLVMModule
clangTidyObjCModule
clangTidyReadabilityModule
clangTidyUtils
clangTooling
clangToolingCore
)