Commit Graph

4360 Commits

Author SHA1 Message Date
Dmitri Gribenko 7b0be962d6 Make RecursiveASTVisitor call WalkUpFrom for unary and binary operators in post-order traversal mode
Reviewers: ymandel, eduucaldas, rsmith

Reviewed By: eduucaldas, rsmith

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82787
2020-07-03 13:03:19 +02:00
Dmitri Gribenko 94454442c3 RecursiveASTVisitor: don't call WalkUp unnecessarily in post-order traversal
Summary:
How does RecursiveASTVisitor call the WalkUp callback for expressions?

* In pre-order traversal mode, RecursiveASTVisitor calls the WalkUp
  callback from the default implementation of Traverse callbacks.

* In post-order traversal mode when we don't have a DataRecursionQueue,
  RecursiveASTVisitor also calls the WalkUp callback from the default
  implementation of Traverse callbacks.

* However, in post-order traversal mode when we have a DataRecursionQueue,
  RecursiveASTVisitor calls the WalkUp callback from PostVisitStmt.

As a result, when the user overrides the Traverse callback, in pre-order
traversal mode they never get the corresponding WalkUp callback. However
in the post-order traversal mode the WalkUp callback is invoked or not
depending on whether the data recursion optimization could be applied.

I had to adjust the implementation of TraverseCXXForRangeStmt in the
syntax tree builder to call the WalkUp method directly, as it was
relying on this behavior. There is an existing test for this
functionality and it prompted me to make this extra fix.

In addition, I had to fix the default implementation implementation of
RecursiveASTVisitor::TraverseSynOrSemInitListExpr to call WalkUpFrom in
the same manner as the implementation generated by the DEF_TRAVERSE_STMT
macro. Without this fix, the InitListExprIsPostOrderNoQueueVisitedTwice
test was failing because WalkUpFromInitListExpr was never called.

Reviewers: eduucaldas, ymandel

Reviewed By: eduucaldas, ymandel

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82486
2020-07-03 13:03:19 +02:00
Dmitri Gribenko 7988969143 Added tests for RecursiveASTVisitor for AST nodes that are special cased
Summary:
RecursiveASTVisitor has special code for handling operator AST nodes,
specifically, unary, binary, and compound assignment operators. In this
change I'm adding tests for operator AST nodes that follow the existing
pattern of tests for the CallExpr node (an AST node that triggers the
common code path).

Reviewers: ymandel, eduucaldas

Reviewed By: ymandel, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82875
2020-07-03 13:03:18 +02:00
Bruno Ricci fcf4d5e449
Revert "[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper"
This reverts commit aa7fd905e4.

I missed some dump() functions.
2020-07-02 19:40:09 +01:00
Bruno Ricci aa7fd905e4
[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper
In general there is no way to get to the ASTContext from most AST nodes
(Decls are one of the exception). This will be a problem when implementing
the rest of APValue::dump since we need the ASTContext to dump some kinds of
APValues.

The ASTContext* in ASTDumper and TextNodeDumper is not always
non-null. This is because we still want to be able to use the various
dump() functions in a debugger.

No functional changes intended.
2020-07-02 19:29:02 +01:00
Vince Bridgers 59f1bf46f8 [ASTImporter] Add unittest case for friend decl import
Summary:
This change adds a matching test case for the recent bug fix to
VisitFriendDecl in ASTImporterLookup.cpp.

See https://reviews.llvm.org/D82882 for details.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, teemperor, cfe-commits, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83006
2020-07-02 09:26:34 -05:00
Nathan James f51a319cac
[ASTMatchers] Enhanced support for matchers taking Regex arguments
Added new Macros `AST(_POLYMORPHIC)_MATCHER_REGEX(_OVERLOAD)` that define a matchers that take a regular expression string and optionally regular expression flags. This lets users match against nodes while ignoring the case without having to manually use `[Aa]` or `[A-Fa-f]` in their regex. The other point this addresses is in the current state, matchers that use regular expressions have to compile them for each node they try to match on, Now the regular expression is compiled once when you define the matcher and used for every node that it tries to match against. If there is an error while compiling the regular expression an error will be logged to stderr showing the bad regex string and the reason it couldn't be compiled. The old behaviour of this was down to the Matcher implementation and some would assert, whereas others just would never match. Support for this has been added to the documentation script as well. Support for this has been added to dynamic matchers ensuring functionality is the same between the 2 use cases.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82706
2020-07-02 14:52:25 +01:00
Eduardo Caldas fdbd78333f Add parenthesized expression to SyntaxTree
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82960
2020-07-02 06:28:41 +00:00
Gabriel Matute ecfa0b2418 [libTooling] Fix `maybeExtendRange` to support `CharRange`s.
Currently, `maybeExtendRange` takes a `CharSourceRange`, but only works
correctly for the `TokenRange` case. This change adds proper support for the
`CharRange` case.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D82901
2020-07-01 20:40:48 +00:00
Balázs Kéri f3b3446610 [clang][CrossTU] Invalidate parent map after get cross TU definition.
Summary:
Parent map of ASTContext is built once. If this happens and later
the TU is modified by getCrossTUDefinition the parent map does not
contain the newly imported objects and has to be re-created.

Invalidation of the parent map is added to the CrossTranslationUnitContext.
It could be added to ASTImporter as well but for now this task remains the
responsibility of the user of ASTImporter. Reason for this is mostly that
ASTImporter calls itself recursively.

Reviewers: gamesh411, martong

Reviewed By: gamesh411

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82568
2020-07-01 09:13:05 +02:00
Andy Soffer 9945bd5911 Add Metadata to Transformer tooling
This change adds a Metadata field to ASTEdit, Edit, and AtomicChange so that
edits can have associated metadata and that metadata can be constructed with
Transformer-based RewriteRules. Metadata is ignored when applying edits to
source, but other consumers of AtomicChange can use this metadata to direct how
they want to consume each edit.

Reviewed By: ymandel, gribozavr2

Differential Revision: https://reviews.llvm.org/D82226
2020-06-30 15:03:07 +00:00
Balazs Benics de361df3f6 [analyzer][Z3-refutation] Fix a refutation BugReporterVisitor bug
FalsePositiveRefutationBRVisitor had a bug where the constraints were not
properly collected thus crosschecked with Z3.
This patch demonstratest and fixes that bug.

Bug:
The visitor wanted to collect all the constraints on a BugPath.
Since it is a visitor, it stated the visitation of the BugPath with the node
before the ErrorNode. As a final step, it visited the ErrorNode explicitly,
before it processed the collected constraints.

In principle, the ErrorNode should have visited before every other node.
Since the constraints were collected into a map, mapping each symbol to its
RangeSet, if the map already had a mapping with the symbol, then it was skipped.

This behavior was flawed if:
We already had a constraint on a symbol, but at the end in the ErrorNode we have
a tighter constraint on that. Therefore, this visitor would not utilize that
tighter constraint during the crosscheck validation.

Differential Revision: https://reviews.llvm.org/D78457
2020-06-29 18:51:24 +02:00
Balazs Benics fe0a555aa3 [analyzer][NFC] Add unittest for FalsePositiveRefutationBRVisitor
Adds the test infrastructure for testing the FalsePositiveRefutationBRVisitor.
It will be extended in the D78457 patch, which demonstrates and fixes a bug in
the visitor.

Differential Revision: https://reviews.llvm.org/D78704
2020-06-29 18:18:43 +02:00
Dmitri Gribenko 1cf2e45c19 Compile the RecursiveASTVisitor callbacks test with "/bigobj"
Summary:
This file was exceeding a limit in MSVC:

fatal error C1128: number of sections exceeded object file format limit: compile with /bigobj

Reviewers: erichkeane

Reviewed By: erichkeane

Subscribers: jmorse, gribozavr2, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82766
2020-06-29 17:04:45 +02:00
Dmitri Gribenko a44425f25b Revert "[analyzer][NFC] Add unittest for FalsePositiveRefutationBRVisitor"
This reverts commit e22cae32c5. It broke
the build:

FalsePositiveRefutationBRVisitorTest.cpp:112:3: error: use of undeclared identifier 'LLVM_WITH_Z3'
2020-06-29 17:00:15 +02:00
Balazs Benics e22cae32c5 [analyzer][NFC] Add unittest for FalsePositiveRefutationBRVisitor
Adds the test infrastructure for testing the FalsePositiveRefutationBRVisitor.
It will be extended in the D78457 patch, which demonstrates and fixes a bug in
the visitor.

Differential Revision: https://reviews.llvm.org/D78704
2020-06-29 16:54:17 +02:00
Jake Merdich 0c332a7784 [clang-format] Preserve whitespace in selected macros
Summary:
https://bugs.llvm.org/show_bug.cgi?id=46383

When the c preprocessor stringizes tokens, the generated string literals
are affected by the whitespace. This means clang-format can affect
codegen silently, adding spaces and newlines to strings.  Practically
speaking, the vast majority of cases will be harmless, only affecting
single identifiers or debug macros.

In the interest of doing no harm in other cases though, this introduces
a blacklist option 'WhitespaceSensitiveMacros', which contains a list of
names of function-like macros whose contents should not be touched by
clang-format, period. Clang-format can't automatically detect these
without a real compile context, so users will have to specify it
explicitly (it still beats clang-format off'ing at every invocation).

Defaults include "STRINGIZE", "PP_STRINGIZE", and "BOOST_PP_STRINGIZE".

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82620
2020-06-29 09:57:47 -04:00
Dmitri Gribenko 339ed1e042 Move TestClangConfig into libClangTesting and use it in AST Matchers tests
Summary:
Previously, AST Matchers tests were using a custom way to run a test
with a specific C++ standard version. I'm migrating them to a shared
infrastructure to specify a Clang target from libClangTesting. I'm also
changing tests for AST Matchers to run in multiple language standards
versions, and under multiple triples that have different behavior with
regards to templates.

To keep the size of the patch manageable, in this patch I'm only
migrating one file to get the process started and get feedback on this
approach.

One caveat is that increasing the number of test configuration does
significantly increase the runtime of AST Matchers tests. On my machine,
the test runtime increases from 2.0 to 6.0s. I think it is worth the
improved test coverage.

Reviewers: jdoerfert, ymandel

Reviewed By: ymandel

Subscribers: gribozavr2, jfb, sstefan1, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82179
2020-06-29 12:50:15 +02:00
Dmitri Gribenko 8e5a56865f Add tests for sequences of callbacks that RecursiveASTVisitor produces
Summary:
These tests show a bug: post-order traversal introduces an extra call to
WalkUp*, that is not present in pre-order traversal. I'm fixing this bug
in a follow-up commit.

Reviewers: ymandel, eduucaldas

Reviewed By: ymandel, eduucaldas

Subscribers: gribozavr2, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82485
2020-06-29 12:36:01 +02:00
mydeveloperday eb50838ba0 [clang-format] [PR462254] fix indentation of default and break correctly in whitesmiths style
Summary:
https://bugs.llvm.org/show_bug.cgi?id=46254

Reviewed By: curdeius, jbcoe

Differential Revision: https://reviews.llvm.org/D8201
2020-06-27 11:35:22 +01:00
David Zarzycki dab859d1bf Reland: [clang driver] Move default module cache from system temporary directory
This fixes a unit test. Otherwise here is the original commit:

1) Shared writable directories like /tmp are a security problem.
2) Systems provide dedicated cache directories these days anyway.
3) This also refines LLVM's cache_directory() on Darwin platforms to use
   the Darwin per-user cache directory.

Reviewers: compnerd, aprantl, jakehehrlich, espindola, respindola, ilya-biryukov, pcc, sammccall

Reviewed By: compnerd, sammccall

Subscribers: hiraditya, llvm-commits, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D82362
2020-06-27 05:35:15 -04:00
Nico Weber 4d5c448943 Revert "[clang driver] Move default module cache from system temporary directory"
This reverts commit bb26838cef.
Breaks Support.CacheDirectoryNoEnv, Support.CacheDirectoryWithEnv
in SupportTests (part of check-llvm) on macOS.
2020-06-26 13:25:45 -04:00
Yitzhak Mandelbaum 30deabf89f [libTooling] Improve error message from failure in selection Stencil
This patch improves the error message provided by the stencil that handles
source from a range selector.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D82654
2020-06-26 16:17:28 +00:00
Dmitri Gribenko fa1b488776 Work around a bug in MSVC in the syntax tree test
Summary:
MSVC does not handle raw string literals with embedded double quotes
correctly. I switched the affected test case to use regular string
literals insetad.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82636
2020-06-26 16:43:30 +02:00
Yitzhak Mandelbaum 056a539e57 [libTooling] Rename overloaded `range` range selector.
Renames the overloaded `RangeSelector` combinator `range` to the more
descriptive `enclose` and `encloseNodes`. The old overloads are left in place
and marked deprected and will be deleted at a future time.

Reviewed By: tdl-g

Differential Revision: https://reviews.llvm.org/D82592
2020-06-26 14:23:25 +00:00
David Zarzycki bb26838cef [clang driver] Move default module cache from system temporary directory
1) Shared writable directories like /tmp are a security problem.
2) Systems provide dedicated cache directories these days anyway.
3) This also refines LLVM's cache_directory() on Darwin platforms to use
   the Darwin per-user cache directory.

Reviewers: compnerd, aprantl, jakehehrlich, espindola, respindola, ilya-biryukov, pcc, sammccall

Reviewed By: compnerd, sammccall

Subscribers: hiraditya, llvm-commits, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D82362
2020-06-26 07:46:03 -04:00
Eduardo Caldas 7b404b6d00 Add `FloatingLiteral` to SyntaxTree
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82318
2020-06-25 17:05:08 +00:00
Eduardo Caldas 466e8b7ea6 Add StringLiteral to SyntaxTree
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82360
2020-06-25 17:05:08 +00:00
Eduardo Caldas 221d7bbe49 Add `CharLiteral` to SyntaxTree
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82312
2020-06-25 17:05:08 +00:00
Eduardo Caldas 7f7f856480 Add `BoolLiteralExpression` to SyntaxTree
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82310
2020-06-25 15:37:53 +00:00
Daniel Grumberg e4e2d8e4c2 Ensure that CompilerInvocationTest normalizes default target triples
This fixes a build failure. More details at http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/78/steps/test-check-clang/logs/FAIL%3A%20Clang-Unit%3A%3ACC1CommandLineGenerationTest.CanGenerateCC1CommandLineSeparateRequiredAbsent
2020-06-25 10:41:40 +01:00
Fangrui Song 6330653547 [unittest] Fix FrontendTests CanGenerateCC1CommandLineFlag when LLVM_DEFAULT_TARGET_TRIPLE is not normalized after D79796
`TargetOpts->Triple` is initialized as llvm::sys::getDefaultTargetTriple() which may not be normalized.
If LLVM_DEFAULT_TARGET_TRIPLE is powerpc64le-linux-gnu, we should check
check `-triple powerpc64le-linux-gnu`, instead of (normalized) `-triple powerpc64le-unknown-linux-gnu`
2020-06-24 16:18:58 -07:00
Daniel Grumberg 29125ddf13 Start adding support for generating CC1 command lines from CompilerInvocation
This change includes the following:
- Add additional information in the relevant table-gen files to encode
the necessary information to automatically parse the argument into a
CompilerInvocation instance and to generate the appropriate command
line argument from a CompilerInvocation instance.
- Extend OptParserEmitter to emit the necessary macro tables as well as
constant tables to support parsing and generating command line
arguments for options that provide the necessary information.
- Port some options to use this new system for parsing and generating
command line arguments.

Differential Revision: https://reviews.llvm.org/D79796
2020-06-24 18:05:05 +01:00
Yitzhak Mandelbaum 87340a2bf1 [libTooling] Delete deprecated `Stencil` combinators.
Summary: Deletes `text()` and `selection()` combinators, since they have been deprecated for months.

Reviewers: tdl-g

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82225
2020-06-24 16:45:24 +00:00
Krasimir Georgiev 0fad648b65 [clang-format] restore indent in conditionals when AlignOperands is DontAlign
Summary:
After D50078, we're experiencing unexpected un-indent using a style combining `AlignOperands: DontAlign` with `BreakBeforeTernaryOperators: false`, such as Google's JavaScript style:
```
% bin/clang-format -style=google ~/test.js
aaaaaaaaaaa = bbbbbbbb ? cccccccccccccccccc() :
dddddddddd             ? eeeeeeeeeeeeee :
                         fffff;
```
The issue lies with the interaction of `AlignOperands: DontAlign` and the edited code section in ContinuationIndenter.cpp, which de-dents the intent by `Style.ContinuationIndentWidth`. From [[ ac3e5c4d93/clang/include/clang/Format/Format.h (L170) | the documentation ]] of AlignOperands: DontAlign:
> The wrapped lines are indented `ContinuationIndentWidth` spaces from the start of the line.
So the de-dent effectively erases the necessary `ContinuationIndentWidth` in that case.

This patch restores the `AlignOperands: DontAlign` behavior, producing:
```
% bin/clang-format -style=google ~/test.js
aaaaaaaaaaa = bbbbbbbb ? cccccccccccccccccc() :
    dddddddddd         ? eeeeeeeeeeeeee :
                         fffff;
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82199
2020-06-24 13:11:18 +02:00
Richard Smith a6308c0ad9 When performing a substitution into a dependent alias template, mark the
outer levels as retained rather than omitting their arguments.

This better reflects what's going on (we're performing a substitution
while still inside a template), and in theory is more correct, but I've
not found a testcase where it matters in practice (largely because we
don't allow alias templates to be declared inside a function).

Fixed AST dumping of SubstNonTypeTemplateParm[Pack]Expr to demonstrate
that we're properly substituting through dependent alias templates. (We
can't deduce properly through these yet, but we can at least produce the
right input to template argument deduction.)

No functionality change intended.
2020-06-23 14:43:04 -07:00
Aaron Ballman 8a9311940a Handle invalid types in the nullPointerConstant AST matcher
Currently, using the nullPointerConstant AST matcher can lead to
assertions in situations where a node to be matched does not have a
valid type associated with it, such as a ParenListExpr. This patch
addresses that by saying such nodes cannot be a null pointer constant.
This addresses PR46353.
2020-06-23 07:14:33 -04:00
Richard Smith 5eca1d5e0d AST dump: recurse into type template arguments when dumping.
Also, do not dump the desugared type for a TemplateSpecializationType
twice.
2020-06-23 00:07:00 -07:00
Loïc Joly cba56e026c [ASTMatcher] Correct memoization bug ignoring direction (descendants or ancestors)
Summary:
In ASTMatcher, when we have `has(...)` and `hasParent(...)` called with the same internal matcher on the same node, the memoization process will mix-up the two calls because the direction of the traversal is not part of the memoization key.

This patch adds this information.

Reviewers: klimek

Reviewed By: klimek

Subscribers: Godin, njames93, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80025
2020-06-22 12:56:29 +02:00
Yitzhak Mandelbaum d81d69f1c0 [libTooling] Change Transformer's `cat` to handle some cases of text in macros.
Summary:
Currently, `cat` validates range selections before extracting the corresponding
source text. However, this means that any range inside a macro is rejected as an
error. This patch changes the implementation to first try to map the range to
something reasonable. This makes the behavior consistent with handling of ranges
used for selecting portions of the source to edit.

Also updates a clang-tidy lit-test for one of the checks which was affected by
this change.

Reviewers: gribozavr2, tdl-g

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82126
2020-06-19 18:48:54 +00:00
Yitzhak Mandelbaum 9ca50e887d [libTooling] Add parser for string representation of `RangeSelector`.
This patch adds a parser for a `RangeSelector` written as a string. The format
is closely based on the way one would right the selector in C++. This should
enable use of `RangeSelector`s from tools like clang-query and web UIs.
2020-06-19 01:11:29 +00:00
Eduardo Caldas 1b2f6b4a08 Add support for DeclRefExpr in SyntaxTree, by generating IdExpressions
Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: hlopko, gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81168
2020-06-18 21:05:23 +02:00
Francesco Petrogalli 3e59dfc301 [llvm][SveEmitter] Emit the bfloat version of `svld1ro`.
Summary:
The new SVE builtin type __SVBFloat16_t` is used to represent scalable
vectors of bfloat elements.

Reviewers: sdesmalen, efriedma, stuij, ctetreau, shafik, rengolin

Subscribers: tschuett, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81304
2020-06-18 16:36:31 +00:00
Dmitry Polukhin c98c94d85f [clang-tidy] Add diagnostics level to YAML output
Summary:
Also added BuildDirectory for completness and removed unused `Fix`.

Test Plan: check-all

Reviewers: alexfh, gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D79285
2020-06-15 07:40:53 -07:00
mydeveloperday 0487f6f19c [clang-format] Fix short block when braking after control statement
Summary:
This patch fixes bug #44192

When clang-format is run with option AllowShortBlocksOnASingleLine, it is expected to either succeed in putting the short block with its control statement on a single line or fail and leave the block as is. When brace wrapping after control statement is activated, if the block + the control statement length is superior to column limit but the block alone is not, clang-format puts the block in two lines: one for the control statement and one for the block. This patch removes this unexpected behaviour. Current unittests are updated to check for this behaviour.

Patch By: Bouska

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D71512
2020-06-13 14:19:49 +01:00
Adam Balogh b2a37cfe2b [Analyzer] Replace `assert` with `ASSERT_TRUE` in a unit test to silence warnings 2020-06-12 17:09:34 +02:00
Kirstóf Umann e22f1c02a2 [analyzer] Introduce weak dependencies to express *preferred* checker callback evaluation order
Checker dependencies were added D54438 to solve a bug where the checker names
were incorrectly registered, for example, InnerPointerChecker would incorrectly
emit diagnostics under the name MallocChecker, or vice versa [1]. Since the
system over the course of about a year matured, our expectations of what a role
of a dependency and a dependent checker should be crystallized a bit more --
D77474 and its summary, as well as a variety of patches in the stack
demonstrates how we try to keep dependencies to play a purely modeling role. In
fact, D78126 outright forbids diagnostics under a dependency checkers name.

These dependencies ensured the registration order and enabling only when all
dependencies are satisfied. This was a very "strong" contract however, that
doesn't fit the dependency added in D79420. As its summary suggests, this
relation is directly in between diagnostics, not modeling -- we'd prefer a more
specific warning over a general one.

To support this, I added a new dependency kind, weak dependencies. These are not
as strict of a contract, they only express a preference in registration order.
If a weak dependency isn't satisfied, the checker may still be enabled, but if
it is, checker registration, and transitively, checker callback evaluation order
is ensured.

If you are not familiar with the TableGen changes, a rather short description
can be found in the summary of D75360. A lengthier one is in D58065.

[1] https://www.youtube.com/watch?v=eqKeqHRAhQM

Differential Revision: https://reviews.llvm.org/D80905
2020-06-12 14:08:38 +02:00
Kirstóf Umann d61b1f8534 [analyzer][NFC] Change checker dependency unit tests to check for the registration order
Exactly what it says on the tin! "Strong" dependencies are mentioned in contrast
to a new kind of dependency introduced in a followup patch.

Differential Revision: https://reviews.llvm.org/D80901
2020-06-12 12:43:56 +02:00
Simon Pilgrim 948b206fc2 Add missing lambda capture from rGf529c0a8a149. 2020-06-11 13:57:39 +01:00
Simon Pilgrim f529c0a8a1 Fix unused variable warning. NFCI.
We're only using the D2 iteration value inside the assert (the only component of the loop) - move the entire loop inside the assert by using llvm::all_of.
2020-06-11 13:48:42 +01:00
Endre Fülöp 5cc18516c4 [analyzer] On-demand parsing capability for CTU
Summary:
Introduce on-demand parsing of needed ASTs during CTU analysis.
The index-file format is extended, and analyzer-option CTUInvocationList
is added to specify the exact invocations needed to parse the needed
source-files.

Reviewers: martong, balazske, Szelethus, xazax.hun, whisperity

Reviewed By: martong, xazax.hun

Subscribers: gribozavr2, thakis, ASDenysPetrov, ormris, mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, steakhal, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75665
2020-06-11 10:56:59 +02:00
Endre Fülöp 435b458ad0 Revert "[analyzer] On-demand parsing capability for CTU"
This reverts commit 97e07d0c35.
Reason: OSX broke for a different reason, this really only seem to work
on linux and very generic windows builds
2020-06-10 17:55:37 +02:00
Haojian Wu 6ef08c3a70 Fix the -Wsign-compare warning. 2020-06-10 16:51:54 +02:00
Endre Fülöp 97e07d0c35 [analyzer] On-demand parsing capability for CTU
Summary:
Introduce on-demand parsing of needed ASTs during CTU analysis.
The index-file format is extended, and analyzer-option CTUInvocationList
is added to specify the exact invocations needed to parse the needed
source-files.

Reviewers: martong, balazske, Szelethus, xazax.hun, whisperity

Reviewed By: martong, xazax.hun

Subscribers: gribozavr2, thakis, ASDenysPetrov, ormris, mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, steakhal, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75665
2020-06-10 13:43:51 +02:00
Endre Fülöp c640779494 Revert "[analyzer] On-demand parsing capability for CTU"
This reverts commit 020815fafd.
Reason: PS4 buildbot broke
2020-06-10 10:30:10 +02:00
Endre Fülöp 020815fafd [analyzer] On-demand parsing capability for CTU
Summary:
Introduce on-demand parsing of needed ASTs during CTU analysis.
The index-file format is extended, and analyzer-option CTUInvocationList
is added to specify the exact invocations needed to parse the needed
source-files.

Reviewers: martong, balazske, Szelethus, xazax.hun, whisperity

Reviewed By: martong, xazax.hun

Subscribers: gribozavr2, thakis, ASDenysPetrov, ormris, mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, steakhal, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75665
2020-06-10 08:59:04 +02:00
Sterling Augustine ccd192204d Fix variables used only in asserts.
Summary: Fix variables used only in asserts.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81522
2020-06-09 17:19:38 -07:00
Tridacnid ce5fecb7d0 Assignment and Inc/Dec operators wouldn't register as a mutation when Implicit Paren Casts were present
Add ignoringParenImpCasts to assignment and inc/dec mutation checks in ExprMutationAnalyzer to fix clang-tidy bug PR45490.
https://bugs.llvm.org/show_bug.cgi?id=45490

Reviewed By: njames93, aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D79912
2020-06-09 19:45:57 +01:00
Jonathan Coe f22b0727fe [clang-format] Microsoft style fixes for C# properties
Summary:
There should be no line break before the opening brace for Microsoft style property accessors when the accessor is a simple `{ get; set }`.

https://docs.microsoft.com/en-us/dotnet/csharp/properties

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D81467
2020-06-09 14:50:34 +01:00
Adam Balogh 54f9ddd806 [Analyzer] Remove warning caused by commit `rGe22ace8ba2b0` 2020-06-09 15:46:15 +02:00
Adam Balogh e22ace8ba2 [Analyzer] Fix buildbot failure caused by commit `rG813734dad7e8b526c39806d1a88820b1f0706fb1` 2020-06-09 14:50:27 +02:00
Adam Balogh 5419a31215 [Analyzer] Allow creation of stack frame for functions without definition
Retrieving the parameter location of functions was disabled because it
may causes crashes due to the fact that functions may have multiple
declarations and without definition it is difficult to ensure that
always the same declration is used. Now parameters are stored in
`ParamRegions` which are independent of the declaration of the function,
therefore the same parameters always have the same regions,
independently of the function declaration used actually. This allows us
to remove the limitation described above.

Differential Revision: https://reviews.llvm.org/D80286
2020-06-09 12:08:57 +02:00
Adam Balogh 98db1f990f [Analyzer] [NFC] Parameter Regions
Currently, parameters of functions without their definition present cannot
be represented as regions because it would be difficult to ensure that the
same declaration is used in every case. To overcome this, we split
`VarRegion` to two subclasses: `NonParamVarRegion` and `ParamVarRegion`.
The latter does not store the `Decl` of the parameter variable. Instead it
stores the index of the parameter which enables retrieving the actual
`Decl` every time using the function declaration of the stack frame. To
achieve this we also removed storing of `Decl` from `DeclRegion` and made
`getDecl()` pure virtual. The individual `Decl`s are stored in the
appropriate subclasses, such as `FieldRegion`, `ObjCIvarRegion` and the
newly introduced `NonParamVarRegion`.

Differential Revision: https://reviews.llvm.org/D80522
2020-06-09 12:08:56 +02:00
Adam Balogh 813734dad7 [Analyzer] Add `getReturnValueUnderConstruction()` to `CallEvent`
Checkers should be able to get the return value under construction for a
`CallEvenet`. This patch adds a function to achieve this which retrieves
the return value from the construction context of the call.

Differential Revision: https://reviews.llvm.org/D80366
2020-06-09 12:08:56 +02:00
Jonathan Coe 7117066bd6 [clang-format] Brace breaking for C# lambdas
Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D81394
2020-06-09 10:20:01 +01:00
Shengchen Kan 2c63ea6ede [TEST] TreeTest.cpp - Add a comma to avoid build error with -werror
Summary:
The macro `INSTANTIATE_TEST_CASE_P` is defined as
```
\# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
...
```

If we build the test case with -werror, we will get an error like
```
error: ISO C++11 requires at least one argument for the "..." in a
variadic macro

testing::ValuesIn(TestClangConfig::allConfigs()));
                                                ^
```
This patch fixes that.

Reviewers: gribozavr, hlopko, eduucaldas, gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81388
2020-06-08 23:14:16 +08:00
Jonathan Coe a67949913a [clang-format] treat 'lock' as a keyword for C# code
Summary: This will put a space in `lock (process)` when spaces are required after keywords.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D81255
2020-06-08 13:31:22 +01:00
Richard Smith 825e3bb580 PR46209: properly determine whether a copy assignment operator is
trivial.

We previously took a shortcut by assuming that if a subobject had a
trivial copy assignment operator (with a few side-conditions), we would
always invoke it, and could avoid going through overload resolution.
That turns out to not be correct in the presenve of ref-qualifiers (and
also won't be the case for copy-assignments with requires-clauses
either). Use the same logic for lazy declaration of copy-assignments
that we use for all other special member functions.

Previously committed as c57f8a3a20. This
now also includes an extension of LLDB's workaround for handling special
members without the help of Sema to cover copy assignments.
2020-06-05 16:05:32 -07:00
Hans Wennborg 767516c546 Fix gcc5 build of ASTMatchersTest.h
After a180d54 the build was failing with:

In file included from /work/llvm.monorepo/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp:9:0:
/work/llvm.monorepo/clang/unittests/ASTMatchers/ASTMatchersTest.h:
In function ‘llvm::ArrayRef<clang::TestLanguage> clang::ast_matchers::langCxx11OrLater()’:
/work/llvm.monorepo/clang/unittests/ASTMatchers/ASTMatchersTest.h:64:10:
error: could not convert ‘(const clang::TestLanguage*)(& Result)’ from
‘const clang::TestLanguage*’ to ‘llvm::ArrayRef<clang::TestLanguage>’
   return Result;
          ^
2020-06-05 10:38:03 +02:00
Jonas Devlieghere df53f09056 Revert "PR46209: properly determine whether a copy assignment operator is"
This reverts commit c57f8a3a20.
2020-06-04 23:45:36 -07:00
Richard Smith c57f8a3a20 PR46209: properly determine whether a copy assignment operator is
trivial.

We previously took a shortcut by assuming that if a subobject had a
trivial copy assignment operator (with a few side-conditions), we would
always invoke it, and could avoid going through overload resolution.
That turns out to not be correct in the presenve of ref-qualifiers (and
also won't be the case for copy-assignments with requires-clauses
either). Use the same logic for lazy declaration of copy-assignments
that we use for all other special member functions.
2020-06-04 19:19:01 -07:00
Dmitri Gribenko a180d5409f AST Matchers test: use arrays instead of vectors
Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81180
2020-06-04 21:40:30 +02:00
Dmitri Gribenko b5fc1deb5b Use libClangTesting in the unittest for AST matchers
Summary:
The unittest for AST matchers has its own way to specify language
standards. I unified it with the shared infrastructure from
libClangTesting.

Reviewers: jdoerfert, hlopko

Reviewed By: hlopko

Subscribers: mgorny, sstefan1, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81150
2020-06-04 17:40:39 +02:00
Jonathan Coe 9520bf146d [clang-format] Update GoogleStyle for C# code to match Google's internal C# style guide
Summary: Google's C# style guide is at https://google.github.io/styleguide/csharp-style.html

Reviewers: krasimir, MyDeveloperDay, sammccall

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits, klimek

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D79715
2020-06-04 15:48:00 +01:00
Eduardo Caldas 3b739690b0 Add support for IntegerLiteral in SyntaxTree
Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81135
2020-06-04 14:05:31 +02:00
Dmitri Gribenko 06cf7adcc8 Make syntax tree test print the line number when it fails
Summary:
The syntax tree test uses a helper function that executes all testing
assertions. When an assertion fails, the only line number that gets
printed to the log refers to the helper function. After this change, we
would also get the line number of the EXPECT_TRUE macro invocation
(unfortunately, the line number of the last token of it, not the first
one, but there's not much I can do about it).

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81107
2020-06-04 10:42:44 +02:00
mydeveloperday 6de794e207 [clang-format] [PR46157] Wrong spacing of negative literals with use of operator
Summary:
see https://bugs.llvm.org/show_bug.cgi?id=46157

Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D80933
2020-06-03 20:44:45 +01:00
mydeveloperday 6a0484f04b [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases
Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D80940
2020-06-03 20:44:45 +01:00
Eduardo Caldas 007098d7e6 Add support for `nullptr` in SyntaxTrees
Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81092
2020-06-03 15:52:33 +02:00
Dmitri Gribenko d7d5dd31fc Split syntax tree tests into more granular ones
Summary:
Doing so allows us to increase test coverage by removing unnecessary
language restrictions.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81040
2020-06-03 11:17:11 +02:00
Dmitri Gribenko b34b7691fa Syntax tree: ignore implicit expressions at the top level of statements
Summary:
I changed `markStmtChild` to ignore implicit expressions the same way as
`markExprChild` does it already. The test that I modified crashes
without this change.

Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81019
2020-06-03 10:58:12 +02:00
Nathan James 26cb70683b [NFC][ASTMatchers] StringRef-ify and Twine-ify ASTMatchers tests. 2020-06-02 21:20:58 +01:00
Dmitri Gribenko 53c29a42d0 Reinstate the syntax tree test for 'static' in an array subscript
Reviewers: eduucaldas

Reviewed By: eduucaldas

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81009
2020-06-02 17:01:51 +02:00
Dmitri Gribenko d559185aae Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20
Summary:
I think we would be better off with tests explicitly specifying the
language mode. Right now Lang_C means C99, but reads as "any C version",
or as "unspecified C version".

I also changed '-std=c++98' to '-std=c++03' because they are aliases (so
there is no difference in practice), because Clang implements C++03
rules in practice, and because 03 makes a nice sortable progression
between 03, 11, 14, 17, 20.

Reviewers: shafik, hlopko

Reviewed By: hlopko

Subscribers: jfb, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81000
2020-06-02 16:31:20 +02:00
Dmitri Gribenko 44f989e780 Run syntax tree tests in many language modes
Reviewers: hlopko, eduucaldas

Reviewed By: hlopko, eduucaldas

Subscribers: gribozavr2, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80822
2020-06-02 10:30:01 +02:00
Nathan James b6d23f2efc [ASTMatchers] Force c++ unittests to specify correct language standard
Force the unittests on c++ code for matchers to specify the correct standard.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D80884
2020-06-01 07:52:01 +01:00
mydeveloperday 50bdd60731 [clang-format] [PR46130] When editing a file with unbalance {} the namespace comment fixer can incorrectly comment the wrong closing brace
Summary:
https://bugs.llvm.org/show_bug.cgi?id=46130   from Twitter https://twitter.com/ikautak/status/1265998988232159232

I have seen this myself many times.. if you have format on save and you work in an editor where you are constantly saving (:w muscle memory)

If you are in the middle of editing and somehow you've missed a { or } in your code, somewhere, often way below where you are at the bottom of your file the namespace comment fixer will have put the namespace on the previous closing brace.

This leads to you having to fix up the bottom of the file.

This revision prevents that happening by performing an initial pass of the tokens and simply counting the number of `{` and `}`  and ensuring they balance.

If they don't balance we don't do any namespace fixing as it will likely be unstable and incorrect.

Reviewed By: curdeius

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80830
2020-05-30 13:15:27 +01:00
Jan Korous 1a5c97f3a4 [ASTMatchers] Matchers related to C++ inheritance
Differential Revision: https://reviews.llvm.org/D79063
2020-05-29 12:38:01 -07:00
Eduardo Caldas 3a574a6cb3 Add support for Overloaded Binary Operators in SyntaxTree
Reviewers: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80812
2020-05-29 20:03:59 +02:00
Dmitri Gribenko 0e265e3157 Move unittest helpers to a shared location
Summary:
unittests/AST/Language.h defines some helpers that we would like to
reuse in other tests, for example, in tests for syntax trees.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: mgorny, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80792
2020-05-29 16:47:33 +02:00
Dmitri Gribenko d4ef654673 Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.

Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.

Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".

Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").

Reviewers: shafik, rengolin, sammccall

Reviewed By: sammccall

Subscribers: gribozavr2, sammccall, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80786
2020-05-29 14:25:20 +02:00
Vy Nguyen 51401a676c add isAtPosition narrowing matcher for parmVarDecl
Differential Revision: https://reviews.llvm.org/D80603
2020-05-28 16:04:41 -04:00
Eduardo Caldas eca41919d2 Improve test infrastructure in SyntaxTree
Summary:
* Test if the code sourcing the SyntaxTree compiles
* Output compiler errors and warnings to err
* Fix tests with code that did not compile

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80731
2020-05-28 21:35:12 +02:00
Yitzhak Mandelbaum ce5780b88c [libTooling] Fix Transformer to work with ambient traversal kinds.
Summary:
`RewriteRule`'s `applyFirst` was brittle with respect to the default setting of the
`TraversalKind`. This patch builds awareness of traversal kinds directly into
rewrite rules so that they are insensitive to any changes in defaults.

Reviewers: steveire, gribozavr

Subscribers: hokein, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80606
2020-05-28 11:42:07 -04:00
Yitzhak Mandelbaum 04a96aa3e4 [ASTMatchers] Add traversal-kind support to `DynTypedMatcher`
Summary:
This patch exposes `TraversalKind` support in the `DynTypedMatcher` API. While
previously, the `match` method supported traversal logic, it was not possible to
set or get the traversal kind.

Reviewers: gribozavr, steveire

Subscribers: hokein, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80685
2020-05-28 11:18:37 -04:00
Valeriy Savchenko bd06c417e6 [analyzer] Allow bindings of the CompoundLiteralRegion
Summary:
CompoundLiteralRegions have been properly modeled before, but
'getBindingForElement` was not changed to accommodate this change
properly.

rdar://problem/46144644

Differential Revision: https://reviews.llvm.org/D78990
2020-05-28 14:11:57 +03:00
Eduardo Caldas 461af57de7 Add support for UnaryOperator in SyntaxTree
Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80624
2020-05-27 17:12:46 +02:00
mydeveloperday 8f1156a7d0 [clang-format] Fix an ObjC regression introduced with new [[likely]][[unlikely]] support in if/else clauses
Summary:
{D80144} introduce an ObjC regression

Only parse the `[]` if what follows is really an attribute

Reviewers: krasimir, JakeMerdichAMD

Reviewed By: krasimir

Subscribers: rdwampler, aaron.ballman, curdeius, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80547
2020-05-26 18:48:49 +01:00
Yitzhak Mandelbaum ff2743bf04 [libTooling] In Transformer, allow atomic changes to span multiple files.
Summary:
Currently, all changes returned by a single application of a rule must fit in
one atomic change and therefore must apply to one file. However, there are
patterns in which a single rule will want to modify multiple files; for example,
a header and implementation to change a declaration and its definition. This
patch relaxes Transformer, libTooling's interpreter of RewriteRules, to support
multiple changes.

Reviewers: gribozavr

Subscribers: mgrang, jfb, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80239
2020-05-26 09:17:35 -04:00
Eduardo Caldas 3785eb83af Add support for binary operators in Syntax Trees
Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80540
2020-05-26 12:25:58 +02:00
Denys Petrov ba92b27422 [analyzer] Improved RangeSet::Negate support of unsigned ranges
Summary:
This fixes https://bugs.llvm.org/show_bug.cgi?id=41588
RangeSet Negate function shall handle unsigned ranges as well as signed ones.
RangeSet getRangeForMinusSymbol function shall use wider variety of ranges, not only concrete value ranges.
RangeSet Intersect functions shall not produce assertions.

Changes:
Improved safety of RangeSet::Intersect function. Added isEmpty() check to prevent an assertion.
Added support of handling unsigned ranges to RangeSet::Negate and RangeSet::getRangeForMinusSymbol.
Extended RangeSet::getRangeForMinusSymbol to return not only range sets with single value [n,n], but with wide ranges [n,m].
Added unit test for Negate function.
Added regression tests for unsigned values.

Differential Revision: https://reviews.llvm.org/D77802
2020-05-25 18:52:22 +03:00
mydeveloperday 447ea9b4f5 [AST] default implementation is possible for non-member functions in C++20.
Summary:
Make RAV not visit the default function decl by default.
Also update some stale comments on FunctionDecl::isDefault.

Fixes https://github.com/clangd/clangd/issues/383

Reviewers: sammccall, rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80288
2020-05-25 10:45:12 +02:00
Stephen Kelly e60de8c825 Add missing test 2020-05-24 22:50:50 +01:00
Stephen Kelly 2be92b7f7e Fix ignore-traversal to call correct method
As is done by ignoreParenImpCasts(). We were not previously calling the
correct internal method.  Adjust tests to account for this.
2020-05-24 22:33:10 +01:00
Stephen Kelly 04ed532ef0 Fix skip-invisible with overloaded method calls 2020-05-24 12:36:16 +01:00
Stephen Kelly 64356b6d94 Add missing unit test 2020-05-23 01:29:39 +01:00
Stephen Kelly 3a1f0c6bd1 Fix mistake made while rebasing 2020-05-23 01:26:30 +01:00
Stephen Kelly 8d62eba105 Add some explicit use of TK_AsIs 2020-05-23 01:04:44 +01:00
Stephen Kelly 26ac5a34ba Fix ignoring traversal of intermediate parens 2020-05-23 01:04:44 +01:00
Stephen Kelly aa5d2d2248 Traverse-ignore invisible CXXConstructExprs with default args 2020-05-23 01:04:44 +01:00
Stephen Kelly a30d411629 Set traversal explicitly where needed in tests
Reviewers: aaron.ballman, shafik

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72531
2020-05-21 22:34:38 +01:00
mydeveloperday 6ef45b0426 [clang-format] Added new option IndentExternBlock
Reviewers: MyDeveloperDay, krasimir, klimek, mitchell-stellar, Abpostelnicu

Patch By: MarcusJohnson91

Reviewed By: MyDeveloperDay, Abpostelnicu

Subscribers: sylvestre.ledru, Abpostelnicu, cfe-commits

Tags: #clang, #clang-format, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75791
2020-05-20 21:27:15 +01:00
mydeveloperday 166ebefd27 [clang-format] Set of unit test to begin to validate that we don't change defaults
Summary:
This revision is to complement {D75791} so we can be sure that we don't change any default behavior.

For now just add rules to cover AfterExternBlock, but in the future we should add cases to cover the other BraceWrapping rules for each style. This will help guard us when we change code inside of the various getXXXStyle() functions to ensure we are not breaking everyone.

Reviewed By: MarcusJohnson91

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https:
2020-05-20 21:11:10 +01:00
mydeveloperday 807ab2cd0d [clang-format] [PR42164] Add Option to Break before While
Summary:
Its currently not possible to recreate the GNU style using the `BreakBeforeBraces: Custom` style due to a lack of missing `BeforeWhile` in the `BraceWrappingFlags`

The following request was raised to add `BeforeWhile` in a `do..while` context like `BeforeElse` and `BeforeCatch` to give greater control over the positioning of the `while`

https://bugs.llvm.org/show_bug.cgi?id=42164

Reviewers: krasimir, mitchell-stellar, sammccall

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79325
2020-05-20 07:48:45 +01:00
mydeveloperday cc918e90c0 [clang-format] [PR33890] Add support for Microsoft C++/CLI non standard for each looping extension
Summary:
https://bugs.llvm.org/show_bug.cgi?id=33890

This revision allow the microsoft `for each(.... in ...` nonstandard C++ extension which can be used in C++/CLI to be handled as a ForEach macro.

This prevents the breaking between the for and each onto a new line

Reviewed By: JakeMerdichAMD

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80228
2020-05-20 07:44:36 +01:00
mydeveloperday b99bf0e08b [clang-format][PR45816] Add AlignConsecutiveBitFields
Summary:
The following revision follows D80115 since @MyDeveloperDay and I apparently both had the same idea at the same time, for https://bugs.llvm.org/show_bug.cgi?id=45816 and my efforts on tooling support for AMDVLK, respectively.

This option aligns adjacent bitfield separators across lines, in a manner similar to AlignConsecutiveAssignments and friends.

Example:
```
struct RawFloat {
  uint32_t sign : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```
would become
```
struct RawFloat {
  uint32_t sign     : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```

This also handles c++2a style bitfield-initializers with AlignConsecutiveAssignments.
```
struct RawFloat {
  uint32_t sign     : 1  = 0;
  uint32_t exponent : 8  = 127;
  uint32_t mantissa : 23 = 0;
}; // defaults to 1.0f
```

Things this change does not do:
 - Align multiple comma-chained bitfield variables. None of the other
   AlignConsecutive* options seem to implement that either.
 - Detect bitfields that have a width specified with something other
   than a numeric literal (ie, `int a : SOME_MACRO;`). That'd be fairly
   difficult to parse and is rare.

Patch By:  JakeMerdichAMD

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80176
2020-05-20 07:42:58 +01:00
mydeveloperday e71c537a48 [clang-format] Fix line lengths w/ comments in align
Summary:
https://bugs.llvm.org/show_bug.cgi?id=43845

When a '//comment' trails a consecutive alignment, it adds a whitespace
replacement within the comment token. This wasn't handled correctly in
the alignment code, which treats it as a whole token and thus double
counts it.

This can wrongly trigger the "line too long, it'll wrap" alignment-break
condition with specific lengths, causing the alignment to break for
seemingly no reason.

Patch By:  JakeMerdichAMD

Reviewed By: MyDeveloperDay

Subscribers: kostyakozko, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79465
2020-05-20 07:22:01 +01:00
mydeveloperday 5d82cb3c3a [clang-format] @lefticus just taught the world how to use [[unlikely]] but we forgot to teach clang-format
Summary:
https://twitter.com/lefticus/status/1262392152950288384?s=20

Jason Turner's (@lefticus) most recent C++ weekly explains the usage of [[likely]] and [[unlikely]] in an 'if/else' context in C++ 20

clang-format leaves the code a little messy afterwards..

```
if (argc > 5)
  [[unlikely]] {
    // ...
  }
else if (argc < 0)
  [[likely]] {
    // ...
  }
else
  [[likely]] {
    // ...
  }
```

try to improve the situation

```
if (argc > 5) [[unlikely]] {
  // ...
} else if (argc < 0) [[likely]] {
  // ...
} else [[likely]] {
  // ...
}
```

Reviewed By: JakeMerdichAMD

Subscribers: cfe-commits, lefticus

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80144
2020-05-19 16:50:24 +01:00
mydeveloperday 575c59cf6a [clang-format] [PR45614] Incorrectly indents [[nodiscard]] attribute funtions after a macro without semicolon
Summary:
https://bugs.llvm.org/show_bug.cgi?id=45614

`[[nodiscard]]` after a macro doesn't behave the same as an __attribute__ resulting in incorrect indentation

This revision corrects that behavior

See original Mozilla bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=1629756

Before:

```
class FooWidget : public nsBaseWidget {
public:
  FooWidget();

  NS_DECL_ISUPPORTS_INHERITED

      [[nodiscard]] nsresult
      FunctionOne();
  [[nodiscard]] nsresult FunctionTwo();
};
```

After:
```
class FooWidget : public nsBaseWidget {
public:
  FooWidget();

  NS_DECL_ISUPPORTS_INHERITED

  [[nodiscard]] nsresult FunctionOne();
  [[nodiscard]] nsresult FunctionTwo();
};
```

Reviewed By: Abpostelnicu

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79990
2020-05-19 16:47:38 +01:00
mydeveloperday 07740dd08b [clang-format] [PR44476] Add space between template and attribute
Summary:
https://bugs.llvm.org/show_bug.cgi?id=44476

```template <typename T> [[nodiscard]] int a() { return 1; }```

gets incorrectly formatted to be

```template <typename T>[[nodiscard]] int a() { return 1; }```

This revision ensure there is a space between the template and the attribute

Reviewed By: JakeMerdichAMD

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79905
2020-05-19 16:43:50 +01:00
mydeveloperday 6189dd06ad [clang-format] [PR45942] [[nodiscard]] causes && to be miss interpreted as BinaryOperators
Summary:
https://bugs.llvm.org/show_bug.cgi?id=45942

With Chromium style (although that is not important) its just it defines PointerAligmment: Left

The following arguments `S&&` are formatted differently depending on if the class has an attribute between it and the class identifier

```
class S {
  S(S&&) = default;
};

class [[nodiscard]] S {
  S(S &&) = default;
};
```

The prescense of [[nodiscard]] between the `class/struct` and the `{` causes the `{` to be incorrectly seen as a `TT_FunctionLBrace` which in turn transforms all the && to be `TT_BinaryOperators` rather than `TT_PointerOrReference`, as binary operators other spacing rules come into play causing a miss format

This revision resolves this by allowing the parseRecord to consider the [[nodisscard]]

Reviewed By: Abpostelnicu

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80008
2020-05-19 16:41:50 +01:00
Haojian Wu 6f56599c14 [AST] Fix the PrintQualifiedName for ObjC instance variable in class extension.
Summary:
Similar to property, we print the containing interface decl as the
nested name specifier for ivar; otherwise we will get "::ivar_name".

this would fix an assertion crash in clangd: https://github.com/clangd/clangd/issues/365

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79576
2020-05-19 15:17:36 +02:00
Kirstóf Umann 9d69072fb8 [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker
One of the pain points in simplifying MallocCheckers interface by gradually
changing to CallEvent is that a variety of C++ allocation and deallocation
functionalities are modeled through preStmt<...> where CallEvent is unavailable,
and a single one of these callbacks can prevent a mass parameter change.

This patch introduces a new CallEvent, CXXDeallocatorCall, which happens after
preStmt<CXXDeleteExpr>, and can completely replace that callback as
demonstrated.

Differential Revision: https://reviews.llvm.org/D75430
2020-05-19 00:18:38 +02:00
Nathan James 74bcb00e00 [ASTMatchers] Added BinaryOperator hasOperands matcher
Summary: Adds a matcher called `hasOperands` for `BinaryOperator`'s when you need to match both sides but the order isn't important, usually on commutative operators.

Reviewers: klimek, aaron.ballman, gribozavr2, alexfh

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80054
2020-05-17 19:54:14 +01:00
mydeveloperday e8ea35e63f [clang-format] [PR44345] Long namespace closing comment is duplicated endlessly
Summary:
https://bugs.llvm.org/show_bug.cgi?id=44345

When namespaces get long the namespace end comment wraps onto the next line

```
namespace would:🇮🇹:save::you:🅰️:lot::of::time::if_::i::just::gave:🆙:and_::
    went::mad::now {
void foo();
void bar();
} // namespace
  // would:🇮🇹:save::you:🅰️:lot::of::time::if_::i::just::gave:🆙:and_::went::mad::now
```

If clang-format it applied successively it will duplicate the end comment

```
namespace would:🇮🇹:save::you:🅰️:lot::of::time::if_::i::just::gave:🆙:and_::
    went::mad::now {
void foo();
void bar();
} // namespace
  // would:🇮🇹:save::you:🅰️:lot::of::time::if_::i::just::gave:🆙:and_::went::mad::now
  // would:🇮🇹:save::you:🅰️:lot::of::time::if_::i::just::gave:🆙:and_::went::mad::now
```

This revision checks to ensure the end comment is not on the next line before adding yet another comment

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79935
2020-05-15 21:00:55 +01:00
Francois Ferrand 0ee04e6e0d [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set
Summary:
Even when BreakBeforeBinaryOperators is set, AlignOperands kept
aligning the beginning of the line, even when it could align the
actual operands (e.g. after an assignment).

With this patch, the operands are actually aligned, and the operator
gets aligned with the equal sign:

  int aaaaa = bbbbbb
            + cccccc;

This not happen in tests, to avoid 'breaking' the indentation:

  if (aaaaa
      && bbbbb)
    return;

Reviewers: krasimir, djasper, klimek, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, acoomans, cfe-commits, klimek

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D32478
2020-05-15 16:40:31 +02:00
Francois Ferrand 4db94094b4 clang-format: support aligned nested conditionals formatting
Summary:
When multiple ternary operators are chained, e.g. like an if/else-if/
else-if/.../else sequence, clang-format will keep aligning the colon
with the question mark, which increases the indent for each
conditionals:

  int a = condition1 ? result1
                     : condition2 ? result2
                                  : condition3 ? result3
                                               : result4;

This patch detects the situation (e.g. conditionals used in false branch
of another conditional), to avoid indenting in that case:

  int a = condition1 ? result1
        : condition2 ? result2
        : condition3 ? result3
                     : result4;

When BreakBeforeTernaryOperators is false, this will format like this:

  int a = condition1 ? result1 :
          condition2 ? result2 :
          conditino3 ? result3 :
                       result4;

This formatting style is referenced here:
https://www.fluentcpp.com/2018/02/27/replace-else-if-ternary-operator/
and here:
https://marcmutz.wordpress.com/2010/10/14/top-5-reasons-you-should-love-your-ternary-operator/

Reviewers: krasimir, djasper, klimek, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: hokein, dyung, MyDeveloperDay, acoomans, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D50078
2020-05-15 16:38:25 +02:00
Jonathan Coe 8fa743ab82 [clang-format] C# property formatting can be controlled by config options
Summary:
Allow brace wrapping in C# property accessors to be controlled by configuration options.

Add new tests and revert old test results for Microsoft style to their previous state (as intended).

`FormatStyle.BraceWrapping.AfterFunction = true;` will change automatic property formatting from

```
Type MyType { get; set }
```

to

```
Type MyType
{ get; set }
```

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir, MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D79000
2020-05-15 14:08:40 +01:00
Alex Lorenz 11d612ac99 [clang][Preprocessor] Replace the slow translateFile call by a new, faster isMainFile check
The commit 3c28a2dc6b introduced the check that checks if we're
trying to re-enter a main file when building a preamble. Unfortunately this slowed down the preamble
compilation by 80-90% in some test cases, as translateFile is really slow. This change checks
to see if the FileEntry is the main file without calling translateFile, but by using the new
isMainFile check instead. This speeds up preamble building by 1.5-2x for certain test cases that we have.

rdar://59361291

Differential Revision: https://reviews.llvm.org/D79834
2020-05-14 14:13:34 -07:00
mydeveloperday c82243d067 [clang-format] : Fix additional pointer alignment for overloaded operators
Summary:
Follow on from {D78879} to handle the more obscure to prevent spaces between operators

```
operator void *&();
operator void *&&();
operator void &*();
operator void &&*();
```

Reviewers: sylvestre.ledru, sammccall, krasimir, Abpostelnicu

Reviewed By: sammccall, Abpostelnicu

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79201
2020-05-13 18:33:57 +01:00
mydeveloperday b2eb439317 [clang-format] Fix AlignConsecutive on PP blocks
Summary:
Currently the 'AlignConsecutive*' options incorrectly align across
elif and else statements, even if they are very far away and across
unrelated preprocessor macros.

This failed since on preprocessor run 2+, there is not enough context
about the #ifdefs to actually differentiate one block from another,
causing them to align across different blocks or even large sections of
the file.

Eg, with AlignConsecutiveAssignments:

```
\#if FOO      // Run 1
\#else        // Run 1
int a   = 1;  // Run 2, wrong
\#endif       // Run 1

\#if FOO      // Run 1
\#else        // Run 1
int bar = 1;  // Run 2
\#endif       // Run 1
```

is read as

```
int a   = 1;  // Run 2, wrong
int bar = 1;  // Run 2
```

The approach taken to fix this was to add a new flag to Token that
forces breaking alignment across groups of lines (MustBreakAlignBefore)
in a similar manner to the existing flag that forces a line break
(MustBreakBefore). This flag is set for the first Token after a
preprocessor statement or diff conflict marker.

Fixes #25167,#31281

Patch By: JakeMerdichAMD

Reviewed By: MyDeveloperDay

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79388
2020-05-13 18:31:51 +01:00
mydeveloperday 31fd12aa09 [clang-format] [PR34574] Handle [[nodiscard]] attribute in class declaration
Summary:
https://bugs.llvm.org/show_bug.cgi?id=34574
https://bugs.llvm.org/show_bug.cgi?id=38401

```
template <typename T>
class [[nodiscard]] result
{
  public:
    result(T&&)
    {
    }
};
```

formats incorrectly to

```
template <typename T>
class [[nodiscard]] result{public : result(T &&){}};
```

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79354
2020-05-09 11:27:23 +01:00
mydeveloperday 5a4ddbd69d [clang-format] [PR45639] clang-format splits up the brackets of C++17 attribute [[ ]] when used with the first parameter
Summary:
https://bugs.llvm.org/show_bug.cgi?id=45639

clang-format incorrectly splits the `[[` in a long argument list

```
void SomeLongClassName::ALongMethodNameInThatClass([[maybe_unused]] const shared_ptr<ALongTypeName>& argumentNameForThat
LongType) {

}
```

becomes

```
void SomeLongClassName::ALongMethodNameInThatClass([
    [maybe_unused]] const shared_ptr<ALongTypeName> &argumentNameForThatLongType) {

}
```

leaving one `[` on the previous line

For a function with just 1 very long argument, clang-format chooses to split between the `[[`,

This revision prevents the slip between the two `[` and the second `[`

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79401
2020-05-07 22:00:04 +01:00
mydeveloperday 5b8ffb4142 [clang-format] [PR45791] BeforeLambdaBody is confused by comment inside lambda
Summary:
https://bugs.llvm.org/show_bug.cgi?id=45791

Lambda with line comment is incorrectly formatted

```
auto k = []() // comment
{ return; };
````

```
auto k = []() // comment { return; };
```

Reviewed By: Wawha

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79320
2020-05-07 19:53:56 +01:00
Daan De Meyer f21c704553 clang-format: Add ControlStatementsExceptForEachMacros option to SpaceBeforeParens
Summary: systemd recently added a clang-format file. One issue I
encountered in using clang-format on systemd is that systemd does
not add a space before the parens of their foreach macros but
clang-format always adds a space. This does not seem to be
configurable in clang-format. This revision adds the
ControlStatementsExceptForEachMacros option to SpaceBeforeParens
which puts a space before all control statement parens except
ForEach macros. This drastically reduces the amount of changes
when running clang-format on systemd's source code.

Reviewers: MyDeveloperDay, krasimir, mitchell-stellar

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78869
2020-05-06 20:59:24 +02:00
Jonathan Coe 047898c9aa [clang-format] C# always regards && as a binary operator
Reviewers: krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D79414
2020-05-05 14:05:00 +01:00
mydeveloperday ece7e95f02 [clang-format] NFC - clang-format the FormatTests
Summary:
Ensure the clang-format unit tests are themselves clang-formatted

Having areas of the llvm code which are clang-format clean, give us more areas to run new clang-format binaries on ensuring we haven't broken anything.

It seems to me we SHOULD have this clang-formatted at a minimum, otherwise how can we expect others to use clang-format if we "don't eat our own dogfood", also if the tests are dependent on the formatting of the code then that would also be bad!

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79204
2020-05-02 15:42:20 +01:00
Sam McCall d10c995b4d std::isspace -> llvm::isSpace (where locale should be ignored)
I've left out some cases where I wasn't totally sure this was right or
whether the include was ok (compiler-rt) or idiomatic (flang).
2020-05-02 15:36:04 +02:00
Michał Górny cac8cd0a16 [clang] [unittest/AST] Fix linking to LLVMTestingSupport
Link to LLVMTestingSupport via target_link_libraries() instead of
clang_target_link_libraries().  The latter is ineffective if tests
are linked to libclang.so.  This solution is consistent with what other
tests do.
2020-05-01 21:22:51 +02:00
mydeveloperday 511868dcf3 [clang-format] [PR45626] SpacesInAngles does not insert or preserve leading space before :: operator
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=45626

Ensure space between < and ::

(void)static_cast<::std::uint32_t >(1);

Reviewers: krasimir, mitchell-stellar

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79172
2020-04-30 21:47:19 +01:00
Aaron Smith 292058a5d6 [clang-format] Fix Microsoft style for enums
Summary:
Before this change enums were formatted incorrectly for the Microsoft style.

[C++ Example]

    enum {
      one,
      two
    } three, four;

[Incorrectly Formatted]

    enum
    {
      one,
      two
    } three,
        four;

[Correct Format with Patch]

    enum
    {
      one,
      two
    } three, four;

Reviewers: jbcoe, MyDeveloperDay, rnk

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D78982
2020-04-30 09:11:54 -07:00
mydeveloperday a8b8bd0f8d [clang-format] Fix a bug causing BeforeLambdaBody to affect brace initialiser formatting
Summary: The condition added with the new setting checked whether the character was an l-brace, not specifically a lambda l-brace, when deciding whether it was possible to break before it or not. This caused the l-brace of some initialiser lists to break onto the next line with the first argument of the initialiser list when the setting was enabled.

Reviewed By: MyDeveloperDay, Wawha

Patch By: duncan-llvm

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79022
2020-04-30 11:11:34 +01:00
mydeveloperday 14198ccfb3 [clang-format] Fix lambda with ellipsis in return type
Summary:
BTW my actual code that hit this issue is like

```
[a, b = std::move(b)](auto &&... c) mutable -> std::invoke_result_t<decltype(b), decltype(c)...> { /* omitted */ }
```

where this explicit return type is required for SFINAE.

Reviewed By: krasimir, MyDeveloperDay

Patch By: johnchen902

Subscribers: krasimir, dexonsmith, cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78694
2020-04-30 11:02:42 +01:00
mydeveloperday b01dca5008 [clang-format] [PR45357] Fix issue found with operator spacing
Summary:
This is a tentative fix for https://bugs.llvm.org/show_bug.cgi?id=45357

Spaces seem to be introduced between * and * due to changes brought in for {D69573}

Reviewers: sylvestre.ledru, mitchell-stellar, sammccall, Abpostelnicu, krasimir, jbcoe

Reviewed By: Abpostelnicu

Subscribers: tstellar, hans, Abpostelnicu, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D78879
2020-04-30 10:55:59 +01:00
Jonathan Coe 85ee97fd89 Revert "[clang-format] C# property formatting can be controlled by config options"
Committed in error without approval https://reviews.llvm.org/D79000

This reverts commit 015bca3e67.
2020-04-28 17:41:17 +01:00
Jonathan Coe 015bca3e67 [clang-format] C# property formatting can be controlled by config options
Summary:
Allow brace wrapping in C# property accessors to be controlled by configuration options.

Add new tests and revert old test results for MS style to their old state (as intended).

`FormatStyle.BraceWrapping.AfterFunction = true;` will change automatic property formatting from

```
Type MyType { get; set }
```

to

```
Type MyType
{ get; set }
```

Reviewers: krasimir, MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D79000
2020-04-28 17:35:33 +01:00
Jonathan Coe 7443f86eab [clang-format] insert space after C# keyword var in var (key, value)
Reviewers: krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D79008
2020-04-28 17:31:40 +01:00
Jonathan Coe 44ad58b991 [clang-format] Improved parser for C# properties
Summary:
Added some examples of properties from Microsoft documentation as test cases.

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties

Configuration support will be added in a follow up patch to address whether automatic properties are formatted as

```
Type MyType { get; set }
```

or

```
Type MyType
{ get; set }
```

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78915
2020-04-28 14:11:09 +01:00
Arthur Eubanks dab1326a5a Strip -showIncludes in getClangStripDependencyFileAdjuster()
Summary:
Follow-up to https://reviews.llvm.org/D78836.

Also consolidate some test cases.

Reviewers: thakis

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78939
2020-04-27 11:20:08 -07:00
Dmitri Gribenko 96717125e8 Revert "[analyzer] On-demand parsing capability for CTU"
This reverts commit 811c0c9eb4. It broke
multiple buildbots.
2020-04-27 14:27:04 +02:00
Raphael Isemann f181f1b7f7 [clang] Remove NFC overload in ASTImporterTest
This overload is just an artifact from the original version of the patch, but
doesn't have any functional purpose.
2020-04-27 14:10:43 +02:00
Raphael Isemann 9f1e81f1c0 [ASTImporter] Also import overwritten file buffers
Summary:
Overwritten file buffers are at the moment ignored when importing and
instead only the underlying file buffer is imported.

This patch fixes this by not going to the underlying file entry if the file has
an overwritten buffer.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong, shafik

Subscribers: rnkovacs

Differential Revision: https://reviews.llvm.org/D78086
2020-04-27 13:16:08 +02:00
Endre Fülöp 811c0c9eb4 [analyzer] On-demand parsing capability for CTU
Summary:
Add an option to enable on-demand parsing of needed ASTs during CTU analysis.
Two options are introduced. CTUOnDemandParsing enables the feature, and
CTUOnDemandParsingDatabase specifies the path to a compilation database, which
has all the necessary information to generate the ASTs.

Reviewers: martong, balazske, Szelethus, xazax.hun

Subscribers: ormris, mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, steakhal, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75665
2020-04-27 11:20:35 +02:00
Arthur Eubanks 8000d506af [clangd] Strip /showIncludes in clangd compile commands
In command lines with /showIncludes, clangd would output includes to stdout, breaking clients.

Summary: Fixes https://github.com/clangd/clangd/issues/322.

Reviewers: sammccall, kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78836
2020-04-26 18:57:39 -07:00
shafik def7c7f602 [ASTImporter] Fix handling of not defined FromRecord in ImportContext(...)
In ImportContext(…) we may call into CompleteDecl(…) which if FromRecrord is not
defined will start the definition of a ToRecord but from what I can tell at least
one of the paths though here don't ensure we complete the definition.
For a RecordDecl this can be problematic since this means we won’t import base
classes and we won’t have any of the methods or types we inherit from these bases.

Differential Revision: https://reviews.llvm.org/D78000
2020-04-23 15:18:48 -07:00
Jonathan Coe 2f9fc8d971 [clang-format] Handle C# property accessors when parsing lines
Summary:
Improve C# `{ get; set; } = default;` formatting by handling it in the UnwrappedLineParser rather than trying to merge lines later.

Remove old logic to merge lines.

Update tests as formatting output has changed (as intended).

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78642
2020-04-23 13:25:10 +01:00
Haojian Wu 47ef09e484 Revert "clang-format: support aligned nested conditionals formatting"
This reverts 3d61b1120e, 5daa25fd7a

The clang-format test (FormatTest.ConfigurableUseOfTab) is failing in the buildbot:

http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/31811/steps/ninja%20check%201/logs/stdio
2020-04-23 09:25:01 +02:00
Kadir Cetinkaya 411a254af3
[clang] Make sure argument expansion locations are correct in presence of predefined buffer
Summary:
Macro argument expansion logic relies on skipping file IDs that created
as a result of an include. Unfortunately it fails to do that for
predefined buffer since it doesn't have a valid insertion location.

As a result of that any file ID created for an include inside the
predefined buffers breaks the traversal logic in
SourceManager::computeMacroArgsCache.

To fix this issue we first record number of created FIDs for predefined
buffer, and then skip them explicitly in source manager.

Another solution would be to just give predefined buffers a valid source
location, but it is unclear where that should be..

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78649
2020-04-22 21:01:52 +02:00
Francois Ferrand 3d61b1120e clang-format: Introduce stricter AlignOperands flag
Summary:
Even when BreakBeforeBinaryOperators is set, AlignOperands kept
aligning the beginning of the line, even when it could align the
actual operands (e.g. after an assignment).

With this patch, there is an option to actually align the operands, so
that the operator gets right-aligned with the equal sign or return
operator:

  int aaaaa = bbbbbb
            + cccccc;
  return aaaaaaa
      && bbbbbbb;

This not happen in parentheses, to avoid 'breaking' the indentation:

  if (aaaaa
      && bbbbb)
    return;

Reviewers: krasimir, djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32478
2020-04-22 17:36:38 +02:00
Francois Ferrand 5daa25fd7a clang-format: support aligned nested conditionals formatting
When multiple ternary operators are chained, e.g. like an if/else-if/
else-if/.../else sequence, clang-format will keep aligning the colon
with the question mark, which increases the indent for each
conditionals:

  int a = condition1 ? result1
                     : condition2 ? result2
                                  : condition3 ? result3
                                               : result4;

This patch detects the situation (e.g. conditionals used in false branch
of another conditional), to avoid indenting in that case:

  int a = condition1   ? result1
          : condition2 ? result2
          : condition3 ? result3
                       : result4;

When BreakBeforeTernaryOperators is false, this will format like this:

  int a = condition1 ? result1 :
          condition2 ? result2 :
          conditino3 ? result3 :
                       result4;
2020-04-22 17:36:33 +02:00
Jonathan Coe 07c1978b15 [clang-format] Do not interpret C# deconstruction in a foreach as a cast
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78295
2020-04-16 14:22:34 +01:00
Jan Korous 14d89bfbe0 [ASTMatchers] Fix isDerivedFrom for recursive templates
Differential Revision: https://reviews.llvm.org/D77612
2020-04-15 12:49:01 -07:00
Huihui Zhang 25db295756 [NFC] Silence compiler warning [-Wmissing-braces].
clang/unittests/AST/ASTImporterFixtures.h:70:5: warning: suggest braces around initialization of subobject [-Wmissing-braces]
    ArgVector(), ArgVector{"-fdelayed-template-parsing"},
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    {
2020-04-15 11:46:05 -07:00
Vince Bridgers 789215dc0d [ASTImporter] Add support for importing fixed point literals
Summary:
This patch adds support for importing fixed point literals, following
up to https://reviews.llvm.org/D46915 specifically for importing AST.

Reviewers: martong, leonardchan, ebevhan, a.sidorin, shafik

Reviewed By: martong

Subscribers: balazske, rnkovacs, teemperor, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77721
2020-04-15 10:36:44 -05:00
mydeveloperday e8111502d8 [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation
Summary:
Use spaces instead of tabs for alignment with UT_ForContinuationAndIndentation to make the code aligned for any tab/indent width.

Fixes https://bugs.llvm.org/show_bug.cgi?id=38381

Reviewed By: MyDeveloperDay

Patch By: fickert

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D75034
2020-04-13 15:14:26 +01:00
mydeveloperday 072ae7c1e6 [clang-format] Always break line after enum opening brace
Summary:
clang-format currently puts the first enumerator on the same line as the
enum keyword and opening brace if it fits (for example, for anonymous
enums if IndentWidth is 8):

  $ echo "enum { RED, GREEN, BLUE };" | clang-format -style="{BasedOnStyle: llvm, ColumnLimit: 15, IndentWidth: 8}"
  enum { RED,
         GREEN,
         BLUE };

This doesn't seem to be intentional, as I can't find any style guide that
suggests wrapping enums this way. Always force the enumerator to be on a new
line, which gets us the desired result:

  $ echo "enum { RED, GREEN, BLUE };" | ./bin/clang-format -style="{BasedOnStyle: llvm, ColumnLimit: 15, IndentWidth: 8}"
  enum {
          RED,
          GREEN,
          BLUE
  };

Test Plan:

New test added. Confirmed test failed without change and passed with change by
running:

  $ ninja FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewed By: MyDeveloperDay

Patch By: osandov

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D77682
2020-04-13 15:03:36 +01:00
Nathan James db71354e4f [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers
Summary: Requires hasCastKind arguments to have `CK_` prefixed to bring it in line with the documentation and other matchers that take enumerations.

Reviewers: klimek, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77503
2020-04-09 15:09:45 +01:00
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
Marcel Hlopko 1bf055c989 [Syntax] Add mapping from spelled to expanded tokens for TokenBuffer
Summary:
Same restrictions apply as in the other direction: macro arguments are
not supported yet, only full macro expansions can be mapped.

Taking over from https://reviews.llvm.org/D72581.

Reviewers: gribozavr2, sammccall

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77209
2020-04-07 15:07:16 +02:00
Sam McCall d66afd6dde [Syntax] Merge overlapping top-level macros in TokenBuffer
Summary:
Our previous definition of "top-level" was too informal, and didn't
allow for overlapping macros that each directly produce expanded tokens.
See D77507 for previous discussion.

Fixes http://bugs.llvm.org/show_bug.cgi?id=45428

Reviewers: kadircet, vabridgers

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77615
2020-04-07 15:06:04 +02:00
Kanglei Fang 28ecd7f0b0 [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam
Summary:
While [the original diff](https://reviews.llvm.org/D42493) makes a lot of sense, and multiple inline block parameter/trailing paramemter after inline block paramemter should be discouraged, the formatting result is different than what xcode does by default
For the exact same example provided in the original diff:
```
[object
  blockArgument:^{
    a = 42;
  }
     anotherArg:42];
```
The code is hard to read and not very visually pleasing

This diff uses `ObjCBreakBeforeNestedBlockParam` to shield from the formatting
When it's set to false, don't allign the inline block paramemters.

Reviewers: jolesiak, benhamilton, jinlin

Reviewed By: jolesiak

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77039
2020-04-06 14:20:09 -07: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
Martin Probst 92201505cd clang-format: [JS] handle pseudo-keywords.
Summary:
The previous change in https://reviews.llvm.org/D77311 attempted to
detect more C++ keywords. However it also precisely detected all
JavaScript keywords. That's generally correct, but many JavaScripy
keywords, e.g. `get`, are so-called pseudo-keywords. They can be used in
positions where a keyword would never be legal, e.g. in a dotted
expression:

    x.type;  // type is a pseudo-keyword, but can be used here.
    x.get;   // same for get etc.

This change introduces an additional parameter to
`IsJavaScriptIdentifier`, allowing clients to toggle whether they want
to allow `IdentifierName` tokens, i.e. pseudo-keywords.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77548
2020-04-06 17:13:04 +02: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
Martin Probst 146d685cd6 clang-format: [JS] detect C++ keywords.
Summary:
C++ defines a number of keywords that are regular identifiers in
JavaScript, e.g. `concept`:

    const concept = 1; // legit JS

This change expands the existing `IsJavaScriptIdentifier(Tok)` function
to return false for C++ keywords that aren't keywords in JS.

Reviewers: krasimir

Subscribers: jfb, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77311
2020-04-03 14:23:56 +02: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
Raphael Isemann 08a53dba93 [clang] Minor cleanup in CloneDetectionTest
Follow up to e8f13f4f62.
2020-04-01 10:48:50 +02:00
Benjamin Kramer e8f13f4f62 Replace std::string::find == 0 with StringRef::startswith
This is both more readable and faster. Found by clang-tidy's
abseil-string-find-startswith.
2020-03-31 21:01:09 +02:00
Jonathan Coe d1b412ae38 [clang-format] Correct line breaks in C# generic type constraints
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D77064
2020-03-31 19:27:01 +01:00
Marcel Hlopko cdce2fe561 [Syntax] Remove delayed folding from tree building.
Summary:
This patch removes delayed folding and replaces it with forward peeking.

Delayed folding was previously used as a solution to the problem that
declaration doesn't have a representation in the AST. For example following
code:

```
int a,b;
```

is expressed in the AST as:

```
TranslationUnitDecl
|-...
|-VarDecl `int a`
`-VarDecl `int b`
```

And in the syntax tree we need:

```
*: TranslationUnit
`-SimpleDeclaration
  |-int
  |-SimpleDeclarator
  | `-a
  |-,
  |-SimpleDeclarator
  | `-b
  |-;
```

So in words, we need to create SimpleDeclaration to be a parent of
SimpleDeclarator nodes. Previously we used delayed folding to make sure SimpleDeclarations will be
eventually created. And in case multiple declarators requested declaration
creation, declaration range was extended to cover all declarators.

This design started to be hard to reason about, so we decided to replace it with
forward peeking. The last declarator node in the chain is responsible for creating
SimpleDeclaration for the whole chain. Range of the declaration corresponds to
the source range of the declarator node. Declarator decides whether its the last
one by peeking to the next AST node (see `isResponsibleForCreatingDeclaration`).

This patch does following:
* Removed delayed folding logic
* Tweaks Token.dumpForTests
* Moves getQualifiedNameStart inside BuildTreeVisitor
* Extracts BuildTreeVisitor.ProcessDeclaratorAndDeclaration
* Renames Builder.getDeclRange to Builder.getDeclarationRange and uses the
  method in all places.
* Adds a bunch of tests

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76922
2020-03-31 09:47:50 +02:00
Haojian Wu 6f428e09fb [AST] Fix crashes on decltype(recovery-expr).
Summary: We mark these decls as invalid.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77037
2020-03-30 14:56:33 +02:00
Krasimir Georgiev 0574030c01 [clang-format] only parse C# generic type constraints in C#
Commit "[clang-format] Handle C# generic type constraints",
dcbcec4822
regressed the formatting of code containing `where` as an identifier in other
languages.
2020-03-30 13:13:07 +02:00
Kadir Cetinkaya 9619c2cc9a
[clang][Syntax] Handle macro arguments in spelledForExpanded
Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75446
2020-03-28 16:35:46 +01:00
Kirstóf Umann bda3dd0d98 [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions
Some checkers may not only depend on language options but also analyzer options.
To make this possible this patch changes the parameter of the shouldRegister*
function to CheckerManager to be able to query the analyzer options when
deciding whether the checker should be registered.

Differential Revision: https://reviews.llvm.org/D75271
2020-03-27 14:34:09 +01:00
Hans Wennborg eb85e90350 clang-format: Fix pointer alignment for overloaded operators (PR45107)
This fixes a regression from D69573 which broke the following example:

  $ echo 'operator C<T>*();' | bin/clang-format --style=Chromium
  operator C<T> *();

(There should be no space before the asterisk.)

It seems the problem is in TokenAnnotator::spaceRequiredBetween(),
which only looked at the token to the left of the * to see if it was a
type or not. That code only handled simple types or identifiers, not
templates or qualified types. This patch addresses that.

Differential revision: https://reviews.llvm.org/D76850
2020-03-27 10:47:19 +01:00
Kirstóf Umann 4dc8472942 [analyzer] Add the Preprocessor to CheckerManager 2020-03-26 17:29:52 +01:00
Haojian Wu 62dea6e9be Revert "[AST] Build recovery expressions by default for C++."
This reverts commit 0788acbccb.
This reverts commit c2d7a1f79cedfc9fcb518596aa839da4de0adb69:  Revert "[clangd] Add test for FindTarget+RecoveryExpr (which already works). NFC"

It causes a crash on invalid code:

class X {
  decltype(unresolved()) foo;
};
constexpr int s = sizeof(X);
2020-03-26 16:25:32 +01:00
Sam McCall 159a9f7e76 [AST] Print a<b<c>> without extra spaces in C++11 or later.
Summary: It's not 1998 anymore.

Reviewers: kadircet

Subscribers: jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76801
2020-03-26 09:53:54 +01:00
Haojian Wu 0788acbccb [AST] Build recovery expressions by default for C++.
Update the existing tests.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76696
2020-03-25 09:00:48 +01:00
Jonathan Coe 04336ada17 [clang-format] No space inserted between commas in C#
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D76621
2020-03-23 17:17:27 +00:00
Jonathan Coe 5e1a026c2d [clang-format] Do not indent C# array initialisers as continuations
Summary: Flag '= {' as a braced init list when parsing C# code.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75760
2020-03-23 14:33:10 +00:00
Jonathan Coe 78e2a3c678 [clang-format] Reflow long C# generic type constraints correctly
Summary:
Align sequential generic type constraints on a type.

Indent sequential generic type constraints on different types as continuations.

Do not allow '(' and '<' within a generic type constraint to open new scopes.

Reviewers: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D76597
2020-03-23 13:38:21 +00:00
Marcel Hlopko eddede9d51 [Syntax] Test both the default and windows target platforms in unittests
Summary:
This increases the coverage for things that differ between Linux and Windows, such as -fdelayed-template-parsing. This would have prevented the rollback of https://reviews.llvm.org/D76346.

While at it, update -std=c++11 to c++17 for the test.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76497
2020-03-20 16:33:58 +01:00
Dmitri Gribenko 9967352a03 Revert "[Syntax] Test both the default and windows target platforms in unittests"
This reverts commit fd7300f717. The fix
in this patch didn't help and the Windows buildbot broke:
http://45.33.8.238/win/10881/step_7.txt
2020-03-20 12:13:49 +01:00
Marcel Hlopko fd7300f717 [Syntax] Test both the default and windows target platforms in unittests
Summary:
This increases the coverage for things that differ between Linux and Windows, such as `-fdelayed-template-parsing`. This would have prevented the rollback of https://reviews.llvm.org/D76346.

While at it, update -std=c++11 to c++17 for the test.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76433
2020-03-20 11:42:18 +01:00
Marcel Hlopko e9630630ff [Syntax] Split syntax tests
Summary:
This patch split Basic test into multple individual tests to allow simpler
filtering and clearer signal into what's broken when it's broken.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76366
2020-03-20 09:53:43 +01:00
Marcel Hlopko 88bf9b3d26 [Syntax] Build template declaration nodes
Summary:
Rollforward of
https://reviews.llvm.org/rGdd12826808f9079e164b82e64b0697a077379241 after
temporarily adding -fno-delayed-template-parsing to the TreeTest.

Original summary:

> Copy of https://reviews.llvm.org/D72334, submitting with Ilya's permission.
>
> Handles template declaration of all kinds.
>
> Also builds template declaration nodes for specializations and explicit
> instantiations of classes.
>
> Some missing things will be addressed in the follow-up patches:
>
> * specializations of functions and variables,
> * template parameters.

Reviewers: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76418
2020-03-19 17:43:07 +01:00
Adam Balogh 6cff2e9f78 [Analyzer] Bugfix for CheckerRegistry
`CheckerRegistry` registers a checker either if it is excplicitly
enabled or it is a dependency of an explicitly enabled checker and is
not explicitly disabled. In both cases it is also important that the
checker should be registered (`shoudRegister`//XXX//`()` returns true).

Currently there is a bug here: if the dependenct checker is not
explicitly disabled it is registered regardless of whether it should
be registered. This patch fixes this bug.

Differential Revision: https://reviews.llvm.org/D75842
2020-03-19 16:06:42 +01:00
Jonathan Coe dcbcec4822 [clang-format] Handle C# generic type constraints
Summary:
Treat each C# generic type constraint, `where T: ...`, as a line.

Add C# keyword: where

Add Token Types: CSharpGenericTypeConstraint, CSharpGenericTypeConstraintColon, CSharpGenericTypeConstraintComma.

This patch does not wrap generic type constraints well, that will be addressed in a follow up patch.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D76367
2020-03-19 12:56:08 +00:00
Eli Friedman e24e95fe90 Remove CompositeType class.
The existence of the class is more confusing than helpful, I think; the
commonality is mostly just "GEP is legal", which can be queried using
APIs on GetElementPtrInst.

Differential Revision: https://reviews.llvm.org/D75660
2020-03-18 13:53:17 -07:00
Nico Weber 881f5b5a7b Revert "[Syntax] Build template declaration nodes"
This reverts commit dd12826808.
Breaks tests on Windows, see https://reviews.llvm.org/D76346#1929208
2020-03-18 12:57:55 -04:00
Marcel Hlopko dd12826808 [Syntax] Build template declaration nodes
Summary:
Copy of https://reviews.llvm.org/D72334, submitting with Ilya's permission.

Handles template declaration of all kinds.

Also builds template declaration nodes for specializations and explicit
instantiations of classes.

Some missing things will be addressed in the follow-up patches:

specializations of functions and variables,
template parameters.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76346
2020-03-18 16:16:59 +01:00
Marcel Hlopko 7d382dcd46 [Syntax] Build declarator nodes
Summary:
Copy of https://reviews.llvm.org/D72089 with Ilya's permission. See
https://reviews.llvm.org/D72089 for the first batch of comments.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76220
2020-03-16 19:13:59 +01:00
Dmitri Gribenko 2e77f0cf76 Added 'const' as suggested by ClangTidy llvm-qualified-auto 2020-03-13 11:49:23 +01:00
Marcel Hlopko f8640737d4 Refactor SourceLocationTest to `using namespace`
Summary: Only for the readability reasons.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76120
2020-03-13 10:55:24 +01:00
Marcel Hlopko ce79c42469 [Sema] Fix location of star ('*') inside MemberPointerTypeLoc
Summary: Copy of https://reviews.llvm.org/D72073?id=235842, submitting with ilya-biryukov's permission.

Reviewers: gribozavr, gribozavr2

Reviewed By: gribozavr2

Subscribers: mgorny, gribozavr2, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76061
2020-03-13 10:47:57 +01:00
Marcel Hlopko db1f40d1a1 Modernize DeclTest
Summary:
This patch removes a call to the old ASTUnit::findFileRegionDecls and
replaces it with ast matchers.

Reviewers: gribozavr, gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76121
2020-03-13 10:37:48 +01:00
Richard Sandiford fa8080376e [AST][SVE] Add new Type queries for sizeless types
One of the defining features of the SVE ACLE types is that they
are "sizeless"; see the SVE ACLE spec:

    https://developer.arm.com/docs/100987/0000/arm-c-language-extensions-for-sve

or the email message:

    http://lists.llvm.org/pipermail/cfe-dev/2019-June/062523.html

for a fuller definition of what that means.

This patch adds two associated type queries:

- isSizelessBuiltinType asks specifically about types that are built
  into clang.  It is effectively an enum range check.

- isSizelessType instead tests for any type that has the "sizeless" type
  property.  At the moment it only returns true for the built-in types,
  but it seems better not to hard-code that assumption throughout
  the codebase.  (E.g. we could in principle support some form of
  user-defined sizeless types in future.  Even if that seems unlikely
  and never actually happens, the possibility at least exists.)

Differential Revision: https://reviews.llvm.org/D75570
2020-03-12 16:30:50 +00: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
Reid Kleckner c4d23d8854 Add a missing include to clang unit tests 2020-03-11 21:05:20 -07:00
Reid Kleckner 213aea4c58 Remove unused Endian.h includes, NFC
Mainly avoids including Host.h everywhere:

$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \
    | grep '^[-+] ' | sort | uniq -c | sort -nr
   3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h
2020-03-11 15:45:34 -07:00
Reid Kleckner e08464fb45 Avoid including FileManager.h from SourceManager.h
Most clients of SourceManager.h need to do things like turning source
locations into file & line number pairs, but this doesn't require
bringing in FileManager.h and LLVM's FS headers.

The main code change here is to sink SM::createFileID into the cpp file.
I reason that this is not performance critical because it doesn't happen
on the diagnostic path, it happens along the paths of macro expansion
(could be hot) and new includes (less hot).

Saves some includes:
    309 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileManager.h
    272 -    /usr/local/google/home/rnk/llvm-project/clang/include/clang/Basic/FileSystemOptions.h
    271 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/VirtualFileSystem.h
    267 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/FileSystem.h
    266 -    /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Chrono.h

Differential Revision: https://reviews.llvm.org/D75406
2020-03-11 13:53:12 -07:00
Mitchell Balan c5c487f0d4 Revert "[clang-format] Add option to specify explicit config file"
There were a number of unexpected test failures.

This reverts commit 10b1a87ba3.
2020-03-11 16:14:42 -04:00
Mitchell Balan 10b1a87ba3 [clang-format] Add option to specify explicit config file
Summary:
This diff extends the -style=file option to allow a config file to be specified explicitly. This is useful (for instance) when adding IDE commands to reformat code to a personal style.

Reviewers: djasper, ioeric, krasimir, MyDeveloperDay

Reviewed by: MyDeveloperDay

Contributed by: tnorth

Subscribers: cfe-commits, lebedev.ri, MyDeveloperDay, klimek, sammccall, mitchell-stellar

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D72326
2020-03-11 15:56:44 -04:00
Jonathan Coe 1fb9c29833 [clang-format] Improved identification of C# nullables
Summary:
Allow `?` inside C# generics.

Do not mistake casts like `(Type?)` as conditional operators.

Reviewers: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75983
2020-03-11 12:58:52 +00:00
Jonathan Coe 5c917bd9a7 [clang-format] No space in `new()` and `this[Type x]` in C#
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75984
2020-03-11 12:53:53 +00:00
Rumeet Dhindsa 57a2eaf3c1 Revert "[modules] Do not cache invalid state for modules that we attempted to load."
As per comment on https://reviews.llvm.org/D72860, it is suggested to
revert this change in the meantime, since it has introduced regression.

This reverts commit 83f4c3af02.
2020-03-10 10:59:26 -07:00
Jonathan Coe 0c28a0938c [clang-format] Correct indentation for `[key] = value,` entries in C# object initialisers
Restores content of commit cb3f20d27c
reverted in commit 5a101f3773
with a corrected commit message.

Summary: Do not use continuation indent for '[' in blocks in C# code.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75747
2020-03-10 09:36:52 +00:00
Jonathan Coe 5a101f3773 Revert "[clang-format] Correct indentation for `[key] = value,` entries in C++ object initialisers"
Commit message says "C++" where it should say "C#".

This reverts commit cb3f20d27c.
2020-03-10 09:30:34 +00: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
Jonathan Coe cb3f20d27c [clang-format] Correct indentation for `[key] = value,` entries in C++ object initialisers
Summary: Do not use continuation indent for '[' in blocks in C# code.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75747
2020-03-09 18:04:34 +00:00
Jonathan Coe eb682b8027 [clang-format] C# does not indent braced initializers as continuations
Summary: C# treats object initializers as braced init blocks. Braced init blocks are no longer indented as continuations.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75731
2020-03-09 17:36:21 +00:00
Jonathan Coe b28ed9cec8 [clang-format] cleanup from D75517
Summary:
Fix typo in comment.

Add closing brace to test text.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75856
2020-03-09 17:31:36 +00:00
Kirstóf Umann 58884eb648 [analyzer][NFC] Refactor the checker registration unit test file
Nothing exciting to see here! The new interface allows for more fine tuning
(register but disable a checker, add custom checker registry functions, etc),
that was basically the point.

Differential Revision: https://reviews.llvm.org/D67335
2020-03-09 16:38:30 +01:00
Balázs Kéri 8d67bcf93c [ASTImporter] Added visibility check for variable templates.
Summary:
ASTImporter makes now difference between variable templates
with same name in different translation units if not visible
outside.

Reviewers: a.sidorin, shafik, a_sidorin

Reviewed By: a_sidorin

Subscribers: dkrupp, Szelethus, gamesh411, teemperor, martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75732
2020-03-09 11:57:55 +01: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
Mitchell Balan 2eff1c3ce4 [clang-format] Extend AllowShortLoopsOnASingleLine to do ... while loops.
Summary:
If AllowShortLoopsOnASingleLine is enabled,

  do
    a++;
  while (true);

becomes

  do a++;
  while (true);

Reviewers: MyDeveloperDay, mitchell-stellar

Reviewed by: mitchell-stellar

Contributed by: DaanDeMeyer

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D75022
2020-03-06 11:13:23 -05: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
Krasimir Georgiev 36c2ab8d04 [clang-format] do not insert spaces around inline asm symbolic names
Summary:
Fixes https://bugs.llvm.org/show_bug.cgi?id=45108.

The `[` in such cases was mis-annotated as an `TT_ArrayInitializerLSquare`.

Reviewers: hans

Reviewed By: hans

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75675
2020-03-05 14:17:21 +01:00
Jonathan Coe fe61bc1a0b [clang-format] Improve identification of C# nullables
Summary: Consider `? identifier =` and `? identifier;` to be nullable within function bodies.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75606
2020-03-04 18:10:27 +00:00
Jonathan Coe 7d2fdd3f66 [clang-format] parse C# object initialisers
Summary:
Treat C# object initializers as braced lists.

Allow lambdas inside C# braced lists.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75473
2020-03-04 12:14:00 +00:00
Jonathan Coe 736fef97c7 [clang-format] Do not format C# array subscript operators as attributes
Summary:
Fix misidentification of C# array subscript operators.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75517
2020-03-03 22:21:33 +00:00
Jonathan Coe 9f8a7e82b8 [clang-format] Allow nested [] in C# attributes
Summary: Keep track of unpaired [] when identifying C# attribute lines

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75455
2020-03-03 17:35:09 +00:00
Kadir Cetinkaya cd9b2e18bd
[clang][Syntax] Add spelledTokenAt helper to TokenBuffer
Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75503
2020-03-03 14:30:41 +01:00
Jonathan Coe 9c4afce702 [clang-format] Rename CSharpNullConditionalSq and add missing test
Summary:
Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

Add test for spaces inside [] with C# Null conditionals.

Address comments missed from https://reviews.llvm.org/D75368.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75456
2020-03-02 15:46:33 +00:00
Jonathan Coe c3af063c2b [clang-format] Handle NullCoalescing and NullConditional operators in C#
Summary:
Disable merging of Type? into a single token.

Merge ?? ?. and ?[ into a single token.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75368
2020-03-02 13:55:54 +00: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
Jonathan Coe f829615205 [clang-format] Improve C# handling of spaces in square brackets
Reviewers: MyDeveloperDay, krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75336
2020-02-28 12:44:15 +00:00
Jonathan Coe 5f52a93b69 [clang-format] Recognize C# nullable types
Summary:
Do not confuse C# nullable types with conditional expressions.

Do not put a space before the `?` in `[access-modifier] Type? variableName;`

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir, MyDeveloperDay

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75261
2020-02-28 11:09:55 +00:00
Balázs Kéri b17f292010 [ASTImporter] Improved import of AlignedAttr.
Summary:
It is not enough to clone the attributes at import.
They can contain reference to objects that should be imported.
This work is done now for AlignedAttr.

Reviewers: martong, a.sidorin, shafik

Reviewed By: shafik

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75048
2020-02-28 09:40:59 +01:00
Adrian McCarthy 0a3117832c Need /bigobj to build SourceCodeTest.cpp with MSVC. 2020-02-27 14:56:29 -08:00
Reid Kleckner 4c2a6567bb Avoid ASTContext.h -> TargetInfo.h dep
This has been done before in 2008: ab13857072
But these things regress easily.
Move some things out of line.

Saves 316 includes + transitive stuff:
    316 -    ../clang/include/clang/Basic/TargetOptions.h
    316 -    ../clang/include/clang/Basic/TargetInfo.h
    316 -    ../clang/include/clang/Basic/TargetCXXABI.h
    316 -    ../clang/include/clang/Basic/OpenCLOptions.h
    316 -    ../clang/include/clang/Basic/OpenCLExtensions.def
    302 -    ../llvm/include/llvm/Target/TargetOptions.h
    302 -    ../llvm/include/llvm/Support/CodeGen.h
    302 -    ../llvm/include/llvm/MC/MCTargetOptions.h
    302 -    ../llvm/include/llvm/ADT/FloatingPointMode.h
    302 -    ../clang/include/clang/Basic/XRayInstr.h
    302 -    ../clang/include/clang/Basic/DebugInfoOptions.h
    302 -    ../clang/include/clang/Basic/CodeGenOptions.h
    302 -    ../clang/include/clang/Basic/CodeGenOptions.def
    257 -    ../llvm/include/llvm/Support/Regex.h
     79 -    ../llvm/include/llvm/ADT/SmallSet.h
     68 -    MSVCSTL/include/set
     66 -    ../llvm/include/llvm/ADT/SmallPtrSet.h
     62 -    ../llvm/include/llvm/ADT/StringSwitch.h
2020-02-27 14:35:00 -08:00
Reid Kleckner 0f6959f363 Add some missing header dependencies
Unit tests are not part of `all` O_O, and I tested on Windows with
-fdelayed-template-parsing.
2020-02-27 14:32:12 -08:00
Joe Turner b26c88e3c6 [clang-tidy] Store all ranges in clang::tooling::Diagnostic
Summary: Instead of dropping all the ranges associated with a Diagnostic when
converting them to a ClangTidy error, instead attach them to the ClangTidyError,
so they can be consumed by other APIs.

Patch by Joe Turner <joturner@google.com>.
Differential Revision: https://reviews.llvm.org/D69782
2020-02-27 19:39:42 +01:00
Jonathan Coe 7dfe0cc7f5 [clang-format] Recognize C# named argument colons as a token type
Summary:
No longer merge 'name' and ':' into a single token.

Ensure that line breaks cannot be placed before or after a named-argument colon.

Ensure that no space is inserted before a named-argument colon.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75244
2020-02-27 13:47:29 +00:00
Jonathan Coe 548e540d2c [clang-format] Handle commas in [] in C#
Summary:
Respect setting `SpacesInSquareBrackets` for commas in square brackets in C# code.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75182
2020-02-27 11:49:30 +00: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
Jonathan Coe e8c5fea243 [clang-format] Special handling of spaces for C# code
Summary:
Ensure that there are spaces around braces '{', '}'.

Ensure that there is a space before and after '=>'.

Ensure that 'async' and 'when' are considered as keywords when inserting spaces.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D75129
2020-02-26 15:27:03 +00:00
Yitzhak Mandelbaum 38b4516de8 [libTooling] Add function to determine associated text of a declaration.
Summary:
Second attempt -- the first was reverted in commit 0e480b39c6, because of test breakages. This revision fixes the cause of the test breakages.

Original description follows:
This patch adds `getAssociatedRange` which, for a given decl, computes preceding
and trailing text that would conceptually be associated with the decl by the
reader. This includes comments, whitespace, and separators like ';'.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72153
2020-02-26 09:56:48 -05:00
Kadir Cetinkaya 8c2cf499e6
[clang][Tooling] Add a way to tokenize a FileRange
Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74962
2020-02-26 13:50:41 +01:00
Nico Weber 0e480b39c6 Revert "[libTooling] Add function to determine associated text of a declaration."
This reverts commit 9c54f6154f.
Breaks two tests on Windows, see e.g.
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/14505/steps/stage%201%20check/logs/stdio
2020-02-25 19:21:52 -05:00
Yitzhak Mandelbaum 9c54f6154f [libTooling] Add function to determine associated text of a declaration.
Summary:
This patch adds `getAssociatedRange` which, for a given decl, computes preceding
and trailing text that would conceptually be associated with the decl by the
reader. This includes comments, whitespace, and separators like ';'.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72153
2020-02-25 16:37:20 -05:00
Haojian Wu 7b65886ec2 Make builtbot happy.
Disable the failing rename test, it should not be failed, needs further
investigation.
2020-02-25 17:04:38 +01:00
Jonathan Coe 2bd6974aaa [clang-format] Wrap lines for C# property accessors
Summary: Ensure that auto-implemented properties `{ get; private set }` are wrapped on to one line for C# code.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75006
2020-02-25 14:23:47 +00:00
Balázs Kéri 7b6168e7be [ASTImporter] Improved variable template redecl chain handling.
Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74720
2020-02-25 14:48:37 +01: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
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
Jonathan Coe a11ff39ba2 [clang-format] Merge name and colon into a single token for C# named arguments
Summary:
Merge 'argumentName' and ':' into a single token in foo(argumentName: bar).

Add C# named argument as a token type.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74894
2020-02-20 19:23:38 +00:00
Alexander Lanin 709fd989b6 [clang-tidy] fix readability-redundant-member-init auto-fix of Function-try-block
Summary: This fixes https://bugs.llvm.org/show_bug.cgi?id=39310

Reviewers: malcolm.parsons, ioeric

Reviewed By: malcolm.parsons

Subscribers: xazax.hun

Tags: #clang-format, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D74800
2020-02-19 23:04:05 +00:00
Yitzhak Mandelbaum 523cae324d [libTooling] Add option for `buildAST` to report diagnostics.
Summary:
Currently, `buildAST[WithArgs]` either succeeds or fails.  This patch adds
support for the caller to pass a `DiagnosticConsumer` to receive all relevant
diagnostics.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74763
2020-02-18 09:11:51 -05:00
Raphael Isemann a37734f643 [ASTImporter] Prevent the ASTImporter from creating multiple main FileIDs.
Summary:
When importing the main FileID the ASTImporter currently gives it no include location. This means
that any SourceLocations produced for this FileID look to Clang as if they are coming from the
main FileID (as the main FileID has no include location).

Clang seems to expect that there is only one main FileID in one translation unit (which makes sense
during normal compilation), so this behavior leads to several problems when producing diagnostics,
one being that when calling `SourceManager::isBeforeInTranslationUnit` on two SourceLocations
that come from two different ASTContext instances, Clang fails to sort the SourceLocations as
the include chains of the FileIDs don't end up in a single FileID. This causes that Clang crashes
with "Unsortable locations found" in this function.

This patch gives any imported main FileIDs the main FileID of the To ASTContext as its include
location. This allows Clang to sort all imported SourceLocations as now all include chains point
to the main FileID of the To ASTContext. The exact include location is currently set to the start
of the To main file (just because that should always be a valid SourceLocation).

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

Reviewed By: martong, a_sidorin, shafik

Subscribers: balazske, rnkovacs, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74542
2020-02-18 08:37:26 +01:00
Haojian Wu af8b0cd58d [clang][Index] Visit the default parameter arguements in libindex.
Summary:
We are missing the default parmeter arguments when IndexFunctionLocals
is true.

Fixes https://github.com/clangd/clangd/issues/285.

Reviewers: kadircet

Subscribers: kristof.beyls, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74610
2020-02-17 16:45:04 +01:00
Balázs Kéri d4741c44ab [ASTImporter] Added visibility check for scoped enums.
Summary:
ASTImporter makes now difference between C++11 scoped enums with same
name in different translation units if these are not visible outside.
Enum declarations are linked into decl chain correctly.

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

Reviewed By: shafik, a_sidorin

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74554
2020-02-17 14:34:13 +01:00
Kadir Cetinkaya 84240e0db8
[clang][Index] Introduce a TemplateParm SymbolKind
Summary:
Currently template parameters has symbolkind `Unknown`. This patch
introduces a new kind `TemplateParm` for templatetemplate, templatetype and
nontypetemplate parameters.

Also adds tests in clangd hover feature.

Reviewers: sammccall

Subscribers: kristof.beyls, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73696
2020-02-14 13:20:34 +01:00
Kadir Cetinkaya c45fb35b5e
[clang][DeclPrinter] Implement visitors for {TemplateType,NonTypeTemplate}Parms
Reviewers: sammccall, hokein

Subscribers: kristof.beyls, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73693
2020-02-14 13:20:34 +01:00
Wawha fa0118e6e5 [clang-format] Add new option BeforeLambdaBody in Allman style.
This option add a line break then a lambda is inside a function call.

Reviewers : djasper, klimek, krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D44609
2020-02-13 22:16:41 +01: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
Yuanfang Chen 4ad7685258 Revert "Revert "Reland "[Support] make report_fatal_error `abort` instead of `exit`"""
This reverts commit 80a34ae311 with fixes.

Previously, since bots turning on EXPENSIVE_CHECKS are essentially turning on
MachineVerifierPass by default on X86 and the fact that
inline-asm-avx-v-constraint-32bit.ll and inline-asm-avx512vl-v-constraint-32bit.ll
are not expected to generate functioning machine code, this would go
down to `report_fatal_error` in MachineVerifierPass. Here passing
`-verify-machineinstrs=0` to make the intent explicit.
2020-02-13 10:16:06 -08:00
Yuanfang Chen 17122ec10a Revert "Revert "Revert "Reland "[Support] make report_fatal_error `abort` instead of `exit`""""
This reverts commit bb51d24330.
2020-02-13 10:08:05 -08:00
Yuanfang Chen bb51d24330 Revert "Revert "Reland "[Support] make report_fatal_error `abort` instead of `exit`"""
This reverts commit 80a34ae311 with fixes.

On bots llvm-clang-x86_64-expensive-checks-ubuntu and
llvm-clang-x86_64-expensive-checks-debian only,
llc returns 0 for these two tests unexpectedly. I tweaked the RUN line a little
bit in the hope that LIT is the culprit since this change is not in the
codepath these tests are testing.
llvm\test\CodeGen\X86\inline-asm-avx-v-constraint-32bit.ll
llvm\test\CodeGen\X86\inline-asm-avx512vl-v-constraint-32bit.ll
2020-02-13 10:02:53 -08:00
Yuanfang Chen 80a34ae311 Revert "Reland "[Support] make report_fatal_error `abort` instead of `exit`""
This reverts commit rGcd5b308b828e, rGcd5b308b828e, rG8cedf0e2994c.

There are issues to be investigated for polly bots and bots turning on
EXPENSIVE_CHECKS.
2020-02-11 20:41:53 -08:00
Yuanfang Chen 8cedf0e299 Reland "[Support] make report_fatal_error `abort` instead of `exit`"
Summary:
Reland D67847 after D73742 is committed. Replace `sys::Process::Exit(1)`
with `abort` in `report_fatal_error`.

After this patch, for tools turning on `CrashRecoveryContext`,
crash handler installed by `CrashRecoveryContext` is called unless
they installed a non-returning handler using `llvm::install_fatal_error_handler`
like `cc1_main` currently does.

Reviewers: rnk, MaskRay, aganea, hans, espindola, jhenderson

Subscribers: jholewinski, qcolombet, dschuff, jyknight, emaste, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, steven_wu, rogfer01, MartinMosbeck, brucehoult, the_o, dexonsmith, PkmX, rupprecht, jocewei, jsji, Jim, dmgreen, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, kerbowa, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74456
2020-02-11 18:20:40 -08:00
Justin Lebar 027eb71696 Use std::foo_t rather than std::foo in clang.
Summary: No functional change.

Reviewers: bkramer, MaskRay, martong, shafik

Subscribers: martong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74414
2020-02-11 10:37:08 -08:00
Ben Langmuir 2ac0c4b46e [DirectoryWatcher] Fix misuse of FSEvents API and data race
I observed two bugs in the DirectoryWatcher on macOS

1. We were calling FSEventStreamStop and FSEventStreamInvalidate before
we called FSEventStreamStart and FSEventStreamSetDispatchQueue, if the
DirectoryWatcher was destroyed before the initial async work was done.
This violates the requirements of the FSEvents API.

2. Calls to Receiver could race between the initial work and the
invalidation during destruction.

The second issue is easier to see when using TSan.

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

rdar://59215667
2020-02-11 09:25:38 -08:00
Jonathan Coe b46f925d68 [clang-format] Improve handling of C# attributes
Summary:
C# attributes can appear on classes and methods, in which case they should go on their own line, or on method parameters in which case
they should be left inline.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: klimek

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74265
2020-02-11 12:00:17 +00:00
Jonathan Coe f40a7972cb [clang-format] Do not merge short C# class definitions into one line
Summary: Skip access specifiers before record definitions when deciding whether
or not to wrap lines so that C# class definitions do not get wrapped into a
single line.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74050
2020-02-05 17:38:33 +00:00
Jonathan Coe ca1fd460f1 [clang-format] Do not treat C# attribute targets as labels
Summary: Merge '[', 'target' , ':' into a single token for C# attributes to
prevent the target from being seen as a label.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74043
2020-02-05 17:30:24 +00:00
Jonathan Coe 50d8977c45 [clang-format] Allow a comment to follow a C# attribute specifier
Summary: Add comments to the list of tokens that can follow the ']' at the end of a C# attribute specifier to prevent comments after attribute specifiers from being formatted as continuations.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73977
2020-02-04 19:00:54 +00: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
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 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
mydeveloperday 70c98671fa [clang-format] Add option for not breaking line before ObjC params
Summary:
From `clang-format` version 3.7.0 and up, , there is no way to keep following format of ObjectiveC block:
```
- (void)_aMethod
{
    [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
        u = c;
    }]
}
```
Regardless of the change in `.clang-format` configuration file, all parameters will be lined up so that colons will be on the same column, like following:
```
- (void)_aMethod
{
    [self.test1 t:self
                w:self
         callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
             u = c;
         }]
}
```

Considering with ObjectiveC, the first code style is cleaner & more readable for some people, I've added a config option: `ObjCDontBreakBeforeNestedBlockParam` (boolean) so that if it is enable, the first code style will be favored.

Reviewed By: MyDeveloperDay

Patch By: ghvg1313

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D70926
2020-02-01 17:39:34 +00:00
Jonathan Coe 0bb60e29f1 [clang-format] Fixes for spaces around C# object initializers
Summary: Fix spaces around typename and [] in C# object initializers.

Reviewers: MyDeveloperDay, klimek, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D72401
2020-01-31 14:22:01 +00:00
Charusso 38ab3b876b [analyzer] CheckerContext: Make the Preprocessor available
Summary:
This patch hooks the `Preprocessor` trough `BugReporter` to the
`CheckerContext` so the checkers could look for macro definitions.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D69731
2020-01-30 17:05:52 +01:00
Jonathan Coe f9f0919db7 [clang-format] Improve support for multiline C# strings
Reviewers: krasimir

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73622
2020-01-30 13:45:48 +00: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
Jonas Devlieghere 509e21a1b9 [clang] Replace SmallStr.str().str() with std::string conversion operator.
Use the std::string conversion operator introduced in
d7049213d0.
2020-01-29 21:27:46 -08:00
Sanne Wouda 4ec2a26732 Fix clang test build 2020-01-29 13:03:27 +00:00
Karasev Nikita d5dfd1350e Add TagDecl AST matcher 2020-01-29 07:58:31 -05:00
Martin Probst a324fcf1ae clang-format: insert trailing commas into containers.
Summary:
This change adds an option to insert trailing commas into container
literals. For example, in JavaScript:

    const x = [
      a,
      b,
       ^~~~~ inserted if missing.
    ]

This is implemented as a seperate post-processing pass after formatting
(because formatting might change whether the container literal does or
does not wrap). This keeps the code relatively simple and orthogonal,
though it has the notable drawback that the newly inserted comma is not
taken into account for formatting decisions (e.g. it might exceed the 80
char limit). To avoid exceeding the ColumnLimit, a comma is only
inserted if it fits into the limit.

Trailing comma insertion conceptually conflicts with argument
bin-packing: inserting a comma disables bin-packing, so we cannot do
both. clang-format rejects FormatStyle configurations that do both with
this change.

Reviewers: krasimir, MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang
2020-01-29 13:23:54 +01:00
Benjamin Kramer 4e3f4f03f3 [ASTMatchers] StringRef'ify hasName
This was just inconvenient, and we make a copy anyways.
2020-01-29 10:53:08 +01:00
Benjamin Kramer 757bdc64d3 Fix clang unnittest build with GCC 5 2020-01-29 10:30:36 +01:00
Benjamin Kramer ddf77f10a3 One more batch of things found by g++ 6 2020-01-29 00:50:34 +01: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
Jonathan Coe 9d212e83e9 [clang-format] Handle quotes and escaped braces in C# interpolated strings
Summary:
This addresses issues raised in https://bugs.llvm.org/show_bug.cgi?id=44454.

There are outstanding issues with multi-line verbatim strings in C# that will be addressed in a follow-up PR.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir, MyDeveloperDay

Subscribers: MyDeveloperDay

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73492
2020-01-28 14:46:27 +00: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