summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clang-tidy/ExprMutationAnalyzerTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clangtidy] Remove old copy of ExprMutationAnalyzerShuai Wang2018-09-111-947/+0
| | | | | | | | | | | | | | | | | | Summary: This is 2/2 of moving ExprMutationAnalyzer from clangtidy to clang/Analysis. ExprMutationAnalyzer is moved to clang/Analysis in D51948. This diff migrates existing usages within clangtidy to point to the new location and remove the old copy of ExprMutationAnalyzer. Reviewers: george.karpenkov, JonasToth Reviewed By: george.karpenkov Subscribers: mgorny, a.sidorin, Szelethus, cfe-commits Differential Revision: https://reviews.llvm.org/D51950 llvm-svn: 342006
* [clang-tidy] Handle sugared reference types in ExprMutationAnalyzerShuai Wang2018-09-111-16/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This handles cases like this: ``` typedef int& IntRef; void mutate(IntRef); void f() { int x; mutate(x); } ``` where the param type is a sugared type (`TypedefType`) instead of a reference type directly. Note that another category of similar but different cases are already handled properly before: ``` typedef int Int; void mutate(Int&); void f() { int x; mutate(x); } ``` Reviewers: aaron.ballman, alexfh, george.karpenkov Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits Differential Revision: https://reviews.llvm.org/D50953 llvm-svn: 341986
* [clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzerShuai Wang2018-09-111-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | Summary: For smart pointers like std::unique_ptr which uniquely owns the underlying object, treat the mutation of the pointee as mutation of the smart pointer itself. This gives better behavior for cases like this: ``` void f(std::vector<std::unique_ptr<Foo>> v) { // undesirable analyze result of `v` as not mutated. for (auto& p : v) { p->mutate(); // only const member function `operator->` is invoked on `p` } } ``` Reviewers: hokein, george.karpenkov Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits Differential Revision: https://reviews.llvm.org/D50883 llvm-svn: 341967
* Revert "Revert "[clang-tidy] Handle unresolved expressions in ↵Shuai Wang2018-09-111-4/+122
| | | | | | | | | | | ExprMutationAnalyzer"" This is the same as D50619 plus fixes for buildbot failures on windows. The test failures on windows are caused by -fdelayed-template-parsing and is fixed by forcing -fno-delayed-template-parsing on test cases that requires AST for uninstantiated templates. llvm-svn: 341891
* Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer"Shuai Wang2018-09-101-106/+4
| | | | | | | | | | | | | | | | | Summary: Tests somehow break on windows (and only on windows) http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/13003 http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/13747 I have yet figure out why so reverting to unbreak first. Reviewers: george.karpenkov Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits Differential Revision: https://reviews.llvm.org/D51898 llvm-svn: 341886
* [clang-tidy] ExprMutationAnalyzer: construct from references. Fixes PR38888Roman Lebedev2018-09-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: I have hit this the rough way, while trying to use this in D51870. There is no particular point in storing the pointers, and moreover the pointers are assumed to be non-null, and that assumption is not enforced. If they are null, it won't be able to do anything good with them anyway. Initially i thought about simply adding asserts() that they are not null, but taking/storing references looks like even cleaner solution? Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38888 | PR38888 ]] Reviewers: JonasToth, shuaiwang, alexfh, george.karpenkov Reviewed By: shuaiwang Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D51884 llvm-svn: 341854
* [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzerShuai Wang2018-09-101-4/+106
| | | | | | | | | | | | | | Summary: - If a function is unresolved, assume it mutates its arguments - Follow unresolved member expressions for nested mutations Reviewers: aaron.ballman, JonasToth, george.karpenkov Subscribers: xazax.hun, a.sidorin, cfe-commits Differential Revision: https://reviews.llvm.org/D50619 llvm-svn: 341848
* Remove explicit type from an initializer list. NFC.Alexander Kornienko2018-06-281-2/+2
| | | | llvm-svn: 335846
* Fix formatting. NFC.Alexander Kornienko2018-06-281-5/+4
| | | | llvm-svn: 335845
* Fixup test to compile with -frtti when trying to use typeid() as the PS4 ↵Douglas Yung2018-06-281-4/+7
| | | | | | does not have it on by default and it was failing on the PS4 linux bot because of this. llvm-svn: 335799
* [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression ↵Alexander Kornienko2018-06-271-0/+609
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Reverting r334604 due to failing tests.Aaron Ballman2018-06-131-609/+0
| | | | | | http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/31500 llvm-svn: 334606
* Add a new class to analyze whether an expression is mutated within a statement.Aaron Ballman2018-06-131-0/+609
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. Patch by Shuai Wang llvm-svn: 334604
OpenPOWER on IntegriCloud