summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Dividied ASTMatcherTests into 4 filesPiotr Padlewski2016-05-171-5646/+0
| | | | | | | fix for long compilation [20061] http://reviews.llvm.org/D20210 llvm-svn: 269802
* Add the hasDynamicExceptionSpec() AST matcher to match function declarations ↵Aaron Ballman2016-05-161-0/+16
| | | | | | | | that have a dynamic exception specification. Patch by Don Hinton. llvm-svn: 269662
* Add an AST matcher for CastExpr kindEtienne Bergeron2016-05-131-0/+9
| | | | | | | | | | | | | | Summary: This AST matcher will match a given CastExpr kind. It's an narrowing matcher on CastExpr. Reviewers: klimek, alexfh, sbenza, aaron.ballman Subscribers: Prazek, jroelofs, aaron.ballman, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19871 llvm-svn: 269460
* Add an AST matcher for string-literal lengthEtienne Bergeron2016-05-121-1/+11
| | | | | | | | | | | | | | | | Summary: This patch is adding support for a matcher to check string literal length. This matcher is used in clang-tidy checkers and is part of this refactoring: see: http://reviews.llvm.org/D19841 Reviewers: sbenza, klimek, aaron.ballman Subscribers: alexfh, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19876 llvm-svn: 269274
* [ASTMatchers] New matcher forFunctionGabor Horvath2016-05-041-0/+35
| | | | | | | | | | | | Summary: Matcher proposed in the review of checker misc-assign-operator (name pending). Its goal is to find the direct enclosing function declaration of a statement and run the inner matcher on it. Two version is attached in this patch (thus it will not compile), to be decided which approach to take. The second one always chooses one single parent while the first one does a depth-first search upwards (thus a height-first search) and returns the first positive match of the inner matcher (thus it always returns zero or one matches, not more). Further questions: is it enough to implement it in-place, or ASTMatchersInternals or maybe ASTMatchFinder should be involved? Reviewers: sbenza Subscribers: aaron.ballman, klimek, o.gyorgy, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D19357 llvm-svn: 268490
* Clarify memory ownership semantics; NFC.Aaron Ballman2016-04-211-83/+87
| | | | | | Patch by Clement Courbet llvm-svn: 266986
* [ASTMatchers] Do not try to memoize nodes we can't compare.Samuel Benzaquen2016-04-191-0/+13
| | | | | | | | | | | | | | | | Summary: Prevent hasAncestor from comparing nodes that are not supported. hasDescendant was fixed some time ago to avoid this problem. I'm applying the same fix to hasAncestor: if any object in the Builder map is not comparable, skip the cache. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D19231 llvm-svn: 266748
* Add typedefNameDecl() and typeAliasDecl() to the AST matchers; improves ↵Aaron Ballman2016-04-141-1/+27
| | | | | | | | hasType() to match on TypedefNameDecl nodes. Patch by Clement Courbet. llvm-svn: 266331
* Add AST Matchers for CXXConstructorDecl::isDelegatingConstructor and ↵Alexander Kornienko2016-04-131-0/+26
| | | | | | | | | | | | | | | | CXXMethodDecl::isUserProvided. Summary: Added two AST matchers: isDelegatingConstructor for CXXConstructorDecl::IsDelegatingConstructor; and isUserProvided corresponding to CXXMethodDecl::isUserProvided. Reviewers: aaron.ballman, alexfh Subscribers: klimek, cfe-commits Patch by Michael Miller! Differential Revision: http://reviews.llvm.org/D19038 llvm-svn: 266189
* [ASTMatchers]: fix crash in hasReturnValueMatthias Gehre2016-04-121-0/+1
| | | | | | | | | | | | | | | Summary: The crash was reproduced by the included test case. It was initially found through a crash of clang-tidy's misc-misplaced-widening-cast check. Reviewers: klimek, alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D18991 llvm-svn: 266043
* [ASTMatchers] Existing matcher hasAnyArgument fixedGabor Horvath2016-03-301-1/+6
| | | | | | | | | | | | Summary: A checker (will be uploaded after this patch) needs to check implicit casts. The checker needs matcher hasAnyArgument but it ignores implicit casts and parenthesized expressions which disables checking of implicit casts for arguments in the checker. However the documentation of the matcher contains a FIXME that this should be removed once separate matchers for ignoring implicit casts and parenthesized expressions are ready. Since these matchers were already there the fix could be executed. Only one Clang checker was affected which was also fixed (ignoreParenImpCasts added) and is separately uploaded. Third party checkers (not in the Clang repository) may be affected by this fix so the fix must be emphasized in the release notes. Reviewers: klimek, sbenza, alexfh Subscribers: alexfh, klimek, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18243 llvm-svn: 264855
* [ASTMatchers] Add own version of VariadicFunction.Samuel Benzaquen2016-03-251-0/+3
| | | | | | | | | | | | | | | | Summary: llvm::VariadicFunction is only being used by ASTMatchers. Having our own copy here allows us to remove the other one from llvm/ADT. Also, we can extend the API to meet our needs without modifying the common implementation. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D18275 llvm-svn: 264417
* [ASTMatchers] New matcher hasReturnValue addedAlexander Kornienko2016-03-221-0/+6
| | | | | | | | | | | | | | Summary: A checker (will be uploaded after this patch) needs to check implicit casts. Existing generic matcher "has" ignores implicit casts and parenthesized expressions and no specific matcher for matching return value expression preexisted. The patch adds such a matcher (hasReturnValue). Reviewers: klimek, sbenza Subscribers: xazax.hun, klimek, cfe-commits Patch by Ádám Balogh! Differential Revision: http://reviews.llvm.org/D17986 llvm-svn: 264037
* Use an explicit instantiation to work around delayed template parsing for ↵Aaron Ballman2016-03-091-3/+3
| | | | | | MSVC-built bots. llvm-svn: 263041
* Adding new AST matchers for: addrLabelExpr, atomicExpr, ↵Aaron Ballman2016-03-091-1/+104
| | | | | | | | binaryConditionalOperator, designatedInitExpr, designatorCountIs, hasSyntacticForm, implicitValueInitExpr, labelDecl, opaqueValueExpr, parenListExpr, predefinedExpr, requiresZeroInitialization, and stmtExpr. Patch by Aleksei Sidorin. llvm-svn: 263027
* [ASTMatchers] Document that isAnyPointer() matcher also matches Objective-C ↵Felix Berger2016-03-061-0/+5
| | | | | | | | | | | | | | object pointers. Summary: Add test for Objective-C object pointer matching. Reviewers: aaron.ballman Subscribers: klimek Differential Revision: http://reviews.llvm.org/D17489 llvm-svn: 262806
* [ASTMatchers] Add matcher hasAnyName.Samuel Benzaquen2016-02-221-0/+13
| | | | | | | | | | | | Summary: Add matcher hasAnyName as an optimization over anyOf(hasName(),...) Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D17163 llvm-svn: 261574
* Add an AST matcher for real floating-point types. e.g., float, double, long ↵Aaron Ballman2016-02-181-0/+9
| | | | | | double, but not complex. llvm-svn: 261221
* Missing semicolons are kind of important. Who knew?Aaron Ballman2016-02-161-1/+1
| | | | llvm-svn: 261009
* Add a nullPointerConstant() AST matcher to handle variations of null pointer ↵Aaron Ballman2016-02-161-0/+10
| | | | | | constants in one matcher. llvm-svn: 261008
* Add isAnyPointer() matchers. Register missing matchers.Felix Berger2016-02-151-0/+8
| | | | | | | | | | | | | Summary: The isAnyPointer() matcher is useful for http://reviews.llvm.org/D15623. Reviewers: alexfh, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15819 llvm-svn: 260872
* Make ParentMap work with explicit specializations of function templates.Nico Weber2016-02-081-0/+7
| | | | | | | | | | | | | | | | | For an explicit specialization, we first build a FunctionDecl, and then we call SubstDecl() on it to build a second FunctionDecl, which has the first FunctionDecl as canonical decl. The address of an explicit specialization of function template used to be the canonical decl of the FunctionDecl. This is different from all the other DeduceTemplateArguments() calls in SemaOverload, and since the canonical decl isn't visited by ParentMap while the redecl is, it also made ParentMap assert when computing the parent of a address-of-explicit-specialization-fun-template. To fix, remove the getCanonicalDecl() call. No behavior difference for clang, but it fixes an assert in ParentMap (which is e.g. used by libTooling). llvm-svn: 260159
* [ASTMatchers] Allow hasName() to look through inline namespacesSamuel Benzaquen2016-02-051-0/+46
| | | | | | | | | | | | | | | | | Summary: Allow hasName() to look through inline namespaces. This will fix the interaction between some clang-tidy checks and libc++. libc++ defines names in an inline namespace named std::<version_#>. When we try to match a name using hasName("std::xxx") it fails to match and the clang-tidy check does not work. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D15506 llvm-svn: 259898
* Provide match function to look over an entire TU again.Daniel Jasper2016-02-031-1/+9
| | | | llvm-svn: 259648
* Always build a new TypeSourceInfo for function templates with parametersNico Weber2016-02-011-0/+11
| | | | | | | | | | | | | | | | | | | | | RecursiveASTVisitor::TraverseFunctionHelper() traverses a function's ParmVarDecls by going to the function's getTypeSourceInfo if it exists, and `DEF_TRAVERSE_TYPELOC(FunctionProtoType` then goes to the function's ParmVarDecls. For a function template that doesn't have parameters that explicitly depend on the template parameter, we used to be clever and not build a new TypeSourceInfo. That meant that when an instantiation of such a template is visited, its TypeSourceInfo would point to the ParmVarDecls of the template, not of the instantiation, which then confused clients of RecursiveASTVisitor. So don't be clever for function templates that have parameters, even if none of the parameters depend on the type. Fixes PR26257. http://reviews.llvm.org/D16478 llvm-svn: 259428
* Reapply r259210 with a fix for RegistryTest.cpp.Aaron Ballman2016-02-011-1/+25
| | | | | | Patch by Richard Thomson. llvm-svn: 259359
* Revert r259210 "Extend hasType narrowing matcher for TypedefDecls, add ↵Hans Wennborg2016-01-291-25/+1
| | | | | | | | functionProtoType matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes." It didn't pass check-clang. llvm-svn: 259218
* Extend hasType narrowing matcher for TypedefDecls, add functionProtoType ↵Aaron Ballman2016-01-291-1/+25
| | | | | | | | matcher for FunctionProtoType nodes, extend parameterCountIs to FunctionProtoType nodes. Patch by Richard Thomson llvm-svn: 259210
* Include RecordDecls from anonymous unions in the AST.Nico Weber2016-01-281-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For void f() { union { int i; }; } clang used to omit the RecordDecl from the anonymous union from the AST. That's because the code creating it only called PushOnScopeChains(), which adds it to the current DeclContext, which here is the function's DeclContext. But RecursiveASTVisitor doesn't descent into all decls in a FunctionDecl. Instead, for DeclContexts that contain statements, return the RecordDecl so that it can be included in the DeclStmt containing the VarDecl for the union. Interesting bits from the AST before this change: |-FunctionDecl | `-CompoundStmt | |-DeclStmt | | `-VarDecl 0x589cd60 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit After this change: -FunctionDecl | `-CompoundStmt | |-DeclStmt | | |-CXXRecordDecl 0x4612e48 <col:3, col:18> col:3 union definition | | | |-FieldDecl 0x4612f70 <col:11, col:15> col:15 referenced i 'int' | | `-VarDecl 0x4613010 <col:3> col:3 implicit used 'union (anonymous at test.cc:3:3)' callinit This is now closer to how anonymous struct and unions are represented as members of structs. It also enabled deleting some one-off code in the template instantiation code. Finally, it fixes a crash with ASTMatchers, see the included test case (this fixes http://crbug.com/580749). llvm-svn: 259079
* Add am AST matcher for isMoveAssignmentOperator.Aaron Ballman2016-01-221-0/+15
| | | | | | Patch by Jonathan Coe. llvm-svn: 258573
* Let RecursiveASTVisitor visit array index VarDeclsNico Weber2016-01-221-0/+8
| | | | | | | | | | | | An implicit copy ctor creates loop VarDecls that hang off CXXCtorInitializer. RecursiveASTVisitor used to not visit them, so that they didn't show up in the parent map used by ASTMatchers, causing asserts() when the implicit DeclRefExpr() in a CXXCtorInitializer referred to one of these VarDecls. Fixes PR26227. http://reviews.llvm.org/D16413 llvm-svn: 258503
* Add an isVirtualAsWritten AST matcher.Nico Weber2016-01-211-0/+10
| | | | | | http://reviews.llvm.org/D16394 llvm-svn: 258415
* Add AST matcher support for FunctionDecls with the hasBody matcher.Aaron Ballman2016-01-201-0/+4
| | | | | | Patch by Aleksei Sidorin. llvm-svn: 258322
* Add AST matcher for paren expressions.Aaron Ballman2016-01-201-0/+8
| | | | | | Patch by Adrian Zgorzałek. llvm-svn: 258321
* The destructor name should be matched to ~Foo instead of Foo.Aaron Ballman2016-01-181-3/+3
| | | | llvm-svn: 258077
* Add an AST matcher for checking whether a function is defaulted.Aaron Ballman2016-01-181-0/+7
| | | | | | Patch by Jonathan Coe. llvm-svn: 258072
* Augments r258042; changes the AST matcher tests to use matchesNot and ↵Aaron Ballman2016-01-181-2/+14
| | | | | | EXPECT_TRUE instead of EXPECT_FALSE. Adds a matcher test to ensure that static member functions are properly handled. Generates the documentation from the matcher. llvm-svn: 258070
* Add forEachArgumentWithParam AST matcher.Manuel Klimek2016-01-181-0/+85
| | | | | | | | | | | | The new matcher allows users to provide a matcher for both the argument of a CallExpr/CxxConstructExpr a well as the ParmVarDecl of the argument. Patch by Felix Berger. Differential Revision: http://reviews.llvm.org/D13845 llvm-svn: 258042
* [ASTMatchers] Add booleanType() matcher.Samuel Benzaquen2015-12-221-0/+7
| | | | llvm-svn: 256278
* Add a new matcher to match character types.Gabor Horvath2015-12-151-0/+8
| | | | llvm-svn: 255627
* Add a narrowing AST matcher that matches on a FunctionDecl with a ↵Aaron Ballman2015-12-021-0/+9
| | | | | | non-throwing exception specification. llvm-svn: 254516
* Traverse the NestedNameSpecifier(Loc) of NamespaceAliasDecls.Daniel Jasper2015-12-021-0/+2
| | | | | Review: http://reviews.llvm.org/D15149 llvm-svn: 254510
* Add an AST matcher for narrowing when a type is volatile-qualified.Aaron Ballman2015-11-231-0/+9
| | | | llvm-svn: 253882
* Removing the AST matcher test for thread_local storage duration. Not all ↵Aaron Ballman2015-11-181-5/+5
| | | | | | platforms support TLS, and on platforms that do not support it, use of thread_local causes an error. Since there's no way to determine whether the testing platform supports TLS, there's no way to know whether the test is safe to run or not. I will explore ways to enable this test, but this will appease at least one more build bot. llvm-svn: 253486
* Re-committing r253473 after hopefully fixing the bot breakage. There was a ↵Aaron Ballman2015-11-181-0/+23
| | | | | | copy-pasta issue that my local testing did not catch. llvm-svn: 253481
* Reverting r253473 while I investigate build bot failures.Aaron Ballman2015-11-181-23/+0
| | | | llvm-svn: 253475
* Adding AST matchers for VarDecl storage durations. Can now determine whether ↵Aaron Ballman2015-11-181-0/+23
| | | | | | a VarDecl has automatic, static, or thread storage duration. This also updates the documentation for matchers, which appear to be missing some previous additions. llvm-svn: 253473
* Make hasLHS and hasRHS matchers available for ArraySubscriptExprAlexander Kornienko2015-11-021-0/+5
| | | | | | | | | | | | | | Summary: The hasBase and hasIndex don't tell anything about the position of the base and the index in the code, so we need hasLHS and hasRHS in some cases. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14212 llvm-svn: 251842
* Add "equalsNode" for types and "isCopyAssignmentOperator" matchers.Angel Garcia Gomez2015-10-301-0/+29
| | | | | | | | | | | | Summary: This matchers are going to be used in modernize-use-default, but are generic enough to be placed in ASTMatchers.h. Reviewers: klimek Subscribers: alexfh, cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D14152 llvm-svn: 251693
* Add an AST node matcher for TemplateTypeParmDecl objects.Eric Fiselier2015-10-171-0/+7
| | | | llvm-svn: 250602
OpenPOWER on IntegriCloud