Commit Graph

434 Commits

Author SHA1 Message Date
Nathan James bf968e28ee [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher
Summary: Adds support for using the ofKind in clang-query and other dynamic matcher use cases

Reviewers: klimek, aaron.ballman, jdoerfert

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77791
2020-04-09 14:33:04 +01:00
Johannes Doerfert f9d558c871 [OpenMP] "UnFix" layering problem with FrontendOpenMP
This reverts commit 97aa593a83 as it
causes problems (PR45453) https://reviews.llvm.org/D77574#1966321.

This additionally adds an explicit reference to FrontendOpenMP to
clang-tidy where ASTMatchers is used.

This is hopefully just a temporary solution. The dependence on
`FrontendOpenMP` from `ASTMatchers` should be handled by CMake
implicitly, not us explicitly.

Reviewed By: aheejin

Differential Revision: https://reviews.llvm.org/D77666
2020-04-07 14:41:18 -05:00
Nathan James 3d1424bc7a Fixed licenses in dynamic ast matchers 2020-04-07 12:08:06 +01:00
Nathan James a473f0a36c Fix mismatch from D77112 and D77499 2020-04-06 20:19:12 +01:00
Nathan James 427c1dc4f4 [ASTMatchers] Matchers that take enumerations args provide hints with invalid arguments
Summary:
This adds support for giving hints when using dynamic matchers with enum args. Take this query, I couldn't figure out why the matcher wasn't working:
(Turns out it needed to be "IntegralToBoolean", but thats another bug itself)
```
clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean"))
1:1: Error parsing argument 1 for matcher implicitCastExpr.
1:18: Error building matcher hasCastKind.
1:30: Incorrect type for arg 1. (Expected = string) != (Actual = String)
```
With this patch the new behaviour looks like this:
```
clang-query> match implicitCastExpr(hasCastKind("CK_IntegralToBoolean"))
1:1: Error parsing argument 1 for matcher implicitCastExpr.
1:18: Error building matcher hasCastKind.
1:30: Unknown value 'CK_IntegralToBoolean' for arg 1; did you mean 'IntegralToBoolean'
```

There are no test cases for this yet as there simply isn't any infrastructure for testing errors reported when parsing args that I can see.

Reviewers: klimek, jdoerfert, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77499
2020-04-06 20:00:30 +01:00
Johannes Doerfert 97aa593a83 [OpenMP] Fix layering problem with FrontendOpenMP
Summary:
ASTMatchers is used in various places and it now exposes the
LLVMFrontendOpenMP library to its users without them needing to depend
on it explicitly.

Reviewers: lebedev.ri

Subscribers: mgorny, yaxunl, bollu, guansong, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77574
2020-04-06 13:04:26 -05:00
Johannes Doerfert 931c0cd713 [OpenMP][NFC] Move and simplify directive -> allowed clause mapping
Move the listing of allowed clauses per OpenMP directive to the new
macro file in `llvm/Frontend/OpenMP`. Also, use a single generic macro
that specifies the directive and one allowed clause explicitly instead
of a dedicated macro per directive.

We save 800 loc and boilerplate for all new directives/clauses with no
functional change. We also need to include the macro file only once and
not once per directive.

Depends on D77112.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D77113
2020-04-06 00:04:08 -05:00
Johannes Doerfert 419a559c5a [OpenMP][NFCI] Move OpenMP clause information to `lib/Frontend/OpenMP`
This is a cleanup and normalization patch that also enables reuse with
Flang later on. A follow up will clean up and move the directive ->
clauses mapping.

Reviewed By: fghanim

Differential Revision: https://reviews.llvm.org/D77112
2020-04-05 22:30:29 -05:00
Johannes Doerfert 1858f4b50d Revert "[OpenMP][NFCI] Move OpenMP clause information to `lib/Frontend/OpenMP`"
This reverts commit c18d55998b.

Bots have reported uses that need changing, e.g.,
  clang-tools-extra/clang-tidy/openmp/UseDefaultNoneCheck.cp
as reported by
  http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/46591
2020-04-02 02:23:22 -05:00
Johannes Doerfert c18d55998b [OpenMP][NFCI] Move OpenMP clause information to `lib/Frontend/OpenMP`
This is a cleanup and normalization patch that also enables reuse with
Flang later on. A follow up will clean up and move the directive ->
clauses mapping.

Differential Revision: https://reviews.llvm.org/D77112
2020-04-02 01:39:07 -05:00
Roman Lebedev d5edcb9064
[clang] Prune 'IsOMPStructuredBlock' Stmt bit
As discussed in https://reviews.llvm.org/D59214#1916596
and in some other reviews dealing with FPenv,
bits in Stmt are scarce, and i got so burnout with D59214
and https://bugs.llvm.org/show_bug.cgi?id=40563 specifically
that i never actually followed up with the usages for this bit.

So let's unhoard it, at least for now?
2020-03-12 14:48:57 +03:00
Nathan James 77eec38626 [ASTMatchers] Add hasAnyOverloadedOperatorName matcher
Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75841
2020-03-10 00:11:27 +00:00
Nathan James fc3c80c386 [ASTMatchers] adds isComparisonOperator to BinaryOperator and CXXOperatorCallExpr
Reviewers: aaron.ballman, gribozavr2

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75800
2020-03-09 00:05:10 +00:00
Yitzhak Mandelbaum c359f9537f [AST Matchers] Restrict `optionally` matcher to a single argument.
Summary:
Currently, `optionally` can take multiple arguments, which commits it to a
particular strategy for those arguments (in this case, "for each"). We limit the
matcher to a single argument, which avoids any potential confusion and
simplifies the implementation. The user can retrieve multiple-argument
optionality, by explicitly using the desired operator (like `forEach`, `anyOf`,
`allOf`, etc.) with all children wrapped in `optionally`.

Reviewers: sbenza, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75556
2020-03-05 14:48:40 -05:00
Yitzhak Mandelbaum 586f13aeac [AST Matchers] Fix bug in 'optionally' matcher wherein all previous bindings are cleared when all inner matchers fail.
Summary: The implementation of 'optionally' doesn't preserve bindings when none of the submatchers succeed. This patch adds a regression test for that behavior and fixes it.

Reviewers: aaron.ballman, sbenza

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75365
2020-02-28 13:46:27 -05:00
Nathan James 16cabf278f [ASTMatchers] HasNameMatcher handles `extern "C"`
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
2020-02-26 22:07:47 +00:00
Nathan James 6a0c066c61 [ASTMatchers] Adds a matcher called `hasAnyOperatorName`
Summary:
Acts on `BinaryOperator` and `UnaryOperator` and functions the same as `anyOf(hasOperatorName(...), hasOperatorName(...), ...)`

Documentation generation isn't perfect but I feel that the python doc script needs updating for that

Reviewers: aaron.ballman, gribozavr2

Reviewed By: aaron.ballman, gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75040
2020-02-25 07:51:20 +00:00
Nathan James 5522e8296f [NFC] Cleaned up ASTMatchersInternal Code 2020-02-25 01:47:51 +00:00
Simon Pilgrim 1723f21993 Fix MSVC "not all control paths return a value" warning. NFCI. 2020-02-21 18:23:55 +00:00
Yitzhak Mandelbaum 23444edf30 [AST matchers] Add basic matchers for googletest EXPECT/ASSERT calls.
Summary:
This revision adds matchers that match calls to the gtest EXPECT and ASSERT
macros almost like function calls. The matchers are placed in separate files
(GtestMatchers...), because they are specific to the gtest library.

Reviewers: gribozavr2

Subscribers: mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74840
2020-02-21 12:05:15 -05:00
Reid Kleckner cd62511496 Remove clang::ast_type_traits namespace in favor of clang
DynTypedNode and ASTNodeKind are implemented as part of the clang AST
library, which uses the main clang namespace. There doesn't seem to be a
need for this extra level of namespacing.

I left behind aliases in the ast_type_traits namespace for out of tree
clients of these APIs. To provide aliases for the enumerators, I used
this pattern:
  namespace ast_type_traits {
  constexpr TraversalKind TK_AsIs = ::clang::TK_AsIs;
  }
I think the typedefs will be useful for migration, but we might be able
to drop these enumerator aliases.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D74499
2020-02-13 10:46:47 -08:00
Yitzhak Mandelbaum e5ff92e049 [clang][NFC] Expand some `auto`s and add another test for matcher `isExpandedFromMacro`.
Summary: Spells out some `auto`s explicitly and adds another test for the matcher `isExpandedFromMacro`.

Reviewers: aaron.ballman

Subscribers: gribozavr, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73975
2020-02-04 13:05:58 -05:00
Stephen Neuendorffer fce1eefb46 [clang] fix lib/ASTMatchers for BUILD_SHARED_LIBS=ON 2020-02-04 09:54:28 -08:00
Yitzhak Mandelbaum 386fd2c170 [clang] Add matcher to identify macro expansions.
Summary:
This revision adds a matcher `isExpandedFromMacro` that determines whether a
statement is (transitively) expanded from a given macro.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73965
2020-02-04 11:43:06 -05:00
Haojian Wu 0ce57731da [clang] Add a missing change of bdbdf74822, fix the buildbot. 2020-02-03 13:43:26 +01:00
Haojian Wu bdbdf74822 [clang][AST] Add an AST matcher for deducedTemplateSpeializationType.
Summary:
misc-unused-using clang-tidy check needs this matcher to fix a false
positive of C++17 deduced class template types.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73869
2020-02-03 12:11:44 +01:00
Nathan James a156a0e28d [ASTMatchers] Add hasPlacementArg and hasAnyPlacementArg traversal matcher for CXXNewExpr
Summary: Adds new traversal matchers called `hasPlacementArg` and `hasAnyPlacementArg` that matches on arguments to `placement new` operators.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: merge_guards_bot, mehdi_amini, hiraditya, steven_wu, dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73562
2020-01-30 10:16:04 +00:00
Karasev Nikita d5dfd1350e Add TagDecl AST matcher 2020-01-29 07:58:31 -05:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Nathan aec6210367 [ASTMatchers] Add cxxNoexceptExpr AST matcher
Summary: Adds a cxxNoexceptExpr matcher that matches the [[ https://en.cppreference.com/w/cpp/language/noexcept |  noexcept operator ]].

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: merge_guards_bot, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73439
2020-01-28 13:12:28 +00:00
Reid Kleckner 8a81daaa8b [AST] Split parent map traversal logic into ParentMapContext.h
The only part of ASTContext.h that requires most AST types to be
complete is the parent map. Nothing in Clang proper uses the ParentMap,
so split it out into its own class. Make ASTContext own the
ParentMapContext so there is still a one-to-one relationship.

After this change, 562 fewer files depend on ASTTypeTraits.h, and 66
fewer depend on TypeLoc.h:
  $ diff -u deps-before.txt deps-after.txt | \
    grep '^[-+] ' | sort | uniq -c | sort -nr | less
      562 -    ../clang/include/clang/AST/ASTTypeTraits.h
      340 +    ../clang/include/clang/AST/ParentMapContext.h
       66 -    ../clang/include/clang/AST/TypeLocNodes.def
       66 -    ../clang/include/clang/AST/TypeLoc.h
       15 -    ../clang/include/clang/AST/TemplateBase.h
  ...
I computed deps-before.txt and deps-after.txt with `ninja -t deps`.

This removes a common and key dependency on TemplateBase.h and
TypeLoc.h.

This also has the effect of breaking the ParentMap RecursiveASTVisitor
instantiation into its own file, which roughly halves the compilation
time of ASTContext.cpp (29.75s -> 17.66s). The new file takes 13.8s to
compile.

I left behind forwarding methods for getParents(), but clients will need
to include a new header to make them work:
  #include "clang/AST/ParentMapContext.h"

I noticed that this parent map functionality is unfortunately duplicated
in ParentMap.h, which only works for Stmt nodes.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D71313
2020-01-24 13:42:28 -08:00
Stephen Kelly 8248190a73 Fix clang-formatting for recent commits 2020-01-20 11:38:23 +00:00
Stephen Kelly 122443a950 Compare traversal for memoization before bound nodes container 2020-01-20 11:20:04 +00:00
Jonas Toth 23a799adf0 Revert "[ASTMatchers] extract public matchers from const-analysis into own patch"
This reverts commit 4c48ea68e4.
The powerpc buildbots had an internal compiler error after this patch.
This requires some inspection.
2020-01-11 19:41:27 +01:00
Jonas Toth 4c48ea68e4 [ASTMatchers] extract public matchers from const-analysis into own patch
Summary:
The analysis for const-ness of local variables required a view generally useful
matchers that are extracted into its own patch.

They are `decompositionDecl` and `forEachArgumentWithParamType`, that works
for calls through function pointers as well.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72505
2020-01-11 19:21:03 +01:00
Reid 4ffcec40ac Implement new AST matcher hasAnyCapture to match on LambdaExpr captures.
Accepts child matchers cxxThisExpr to match on capture of this and also on varDecl.
2020-01-10 15:49:43 -05:00
Rihan Yang 2823e91d55 Add a new AST matcher 'optionally'.
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.
2020-01-08 14:10:11 -05:00
Aaron Ballman 7a77ad1446 Fixing a formatting nit; NFC 2020-01-08 08:53:04 -05:00
Stephen Kelly ad0a45833b Allow using traverse() with bindings 2020-01-05 20:48:56 +00:00
Nathan James ec3d8e61b5 Handle init statements in readability-else-after-return
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.
2020-01-02 13:39:27 -05:00
Stephen Kelly d89c4cb938 Match code following lambdas when ignoring invisible nodes
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71976
2019-12-31 17:04:39 +00:00
Stephen Kelly f7d9584c56 Fix formatting in previous commits 2019-12-29 19:41:30 +00:00
Stephen Kelly bee973f4df Fix use of named values surrounded by newlines in clang-query 2019-12-29 14:58:56 +00:00
Stephen Kelly dc93540acb Fix handling of newlines in clang-query
Replace assert with diagnostic for missing newline.
2019-12-29 14:58:56 +00:00
Stephen Kelly f0722333dd Allow newlines in AST Matchers in clang-query files
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71842
2019-12-27 15:25:57 +00:00
Evgenii Stepanov 5ca97d0def Revert "Allow newlines in AST Matchers in clang-query files" + 1
Revert "Fix -Wunused-lambda-capture warnings."
This reverts commit 2369560f4a.
This reverts commit 522ee29a4f.

clang/lib/ASTMatchers/Dynamic/Parser.cpp:610:13: warning: implicit conversion turns string literal into bool: 'const char [35]' to 'bool' [-Wstring-conversion]
    assert(!"Newline should never be found here");
2019-12-26 18:07:20 -08:00
Eric Christopher 2369560f4a Fix -Wunused-lambda-capture warnings. 2019-12-26 15:27:21 -08:00
Stephen Kelly 522ee29a4f Allow newlines in AST Matchers in clang-query files
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71842
2019-12-26 20:40:33 +00:00
Stephen Kelly 831b636861 Revert "Allow newlines in AST Matchers in clang-query files"
This reverts commit 6a3ecf4dc7.
2019-12-26 20:16:23 +00:00
Stephen Kelly 6a3ecf4dc7 Allow newlines in AST Matchers in clang-query files
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71842
2019-12-26 20:00:59 +00:00
Stephen Kelly 5a79cfa32d Customize simplified dumping and matching of LambdaExpr
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71680
2019-12-21 11:02:11 +00:00
Stephen Kelly 0378f3a903 Revert "Customize simplified dumping and matching of LambdaExpr"
This reverts commit 494b1318ca.
2019-12-20 21:33:31 +00:00
Stephen Kelly 494b1318ca Customize simplified dumping and matching of LambdaExpr
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71680
2019-12-20 21:13:23 +00:00
Stephen Kelly 0a717d5b5d Make it possible control matcher traversal kind with ASTContext
Summary:
This will eventually allow traversal of an AST while ignoring invisible
AST nodes.  Currently it depends on the available enum values for
TraversalKinds.  That can be extended to ignore all invisible nodes in
the future.

Reviewers: klimek, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61837
2019-12-06 23:11:32 +00:00
George Burgess IV 380a6452b2 [ASTMatchers] work around a miscompile; "NFC"
I chatted with Reid offline, and we agreed that having a workaround here
would be appropriate until PR43879 is resolved.

The given transformation Works On My Machine(TM), and should hopefully
hold more broadly, but my fingers are crossed nonetheless. :)
2019-11-22 20:11:16 -08:00
Jonas Devlieghere 2b3d49b610 [Clang] Migrate llvm::make_unique to std::make_unique
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
2019-08-14 23:04:18 +00:00
Stephane Moore a0a47d8ac1 [clang] Update isDerivedFrom to support Objective-C classes 🔍
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
2019-08-12 23:23:35 +00:00
Anton Bikineev 4e1d188be2 [clang] Add isDirectlyDerivedFrom AST matcher.
Differential Revision: https://reviews.llvm.org/D65092

llvm-svn: 367010
2019-07-25 11:54:13 +00:00
Gauthier Harnisch e10a881c2b Revert "[clang] Fixing windows buildbot after D61552"
This reverts commit 5d5d2ca69e.

has already been fixed by c230eea2f3

llvm-svn: 363920
2019-06-20 10:34:02 +00:00
Gauthier Harnisch 5d5d2ca69e [clang] Fixing windows buildbot after D61552
Summary:
original review : https://reviews.llvm.org/D61552

build bot faillure : http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/110

this adds a missing definition of cxxDeductionGuideDecl.
surprisingly it was still working on linux with out it.

Reviewers: aaron.ballman

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

llvm-svn: 363919
2019-06-20 10:27:14 +00:00
Kadir Cetinkaya c230eea2f3 [clang][ASTMatchers] Add definition for cxxDeductionGuideDecl introduced in rL363855
llvm-svn: 363917
2019-06-20 10:13:58 +00:00
Gauthier Harnisch e1f4ba85e5 [clang] Adapt ASTMatcher to explicit(bool) specifier
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
2019-06-19 18:27:56 +00:00
Dmitri Gribenko 31d68804fd Added AST matcher for ignoring elidable constructors
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
2019-06-13 13:48:24 +00:00
Stephen Kelly d147cea3b9 Move TraversalKind enum to ast_type_traits
Summary:
Make it usable outside of ASTMatchFinder.  This will make it possible to
use this enum to control whether certain implicit nodes are skipped
while AST dumping for example.

Reviewers: klimek, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360920
2019-05-16 17:57:38 +00:00
Dmitri Gribenko b641b914a3 Added an AST matcher for declarations that are in the `std` namespace
Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 359876
2019-05-03 12:50:00 +00:00
Ben Hamilton a282bde69e [ASTMatchers] Introduce Objective-C matchers `isClassMessage`, `isClassMethod`, and `isInstanceMethod`
Summary:
isClassMessage is an equivalent to isInstanceMessage for ObjCMessageExpr, but matches message expressions to classes.

isClassMethod and isInstanceMethod check whether a method declaration (or definition) is for a class method or instance method (respectively).

Contributed by @mywman!

Reviewers: benhamilton, klimek, mwyman

Reviewed By: benhamilton, mwyman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 358904
2019-04-22 17:54:11 +00:00
Roman Lebedev c816195759 [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers
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
2019-03-21 15:33:35 +00:00
Roman Lebedev 33ef20ec2f [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling
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
2019-03-21 15:33:24 +00:00
Roman Lebedev de0e4ae024 [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.
Summary:
A simple matcher for `OMPExecutableDirective` Stmt type.
Split off from D57113.

Reviewers: gribozavr, aaron.ballman, JonasToth, george.karpenkov

Reviewed By: gribozavr, aaron.ballman

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 356674
2019-03-21 15:33:10 +00:00
Roman Lebedev 8e0b2fb9fa [NFC][ASTMatchers] Alphabetically sort REGISTER_MATCHER() macros in RegistryMaps::RegistryMaps()
As noted in https://reviews.llvm.org/D59453#inline-526253

llvm-svn: 356578
2019-03-20 17:15:47 +00:00
Tom Roeder 521f004e99 [ASTImporter] Add support for importing ChooseExpr AST nodes.
Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

The node is already supported in the AST, but it didn't have a matcher
in ASTMatchers. So, this change adds the matcher and adds support to
ASTImporter.

This was originally reviewed and approved in
https://reviews.llvm.org/D58292 and submitted as r354832. It was
reverted in r354839 due to failures on the Windows CI builds.

This version fixes the test failures on Windows, which were caused by
differences in template expansion between versions of clang on different
OSes. The version of clang built with MSVC and running on Windows never
expands the template in the C++ test in ImportExpr.ImportChooseExpr in
clang/unittests/AST/ASTImporter.cpp, but the version on Linux does for
the empty arguments and -fms-compatibility.

So, this version of the patch drops the C++ test for
__builtin_choose_expr, since that version was written to catch
regressions of the logic for isConditionTrue() in the AST import code
for ChooseExpr, and those regressions are also caught by
ASTImporterOptionSpecificTestBase.ImportChooseExpr, which does work on
Windows.

Reviewers: shafik, a_sidorin, martong, aaron.ballman, rnk, a.sidorin

Subscribers: cfe-commits, jdoerfert, rnkovacs, aaron.ballman

Tags: #clang

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

llvm-svn: 354916
2019-02-26 19:26:41 +00:00
Reid Kleckner 1144084cb2 Revert r354832 "[ASTImporter] Add support for importing ChooseExpr AST nodes."
Test does not pass on Windows

llvm-svn: 354839
2019-02-26 02:22:22 +00:00
Tom Roeder 9a72870122 [ASTImporter] Add support for importing ChooseExpr AST nodes.
Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

The node is already supported in the AST, but it didn't have a matcher
in ASTMatchers. So, this change adds the matcher and adds support to
ASTImporter.

Reviewers: shafik, a_sidorin, martong, aaron.ballman

Subscribers: aaron.ballman, rnkovacs, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 354832
2019-02-25 23:24:58 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
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
2019-01-19 08:50:56 +00:00
Sam McCall e72804066c [ASTMatchers] Improve assert message for broken parent map.
Summary:
This assert catches places where the AST (as seen by RecursiveASTVisitor)
becomes disconnected due to incomplete traversal.
Making it print the actual parent-less node is a lot more helpful - it's
possible to work out which part of the tree wasn't traversed.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 350612
2019-01-08 07:29:46 +00:00
Hyrum Wright 2cd40c0170 [clang] Add AST matcher for initializer list members
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
2019-01-07 14:14:36 +00:00
Gabor Marton 7df342a4d1 [ASTImporter] Fix redecl chain of classes and class templates
Summary:
The crux of the issue that is being fixed is that lookup could not find
previous decls of a friend class. The solution involves making the
friend declarations visible in their decl context (i.e. adding them to
the lookup table).
Also, we simplify `VisitRecordDecl` greatly.

This fix involves two other repairs (without these the unittests fail):
(1) We could not handle the addition of injected class types properly
when a redecl chain was involved, now this is fixed.
(2) DeclContext::removeDecl failed if the lookup table in Vector form
did not contain the to be removed element. This caused troubles in
ASTImporter::ImportDeclContext. This is also fixed.

Reviewers: a_sidorin, balazske, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

llvm-svn: 349349
2018-12-17 12:42:12 +00:00
Stephane Moore 3897b2dca1 [clang] Add AST matcher for block expressions 🔍
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
2018-12-13 03:35:10 +00:00
Eric Fiselier 5cdc2cda28 [AST] Store "UsesADL" information in CallExpr.
Summary:
Currently the Clang AST doesn't store information about how the callee of a CallExpr was found. Specifically if it was found using ADL.

However, this information is invaluable to tooling. Consider a tool which renames usages of a function. If the originally CallExpr was formed using ADL, then the tooling may need to additionally qualify the replacement.
Without information about how the callee was found, the tooling is left scratching it's head. Additionally, we want to be able to match ADL calls as quickly as possible, which means avoiding computing the answer on the fly.

This patch changes `CallExpr` to store whether it's callee was found using ADL. It does not change the size of any AST nodes.


Reviewers: fowles, rsmith, klimek, shafik

Reviewed By: rsmith

Subscribers: aaron.ballman, riccibruno, calabrese, titus, cfe-commits

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

llvm-svn: 348977
2018-12-12 21:50:55 +00:00
Clement Courbet a6144db15f Revert rL347462 "[ASTMatchers] Add hasSideEffect() matcher."
Breaks some buildbots.

llvm-svn: 347463
2018-11-22 14:26:33 +00:00
Clement Courbet c022c51f89 [ASTMatchers] Add hasSideEffect() matcher.
Summary: Exposes Expr::HasSideEffects.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 347462
2018-11-22 14:00:56 +00:00
Erich Keane a6e4a3987c Fix parens warning in assert in ASTMatchFinder
Change-Id: Ie34f9c6846b98fba87449e73299519fc2346bac1
llvm-svn: 346996
2018-11-15 21:35:35 +00:00
Sam McCall 814e7974c6 [AST] Allow limiting the scope of common AST traversals (getParents, RAV).
Summary:
The goal is to allow analyses such as clang-tidy checks to run on a
subset of the AST, e.g. "only on main-file decls" for interactive tools.

Today, these become "problematically global" by running RecursiveASTVisitors
rooted at the TUDecl, or by navigating up via ASTContext::getParent().

The scope is restricted using a set of top-level-decls that RecursiveASTVisitors
should be rooted at. This also applies to the visitor that populates the
parent map, and so the top-level-decls are considered to have no parents.

This patch makes the traversal scope a mutable property of ASTContext.
The more obvious way to do this is to pass the top-level decls to
relevant functions directly, but this has some problems:
 - it's error-prone: accidentally mixing restricted and unrestricted
   scopes is a performance trap. Interleaving multiple analyses is
   common (many clang-tidy checks run matchers or RAVs from matcher callbacks)
 - it doesn't map well to the actual use cases, where we really do want
   *all* traversals to be restricted.
 - it involves a lot of plumbing in parts of the code that don't care
   about traversals.
This approach was tried out in D54259 and D54261, I wanted to like it
but it feels pretty awful in practice.

Caveats: to get scope-limiting behavior of RecursiveASTVisitors, callers
have to call the new TraverseAST(Ctx) function instead of TraverseDecl(TU).
I think this is an improvement to the API regardless.

Reviewers: klimek, ioeric

Subscribers: mgorny, cfe-commits

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

llvm-svn: 346847
2018-11-14 10:33:30 +00:00
Jonas Toth 295aa09dd2 [ASTMatchers] overload ignoringParens for Expr
Summary: This patch allows fixing PR39583.

Reviewers: aaron.ballman, sbenza, klimek

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 346554
2018-11-09 20:54:06 +00:00
Bill Wendling 8003edc9aa Compound literals, enums, et al require const expr
Summary:
Compound literals,  enums, file-scoped arrays, etc. require their
initializers and size specifiers to be constant. Wrap the initializer
expressions in a ConstantExpr so that we can easily check for this later
on.

Reviewers: rsmith, shafik

Reviewed By: rsmith

Subscribers: cfe-commits, jyknight, nickdesaulniers

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

llvm-svn: 346455
2018-11-09 00:41:36 +00:00
Aaron Ballman 31f48c50cd Add the isStaticLocal() AST matcher for matching on local static variables.
Patch by Joe Ranieri.

llvm-svn: 345502
2018-10-29 13:47:56 +00:00
Fangrui Song 3117b17bc5 Use llvm::{all,any,none}_of instead std::{all,any,none}_of. NFC
llvm-svn: 344859
2018-10-20 17:53:42 +00:00
Stephen Kelly ccc0c6d3e6 [ASTMatcher] Add missing imaginaryLiteral
llvm-svn: 344026
2018-10-09 08:44:28 +00:00
Stephen Kelly 5834d52d1c Add matchers missing from dynamic AST registry
llvm-svn: 343717
2018-10-03 20:52:51 +00:00
Stephen Kelly 5da85abfa1 Sort list of matchers
llvm-svn: 343716
2018-10-03 20:52:45 +00:00
Stephen Kelly 7c787b8adf Allow comments with '#' in dynamic AST Matchers
Summary: This is necessary for clang-query to be able to handle comments.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 343665
2018-10-03 07:56:43 +00:00
Fangrui Song 1d38c13f6e Use the container form llvm::sort(C, ...)
There are a few leftovers of rC343147 that are not (\w+)\.begin but in
the form of ([-[:alnum:]>.]+)\.begin or spanning two lines. Change them
to use the container form in this commit. The 12 occurrences have been
inspected manually for safety.

llvm-svn: 343425
2018-09-30 21:41:11 +00:00
Jonas Toth 2253878a40 [ASTMatchers] add three matchers for dependent expressions
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
2018-09-11 16:09:19 +00:00
Stephen Kelly fc934cd916 Allow binding to NamedValue resulting from let expression
Subscribers: cfe-commits

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

llvm-svn: 341142
2018-08-30 23:11:09 +00:00
Stephen Kelly 5fb9dc51dc Extract parseBindID method
Subscribers: cfe-commits

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

llvm-svn: 341141
2018-08-30 23:11:01 +00:00
Gabor Marton 42e15deb6c Fix import of class templates partial specialization
Summary:
Currently there are several issues with the import of class template
specializations.  (1) Different TUs may have class template specializations
with the same template arguments, but with different set of instantiated
MethodDecls and FieldDecls.  In this patch we provide a fix to merge these
methods and fields.  (2) Currently, we search the partial template
specializations in the set of simple specializations and we add partial
specializations as simple specializations. This is bad, this patch fixes it.

Reviewers: a_sidorin, xazax.hun, r.stahl

Subscribers: rnkovacs, dkrupp, cfe-commits

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

llvm-svn: 340402
2018-08-22 11:52:14 +00:00
Shuai Wang 72b56ed6b4 [ASTMatchers] Add matchers unresolvedMemberExpr, cxxDependentScopeMemberExpr
Subscribers: cfe-commits

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

llvm-svn: 339522
2018-08-12 17:34:36 +00:00
Gabor Marton bf7f18b79c Add support for importing imaginary literals
Reviewers: a_sidorin, r.stahl, xazax.hun

Subscribers: rnkovacs, dkrupp, cfe-commits

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

llvm-svn: 339334
2018-08-09 12:18:07 +00:00
George Karpenkov 079275b4dc [ASTMatchers] Introduce a matcher for `ObjCIvarExpr`, support getting it's 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
2018-07-27 17:26:11 +00:00
George Karpenkov fc3d72eeea [ASTMatchers] Add an isMain() matcher
Differential Revision: https://reviews.llvm.org/D49615

llvm-svn: 337761
2018-07-23 22:29:35 +00:00