Commit Graph

466 Commits

Author SHA1 Message Date
Oliver Stannard 6c203149b6 [clang] Remove raw string literals in macros
Older (but still supported) versions of GCC don't handle C++11 raw
string literals in macro parameters correctly.
2020-01-13 12:38:58 +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
Stephen Kelly 55d7b22277 [ASTMatchers] Make test more clear about what it is verifying 2020-01-10 19:47:12 +00: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
Stephen Kelly 445f4d2310 Clang-format previous commit 2020-01-05 22:58:32 +00:00
Stephen Kelly 35efef5351 Add missing test 2020-01-05 21:55:52 +00:00
Stephen Kelly ad0a45833b Allow using traverse() with bindings 2020-01-05 20:48:56 +00:00
David Green 170de3de2e [ParserTest] Move raw string literal out of macro
Some combinations of gcc and ccache do not deal well with raw strings in
macros. Moving the string out to attempt to fix the bots.
2020-01-05 11:24:04 +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 69bb99914f Implement additional traverse() overloads
Summary:
These overloads make it possible to wrap unless(), anyOf(), has() etc
with the traverse matcher.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71977
2019-12-31 17:04:40 +00: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 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
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 98e8f774eb Add method to ignore invisible AST nodes
Reviewers: aaron.ballman

Subscribers: mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70613
2019-12-18 22:33:23 +00:00
Stephen Kelly 2e8dc8590d Add matchDynamic convenience functions
Summary: These correspond to the existing match() free functions.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D54406
2019-12-07 00:01:29 +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
Aaron Ballman 518b2266f5 Fix the nullPointerConstant() test to get bots back to green.
llvm-svn: 369686
2019-08-22 18:56:18 +00: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
Yitzhak Mandelbaum a3c3530958 [clang][NFC] Move matcher ignoringElidableConstructorCall's tests to 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
2019-08-08 18:55:42 +00:00
Yitzhak Mandelbaum 57f471f4ff [clang] Update `ignoringElidableConstructorCall` matcher to ignore `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
2019-08-08 17:41:44 +00:00
Anton Bikineev 207726c882 [clang] Remove IsDerivedFromDeathTest.DiesOnEmptyBaseName test.
The semantics of an empty basename passed to isDerivedFrom matchers
changed in r367022, so this test is no longer relevant.

llvm-svn: 367026
2019-07-25 15:09:37 +00:00
Anton Bikineev 0ef3f27458 [clang] Fail for empty names in is*DerivedFrom matchers.
Differential Revision: https://reviews.llvm.org/D65279

llvm-svn: 367022
2019-07-25 14:48:55 +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
Tom Stellard 2e97d2aa1b cmake: Add CLANG_LINK_CLANG_DYLIB option
Summary:
Setting CLANG_LINK_CLANG_DYLIB=ON causes clang tools to link against
libclang_shared.so instead of the individual component libraries.

Reviewers: mgorny, beanz, smeenai, phosek, sylvestre.ledru

Subscribers: arphaman, cfe-commits, llvm-commits

Tags: #clang

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

llvm-svn: 365092
2019-07-03 22:45:55 +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
Jordan Rupprecht f960351ac4 [clang][OpenMP] Fix another test when using libgomp.
Similarly to r356614, -fopenmp=libomp needs to be used for some omp-related AST matching.

llvm-svn: 356700
2019-03-21 19:13:22 +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
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
David Green 87992de487 Move multiline raw string literal out of macro. NFC
Certain combinations of gcc and ccache fail when the raw
string literal is preprocessed. This just moves the string
out as is done elsewhere in the same file.

llvm-svn: 354201
2019-02-16 11:19:04 +00:00
Yitzhak Mandelbaum 5dfddff242 Exteded test of .
llvm-svn: 354136
2019-02-15 14:43:10 +00:00
Yitzhak Mandelbaum c11f074323 Remove unnecessary expectation.
llvm-svn: 354135
2019-02-15 14:43:08 +00:00
Yitzhak Mandelbaum e1f0a0e759 Added test for matcher On.
llvm-svn: 354134
2019-02-15 14:43:06 +00:00
Yitzhak Mandelbaum 1a8b6ff528 Add tests for assorted `CXXMemberCallExpr` matchers.
Summary: Add tests for matchers `on`, `onImplicitObjectArgument` and `hasObjectExpression`.

Reviewers: alexfh, steveire, aaron.ballman

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

llvm-svn: 354133
2019-02-15 14:43:03 +00:00