Commit Graph

3472 Commits

Author SHA1 Message Date
Francois Ferrand c5227a1f53 [clang-format] Allow configuring list of function-like macros that resolve to a type
Summary:
Adds a `TypenameMacros` configuration option that causes certain identifiers to be handled in a way similar to `typeof()`.

This is enough to:
- Prevent misinterpreting declarations of pointers to such types as expressions (`STACK_OF(int) * foo` -> `STACK_OF(int) *foo`),
- Avoid surprising line breaks in variable/struct field declarations (`STACK_OF(int)\nfoo;` -> `STACK_OF(int) foo;`, see https://bugs.llvm.org/show_bug.cgi?id=30353).

Reviewers: Typz, krasimir, djasper

Reviewed By: Typz

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361986
2019-05-29 16:30:47 +00:00
Francois Ferrand 0a729261e2 [NFC] clang-format: Use LLVM style in NamespaceEndCommentsFixerTest
As pointed out in https://reviews.llvm.org/D37813#inline-555026, the
code which is formatted does not match LLVM formatting style.

Technically this is not a problem since these tests bypass most of the
formatter, but it can be misleading.

llvm-svn: 361984
2019-05-29 16:22:43 +00:00
Yitzhak Mandelbaum e1312c54d3 [LibTooling] Add `before` and `after` selectors for selecting point-ranges relative to nodes.
Summary:
The `before` and `after` selectors allow users to specify a zero-length range --
a point -- at the relevant location in an AST-node's source.  Point ranges can
be useful, for example, to insert a change using an API that takes a range to be
modified (e.g. `tooling::change()`).

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361955
2019-05-29 12:40:36 +00:00
Ilya Biryukov b1296faee0 [CodeComplete] Set preferred type for qualified-id
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361838
2019-05-28 15:21:03 +00:00
Kadir Cetinkaya 20c3c4fe5a [clang] Respect TerseOutput when printing lambdas
Reviewers: ilya-biryukov, hokein, sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361771
2019-05-27 16:20:45 +00:00
Balazs Keri c8272195cd [ASTImporter] Added visibility context check for CXXRecordDecl.
Summary:
ASTImporter makes now difference between classes with same name in different
translation units if these are not visible outside. These classes are not linked
into one decl chain.

Reviewers: martong, a.sidorin, shafik

Reviewed By: shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 361752
2019-05-27 09:36:00 +00:00
Duncan P. N. Exon Smith d4a9cae965 Add missing newline at end of file
llvm-svn: 361708
2019-05-25 22:38:02 +00:00
Nico Weber bab1d8edcf Rename clangToolingRefactor to clangToolingRefactoring for consistency with its directory
See "[cfe-dev] The name of clang/lib/Tooling/Refactoring".

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

llvm-svn: 361684
2019-05-25 00:27:19 +00:00
Yitzhak Mandelbaum fab7205ac4 [LibTooling] Add Explanation parameter to `makeRule`.
Summary:
Conceptually, a single-case RewriteRule has a matcher, edit(s) and an (optional)
explanation. `makeRule` previously only took the matcher and edit(s). This
change adds (optional) support for the explanation.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361643
2019-05-24 15:11:45 +00:00
Thomas Lively a8e0d49c0c Fix unresolved symbols when linking tools/clang/unittests/Tooling/ToolingTests
Summary: Add correct cmake dependencies so that `ToolingTests` link
successfully.

Patch by Guanzhong Chen

Reviewers: tlively, aheejin

Reviewed By: tlively

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361536
2019-05-23 18:55:00 +00:00
Yitzhak Mandelbaum 1f46d524a1 [LibTooling] Update Stencil to use RangeSelector
Add support for creating a `StencilPart` from any `RangeSelector`, which
broadens the scope of `Stencil`.

Correspondingly, deprecate Stencil's specialized combinators `node` and `sNode`
in favor of using the new `selection` combinator directly (with the appropriate
range selector).

Reviewers: sbenza

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361413
2019-05-22 18:03:00 +00:00
Yitzhak Mandelbaum 3ec50e292f [LibTooling] Update Transformer to use RangeSelector instead of NodePart enum.
Transformer provides an enum to indicate the range of source text to be edited.
That support is now redundant with the new (and more general) RangeSelector
library, so we remove the custom enum support in favor of supporting any
RangeSelector.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361392
2019-05-22 14:48:19 +00:00
Ilya Biryukov e7230ea7c9 Reland r361148 with a fix to the buildbot failure.
Reverted in r361377.
Also reland the '.gn' files (reverted in r361389).

llvm-svn: 361391
2019-05-22 14:44:45 +00:00
Russell Gallop fd22d7f861 Revert r361148 "[Syntax] Introduce TokenBuffer, start clangToolingSyntax library"
Also reverted r361264 "[Syntax] Rename TokensTest to SyntaxTests. NFC"
which built on it. This is because there were hitting an assert on bots

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast

llvm-svn: 361377
2019-05-22 12:50:52 +00:00
Yitzhak Mandelbaum f0d9cfa591 [LibTooling] Address post-commit feedback for r361152
Fixes a redundant dependency and moves another to its proper place.

Reviewers: thakis

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361285
2019-05-21 18:48:58 +00:00
Ilya Biryukov 6c0531222a [Syntax] Rename TokensTest to SyntaxTests. NFC
To be more consistent with conventions used in the codebase. The new
name will be a better fit when more bits of the syntax library land.

llvm-svn: 361264
2019-05-21 14:37:41 +00:00
Nikolai Kosjar 295c19e948 [Preamble] Reuse preamble even if an unsaved file does not exist
When a preamble is created an unsaved file not existing on disk is
already part of PrecompiledPreamble::FilesInPreamble. However, when
checking whether the preamble can be re-used, a failed stat of such an
unsaved file invalidated the preamble, which led to pointless and time
consuming preamble regenerations on subsequent reparses.

Do not require anymore that unsaved files should exist on disk.

This avoids costly preamble invalidations depending on timing issues for
the cases where the file on disk might be removed just to be regenerated
a bit later.

It also allows an IDE to provide in-memory files that might not exist on
disk, e.g. because the build system hasn't generated those yet.

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

llvm-svn: 361226
2019-05-21 07:26:59 +00:00
Nico Weber 4522e26696 Try to fix build with older gccs after r361152
Also merge the cmake change there to the gn build.

llvm-svn: 361209
2019-05-21 00:27:26 +00:00
Dmitri Gribenko 76e3a04951 Renamed `apply` to `select` to avoid ADL conflict with `std::apply`
Summary:
`std::apply` in C++14 and above is defined with two unrestricted arguments, and
it wins overload resolution in this case.

Reviewers: ilya-biryukov

Subscribers: cfe-commits, ymandel

Tags: #clang

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

llvm-svn: 361170
2019-05-20 16:30:49 +00:00
Yitzhak Mandelbaum ef29c6a63e [LibTooling] Fix build break in test after r361152.
r361152 broke gcc builds.

llvm-svn: 361160
2019-05-20 14:44:40 +00:00
Yitzhak Mandelbaum 27872b8d55 [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.
Summary:

The RangeSelector library defines a combinator language for specifying source
ranges based on bound ids for AST nodes.  The combinator approach follows the
design of the AST matchers.  The RangeSelectors defined here will be used in
both RewriteRule, for specifying source affected by edit, and in Stencil for
specifying source to use constructively in a replacement.

Reviewers: ilya-biryukov

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361152
2019-05-20 13:15:14 +00:00
Ilya Biryukov ddd5d5dbc8 [Syntax] Introduce TokenBuffer, start clangToolingSyntax library
Summary:
TokenBuffer stores the list of tokens for a file obtained after
preprocessing. This is a base building block for syntax trees,
see [1] for the full proposal on syntax trees.

This commits also starts a new sub-library of ClangTooling, which
would be the home for the syntax trees and syntax-tree-based refactoring
utilities.

[1]: https://lists.llvm.org/pipermail/cfe-dev/2019-February/061414.html

Reviewers: gribozavr, sammccall

Reviewed By: sammccall

Subscribers: mgrang, riccibruno, Eugene.Zelenko, mgorny, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 361148
2019-05-20 13:00:42 +00:00
Gabor Marton 1d51e3e6ee [ASTImporter] Enable disabled but passing tests
Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 361139
2019-05-20 10:38:14 +00:00
Stephen Kelly ad3314b146 Add a Visit overload for DynTypedNode to ASTNodeTraverser
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361117
2019-05-19 13:03:48 +00:00
Nico Weber e78ac9cc72 Revert r361033 "Add a Visit overload for DynTypedNode to ASTNodeTraverser"
It fails to build on some bots.

Also revert follow-up r361055.

llvm-svn: 361059
2019-05-17 18:31:24 +00:00
Kristof Umann 83cc1b35d1 [analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.

By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.

This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!

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

llvm-svn: 361042
2019-05-17 15:52:13 +00:00
Yitzhak Mandelbaum 8369a9beb7 [LibTooling] Add support to Transformer for composing rules as an ordered choice.
This revision updates `RewriteRule` to support multiple subrules that are
interpreted as an ordered-choice (apply the first one that matches). With this
feature, users can write the rules that appear later in the list of subrules
knowing that previous rules' patterns *have not matched*, freeing them from
reasoning about those cases in the current pattern.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361037
2019-05-17 14:23:33 +00:00
Stephen Kelly 0855896c68 Add a Visit overload for DynTypedNode to ASTNodeTraverser
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361033
2019-05-17 13:55:28 +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
Gabor Marton 5ac6d49065 [ASTImporter] Use llvm::Expected and Error in the importer API
Summary:
This is the final phase of the refactoring towards using llvm::Expected
and llvm::Error in the ASTImporter API.
This involves the following:
- remove old Import functions which returned with a pointer,
- use the Import_New functions (which return with Err or Expected) everywhere
  and handle their return value
- rename Import_New functions to Import
This affects both Clang and LLDB.

Reviewers: shafik, teemperor, aprantl, a_sidorin, balazske, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits, lldb-commits

Tags: #clang, #lldb

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

llvm-svn: 360760
2019-05-15 10:29:48 +00:00
Gabor Marton 3c72fe1bad [ASTImporter] Separate unittest files
Summary:
Move generic redecl chain tests and visibility tests into their own
separate test files.

Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: mgorny, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 360572
2019-05-13 10:06:25 +00:00
Krasimir Georgiev 4dea1378ea Revert "Revert "[clang-format] Keep protobuf "package" statement on one line""
Summary:
Top-level "package" and "import" statements should generally be kept on
one line, for all languages.

----

This reverts commit rL356912.
The regression from rL356835 was fixed via rC358275.

Reviewers: krasimir, sammccall, MyDeveloperDay, xinz, dchai, klimek

Reviewed By: krasimir, xinz, dchai

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360411
2019-05-10 09:15:11 +00:00
Richard Smith 76b9027f35 [c++20] Add support for explicit(bool), as described in P0892R2.
Patch by Tyker!

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

llvm-svn: 360311
2019-05-09 03:59:21 +00:00
Balazs Keri b7d8cffa75 [ASTImporter] Corrected type of integer constant in a test.
llvm-svn: 360156
2019-05-07 14:53:04 +00:00
Sam McCall 87ad30be5f [Tooling] Add -x flags when inferring compile commands for files with no/invalid extension.
Summary: We treat them as headers, as the motivating case is C++ standard library.

Reviewers: kadircet

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360153
2019-05-07 14:34:06 +00:00
Balazs Keri 1efc97425d [ASTImporter] Import TemplateParameterLists in function templates.
Summary: Correct missing import of TemplateParameterList in function decl.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 360132
2019-05-07 10:55:11 +00:00
Hans Wennborg d2b9fc88c8 Revert r359949 "[clang] adding explicit(bool) from c++2a"
This caused Clang to start erroring on the following:

  struct S {
    template <typename = int> explicit S();
  };

  struct T : S {};

  struct U : T {
    U();
  };
  U::U() {}

  $ clang -c /tmp/x.cc
  /tmp/x.cc:10:4: error: call to implicitly-deleted default constructor of 'T'
  U::U() {}
     ^
  /tmp/x.cc:5:12: note: default constructor of 'T' is implicitly deleted
    because base class 'S' has no default constructor
  struct T : S {};
             ^
  1 error generated.

See discussion on the cfe-commits email thread.

This also reverts the follow-ups r359966 and r359968.

> this patch adds support for the explicit bool specifier.
>
> Changes:
> - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
> - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
> - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
> - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
> - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
> - Test for Semantic and Serialization were added.
>
> This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
> Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.
>
> Patch by Tyker
>
> Differential Revision: https://reviews.llvm.org/D60934

llvm-svn: 360024
2019-05-06 09:51:10 +00:00
Hamza Sood 8205a814a6 [c++20] Implement P0428R2 - Familiar template syntax for generic lambdas
Differential Revision: https://reviews.llvm.org/D36527

llvm-svn: 359967
2019-05-04 10:49:46 +00:00
Nicolas Lesser 5fe2ddbdf4 [clang] adding explicit(bool) from c++2a
this patch adds support for the explicit bool specifier.

Changes:
- The parsing for the explicit(bool) specifier was added in ParseDecl.cpp.
- The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class.
- Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted.
- Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration.
- The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected.
- Test for Semantic and Serialization were added.

This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback.
Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky.

Patch by Tyker

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

llvm-svn: 359949
2019-05-04 00:09:00 +00:00
Owen Pan 3dcb892d2d [clang-format] Fix bug in block comment reflow that joins * and /
Fixes PR41213

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

llvm-svn: 359943
2019-05-03 23:15:40 +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
Owen Pan a0df4d37b0 [clang-format] Fix a bug in AlignConsecutiveDeclarations.
Fixes PR37175

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

llvm-svn: 359711
2019-05-01 18:23:44 +00:00
Owen Pan 945890a63c [clang-format] Fix bug that misses some function-like macro usages
Fixes PR41483

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

llvm-svn: 359687
2019-05-01 15:03:41 +00:00
Yitzhak Mandelbaum a5dadbe1aa [LibTooling] Fix broken test after r359574.
r359574 changed the way that failures are reported, which broke the test TransformerTest.NodePartNameDeclRefFailure which detects a faiure.

llvm-svn: 359578
2019-04-30 17:24:36 +00:00
Yitzhak Mandelbaum aecc59c5f9 [LibTooling] Change Transformer's TextGenerator to a partial function.
Summary:
Changes the signature of the TextGenerator std::function to return an Expected<std::string>
instead of std::string to allow for (non-fatal) failures.  Previously, we
expected that any failures would be expressed with assertions. However, that's
unfriendly to running the code in servers or other places that don't want their
library calls to crash the program.

Correspondingly, updates Transformer's handling of failures in TextGenerators
and the signature of `ChangeConsumer`.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 359574
2019-04-30 16:48:33 +00:00
Simon Pilgrim 648a8cfe70 Fix gcc "-Wdangling-else" warning. NFCI.
llvm-svn: 359551
2019-04-30 10:57:37 +00:00
Simon Pilgrim 85f61257d2 Fix gcc "-Wdangling-else" warnings. NFCI.
llvm-svn: 359550
2019-04-30 10:57:02 +00:00
Artem Dergachev ab7747b727 [analyzer] Treat functions without run-time branches as "small".
Currently we always inline functions that have no branches, i.e. have exactly
three CFG blocks: ENTRY, some code, EXIT. This makes sense because when there
are no branches, it means that there's no exponential complexity introduced
by inlining such function. Such functions also don't trigger various fundamental
problems with our inlining mechanism, such as the problem of inlined
defensive checks.

Sometimes the CFG may contain more blocks, but in practice it still has
linear structure because all directions (except, at most, one) of all branches
turned out to be unreachable. When this happens, still treat the function
as "small". This is useful, in particular, for dealing with C++17 if constexpr.

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

llvm-svn: 359531
2019-04-30 03:01:02 +00:00
Raphael Isemann e9bc35fe06 [ASTImporter] Add an ImportImpl method to allow customizing Import behavior.
Summary:
We are currently implementing support in LLDB that reconstructs the STL templates from
the target program in the expression evaluator. This reconstruction happens during the
import process from our debug info AST into the expression evaluation AST, which means
we need a way to intercept the ASTImporter import process.

This patch adds an protected ImportImpl method that we can overwrite in LLDB to implement
our special importing logic (which is essentially just looking into a C++ module that is attached to
the target context). Because ImportImpl has to call MapImported/AddToLookup for the decls it
creates, this patch also exposes those via a new unified method and checks that we call it when
importing decls.

Reviewers: martong, balazske, a.sidorin, shafik, a_sidorin

Reviewed By: martong, a_sidorin

Subscribers: rnkovacs, cfe-commits, lldb-commits, aprantl

Tags: #clang

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

llvm-svn: 359502
2019-04-29 21:02:35 +00:00
Petr Hosek 0f9f021d05 [Driver] Support priority for multilibs
When more than one multilib flag matches, try to select the best
possible match based on priority. When two different multilibs with
the same same priority match, we still throw an error matching the
existing behavior.

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

llvm-svn: 359359
2019-04-27 00:25:11 +00:00