summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ASTMatchers] HasNameMatcher handles `extern "C"`Nathan James2020-02-271-0/+15
| | | | | | | | | | | | | | | | Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=42193 | hasName AST matcher is confused by extern "C" in namespace. ]] Reviewers: klimek, aaron.ballman, gribozavr2 Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75202 (cherry picked from commit 16cabf278fc8c14d415e677ce0bc40d46a6de30d)
* Add a new AST matcher 'optionally'.Rihan Yang2020-01-081-0/+21
| | | | | | | | This matcher matches any node and at the same time executes all its inner matchers to produce any possbile result bindings. This is useful when a user wants certain supplementary information that's not always present along with the main match result.
* Handle init statements in readability-else-after-returnNathan James2020-01-021-0/+29
| | | | | | | | | | Adds a new ASTMatcher condition called 'hasInitStatement()' that matches if, switch and range-for statements with an initializer. Reworked clang-tidy readability-else-after-return to handle variables in the if condition or init statements in c++17 ifs. Also checks if removing the else would affect object lifetimes in the else branch. Fixes PR44364.
* Fix the nullPointerConstant() test to get bots back to green.Aaron Ballman2019-08-221-1/+1
| | | | llvm-svn: 369686
* [Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-13/+13
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
* [clang] Update isDerivedFrom to support Objective-C classes 🔍Stephane Moore2019-08-121-0/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change updates `isDerivedFrom` to support Objective-C classes by converting it to a polymorphic matcher. Notes: The matching behavior for Objective-C classes is modeled to match the behavior of `isDerivedFrom` with C++ classes. To that effect, `isDerivedFrom` matches aliased types of derived Objective-C classes, including compatibility aliases. To achieve this, the AST visitor has been updated to map compatibility aliases to their underlying Objective-C class. `isSameOrDerivedFrom` also provides similar behaviors for C++ and Objective-C classes. The behavior that `cxxRecordDecl(isSameOrDerivedFrom("X"))` does not match `class Y {}; typedef Y X;` is mirrored for Objective-C in that `objcInterfaceDecl(isSameOrDerivedFrom("X"))` does not match either `@interface Y @end typedef Y X;` or `@interface Y @end @compatibility_alias X Y;`. Test Notes: Ran clang unit tests. Reviewers: aaron.ballman, jordan_rose, rjmccall, klimek, alexfh, gribozavr Reviewed By: aaron.ballman, gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60543 llvm-svn: 368632
* [clang][NFC] Move matcher ignoringElidableConstructorCall's tests to ↵Yitzhak Mandelbaum2019-08-081-85/+0
| | | | | | | | | | | | | | | | | | | appropriate file. Summary: `ignoringElidableConstructorCall` is a traversal matcher, but its tests are grouped with narrowing-matcher tests. This revision moves them to the correct file. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65963 llvm-svn: 368326
* [clang] Update `ignoringElidableConstructorCall` matcher to ignore ↵Yitzhak Mandelbaum2019-08-081-0/+17
| | | | | | | | | | | | | | | | | | | `ExprWithCleanups`. Summary: The `ExprWithCleanups` node is added to the AST along with the elidable CXXConstructExpr. If it is the outermost node of the node being matched, ignore it as well. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65944 llvm-svn: 368319
* [clang] Fail for empty names in is*DerivedFrom matchers.Anton Bikineev2019-07-251-0/+7
| | | | | | Differential Revision: https://reviews.llvm.org/D65279 llvm-svn: 367022
* [clang] Add isDirectlyDerivedFrom AST matcher.Anton Bikineev2019-07-251-0/+30
| | | | | | Differential Revision: https://reviews.llvm.org/D65092 llvm-svn: 367010
* [clang] Adapt ASTMatcher to explicit(bool) specifierGauthier Harnisch2019-06-191-0/+41
| | | | | | | | | | | | | | | | | | | | Summary: Changes: - add an ast matcher for deductiong guide. - allow isExplicit matcher for deductiong guide. - add hasExplicitSpecifier matcher which give access to the expression of the explicit specifier if present. Reviewers: klimek, rsmith, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61552 llvm-svn: 363855
* Added AST matcher for ignoring elidable constructorsDmitri Gribenko2019-06-131-4/+72
| | | | | | | | | | | | | | | | | | Summary: Added AST matcher for ignoring elidable move constructors Reviewers: hokein, gribozavr Reviewed By: hokein, gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63149 Patch by Johan Vikström. llvm-svn: 363262
* Added an AST matcher for declarations that are in the `std` namespaceDmitri Gribenko2019-05-031-0/+51
| | | | | | | | | | | | Reviewers: alexfh Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61480 llvm-svn: 359876
* [ASTMatchers][OpenMP] OpenMP Structured-block-related matchersRoman Lebedev2019-03-211-0/+65
| | | | | | | | | | | | | | | | | Summary: Exposes to the for ASTMatchers the interface/modelling of OpenMP structured-block. Reviewers: gribozavr, aaron.ballman, JonasToth, george.karpenkov Reviewed By: gribozavr, aaron.ballman Subscribers: guansong, jdoerfert, cfe-commits Tags: #clang, #openmp Differential Revision: https://reviews.llvm.org/D59463 llvm-svn: 356676
* [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handlingRoman Lebedev2019-03-211-0/+168
| | | | | | | | | | | | | | | | | | | Summary: `OMPClause` is the base class, it is not descendant from **any** other class, therefore for it to work with e.g. `VariadicDynCastAllOfMatcher<>`, it needs to be handled here. Reviewers: sbenza, bkramer, pcc, klimek, hokein, gribozavr, aaron.ballman, george.karpenkov Reviewed By: gribozavr, aaron.ballman Subscribers: guansong, jdoerfert, alexfh, ABataev, cfe-commits Tags: #openmp, #clang Differential Revision: https://reviews.llvm.org/D57112 llvm-svn: 356675
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang] Add AST matcher for initializer list membersHyrum Wright2019-01-071-0/+12
| | | | | | | | | | | | | Summary: Much like hasArg for various call expressions, this allows LibTooling users to match against a member of an initializer list. This is currently being used as part of the abseil-duration-scale clang-tidy check. Differential Revision: https://reviews.llvm.org/D56090 llvm-svn: 350523
* [clang] Add AST matcher for block expressions 🔍Stephane Moore2018-12-131-0/+4
| | | | | | | | | | | | | | | | | | Summary: This change adds a new AST matcher for block expressions. Test Notes: Ran the clang unit tests. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55546 llvm-svn: 349004
* Revert rL347462 "[ASTMatchers] Add hasSideEffect() matcher."Clement Courbet2018-11-221-16/+0
| | | | | | Breaks some buildbots. llvm-svn: 347463
* [ASTMatchers] Add hasSideEffect() matcher.Clement Courbet2018-11-221-0/+16
| | | | | | | | | | | | Summary: Exposes Expr::HasSideEffects. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D54830 llvm-svn: 347462
* Add the isStaticLocal() AST matcher for matching on local static variables.Aaron Ballman2018-10-291-0/+8
| | | | | | Patch by Joe Ranieri. llvm-svn: 345502
* [ASTMatchers] Let isArrow also support UnresolvedMemberExpr, ↵Shuai Wang2018-09-171-0/+13
| | | | | | | | | | | | CXXDependentScopeMemberExpr Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52157 llvm-svn: 342407
* [ASTMatchers] add three matchers for dependent expressionsJonas Toth2018-09-111-0/+42
| | | | | | | | | | | | | | | | | | | Summary: The new matchers can be used to check if an expression is type-, value- or instantiation-dependent in a templated context. These matchers are used in a clang-tidy check and generally useful as the problem of unresolved templates occurs more often in clang-tidy and they provide an easy way to check for this issue. Reviewers: aaron.ballman, alexfh, klimek Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51880 llvm-svn: 341958
* [ASTMatchers] Let hasObjectExpression also support UnresolvedMemberExpr, ↵Shuai Wang2018-08-231-0/+20
| | | | | | | | | | | | CXXDependentScopeMemberExpr Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50617 llvm-svn: 340547
* [ASTMatchers] Introduce a matcher for `ObjCIvarExpr`, support getting it's ↵George Karpenkov2018-07-271-0/+10
| | | | | | | | | | | | | declaration. ObjCIvarExpr is *not* a subclass of MemberExpr, and a separate matcher is required to support it. Adding a hasDeclaration support as well, as it's not very useful without it. Differential Revision: https://reviews.llvm.org/D49701 llvm-svn: 338137
* [ASTMatchers] Add an isMain() matcherGeorge Karpenkov2018-07-231-0/+8
| | | | | | Differential Revision: https://reviews.llvm.org/D49615 llvm-svn: 337761
* [ASTMatchers] Overload isConstexpr for ifStmtsGabor Horvath2018-05-081-0/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D46233 llvm-svn: 331759
* [ASTMatchers] Add isAssignmentOperator matcherPeter Szecsi2018-03-271-0/+15
| | | | | | | | | | | Adding a matcher for BinaryOperator and cxxOperatorCallExpr to be able to decide whether it is any kind of assignment operator or not. This would be useful since allows us to easily detect assignments via matchers for static analysis (Tidy, SA) purposes. Differential Revision: https://reviews.llvm.org/D44893 llvm-svn: 328618
* [ASTMatchers] isTemplateInstantiation: also match explicit instantiation ↵Eric Liu2018-02-211-0/+8
| | | | | | | | | | | | | | | | | | declaration. Summary: Example: template <typename T> class X {}; class A {}; // Explicit instantiation declaration. extern template class X<A>; Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43567 llvm-svn: 325678
* Add hasTrailingReturn AST matcherJulie Hockett2018-01-221-0/+19
| | | | | | | | Adds AST matcher for a FunctionDecl that has a trailing return type. Differential Revision: https://reviews.llvm.org/D42273 llvm-svn: 323158
* [ASTMatcher] Add isScoped matcher for enumDecl.Haojian Wu2018-01-181-0/+5
| | | | | | | | | | | | Summary: Reviewers: bkramer, aaron.ballman Subscribers: aaron.ballman, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D42185 llvm-svn: 322826
* [ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarationsRoman Lebedev2018-01-171-0/+78
| | | | | | | | | | | | | | Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: dblaikie, klimek, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D41455 llvm-svn: 322746
* Add the hasDefinition() AST matcher to match class declarations that also ↵Aaron Ballman2017-11-291-0/+21
| | | | | | | | have a definition. Patch by Julie Hockett. llvm-svn: 319360
* [ASTMatchers] Matchers for new[] operatorsAdam Balogh2017-11-231-0/+10
| | | | | | | | Two new matchers for `CXXNewExpr` are added which may be useful e.g. in `clang-tidy` checkers. One of them is `isArray` which matches `new[]` but not plain `new`. The other one, `hasArraySize` matches `new[]` for a given size. llvm-svn: 318909
* Add an AST matcher for hasDefaultArgument() to match on parameter ↵Aaron Ballman2017-11-211-0/+7
| | | | | | | | declarations that have a default value. Patch by Julie Hockett. llvm-svn: 318794
* Make isDefinition matcher support ObjCMethodDeclDave Lee2017-11-141-0/+8
| | | | | | | | | | | | | | | | | Summary: Allow the `isDefinition()` matcher to apply to `ObjCMethodDecl` nodes, in addition to those it already supports. For whatever reason, `ObjCMethodDecl` does not inherit from `FunctionDecl` and so this is specialization is necessary. Reviewers: aaron.ballman, malcolm.parsons, alexshap Reviewed By: aaron.ballman Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39948 llvm-svn: 318152
* PR19668, PR23034: Fix handling of move constructors and deleted copyRichard Smith2017-08-161-20/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | constructors when deciding whether classes should be passed indirectly. This fixes ABI differences between Clang and GCC: * Previously, Clang ignored the move constructor when making this determination. It now takes the move constructor into account, per https://github.com/itanium-cxx-abi/cxx-abi/pull/17 (this change may seem recent, but the ABI change was agreed on the Itanium C++ ABI list a long time ago). * Previously, Clang's behavior when the copy constructor was deleted was unstable -- depending on whether the lazy declaration of the copy constructor had been triggered, you might get different behavior. We now eagerly declare the copy constructor whenever its deletedness is unclear, and ignore deleted copy/move constructors when looking for a trivial such constructor. This also fixes an ABI difference between Clang and MSVC: * If the copy constructor would be implicitly deleted (but has not been lazily declared yet), for instance because the class has an rvalue reference member, we would pass it directly. We now pass such a class indirectly, matching MSVC. Based on a patch by Vassil Vassilev, which was based on a patch by Bernd Schmidt, which was based on a patch by Reid Kleckner! This is a re-commit of r310401, which was reverted in r310464 due to ARM failures (which should now be fixed). llvm-svn: 310983
* Revert "PR19668, PR23034: Fix handling of move constructors and deleted copy ↵Diana Picus2017-08-091-29/+20
| | | | | | | | | constructors when deciding whether classes should be passed indirectly." This reverts commit r310401 because it seems to have broken some ARM bot(s). llvm-svn: 310464
* PR19668, PR23034: Fix handling of move constructors and deleted copyRichard Smith2017-08-081-20/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | constructors when deciding whether classes should be passed indirectly. This fixes ABI differences between Clang and GCC: * Previously, Clang ignored the move constructor when making this determination. It now takes the move constructor into account, per https://github.com/itanium-cxx-abi/cxx-abi/pull/17 (this change may seem recent, but the ABI change was agreed on the Itanium C++ ABI list a long time ago). * Previously, Clang's behavior when the copy constructor was deleted was unstable -- depending on whether the lazy declaration of the copy constructor had been triggered, you might get different behavior. We now eagerly declare the copy constructor whenever its deletedness is unclear, and ignore deleted copy/move constructors when looking for a trivial such constructor. This also fixes an ABI difference between Clang and MSVC: * If the copy constructor would be implicitly deleted (but has not been lazily declared yet), for instance because the class has an rvalue reference member, we would pass it directly. We now pass such a class indirectly, matching MSVC. llvm-svn: 310401
* [ASTMatchers] Add hasInClassInitializer traversal matcher for FieldDecl.Malcolm Parsons2016-12-241-0/+10
| | | | | | | | | | | | | | | Summary: I needed to know whether a FieldDecl had an in-class initializer for D26453. I used a narrowing matcher there, but a traversal matcher might be generally useful. Reviewers: sbenza, bkramer, klimek, aaron.ballman Subscribers: aaron.ballman, Prazek, cfe-commits Differential Revision: https://reviews.llvm.org/D28034 llvm-svn: 290492
* [ASTMatcher] Clarify isStaticStorageClass and hasStaticStorageDuration ↵Haojian Wu2016-09-271-1/+4
| | | | | | | | | | | | documents. Reviewers: aaron.ballman Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24928 llvm-svn: 282474
* [ASTMatcher] Add isStaticStorageClass matcher for varDecl and functionDecl.Haojian Wu2016-09-261-0/+8
| | | | | | | | | | Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24821 llvm-svn: 282415
* Add an AST matcher for external formal linkage.Aaron Ballman2016-08-171-0/+16
| | | | | | Patch by Visoiu Mistrih llvm-svn: 278926
* Make isExternC work on VarDecls too.Benjamin Kramer2016-08-041-0/+6
| | | | llvm-svn: 277712
* [ASTMatchers] isSignedInteger() and isUnsignedInteger()Clement Courbet2016-07-121-0/+12
| | | | | | | | Complementary to isInteger(), these match signed and unsigned integers respectively. Review: http://reviews.llvm.org/D21989 llvm-svn: 275157
* Add AST matchers for handling bit-fields and narrowing based on their width.Aaron Ballman2016-07-061-0/+8
| | | | llvm-svn: 274652
* [ASTMatchers] Add isLambda() matcher.Samuel Benzaquen2016-06-281-0/+6
| | | | llvm-svn: 274015
* Make isNoThrow and hasDynamicExceptionSpec polymorphic so they can be used ↵Aaron Ballman2016-06-071-0/+21
| | | | | | | | with both functionDecl and functionPrototype matchers. Patch by Don Hinton. llvm-svn: 272028
* Dividied ASTMatcherTests into 4 filesPiotr Padlewski2016-05-171-0/+1888
fix for long compilation [20061] http://reviews.llvm.org/D20210 llvm-svn: 269802
OpenPOWER on IntegriCloud