Commit Graph

4463 Commits

Author SHA1 Message Date
Björn Schäpers 25f753c51e [clang-format] Add possibility to be based on parent directory
This allows the define BasedOnStyle: InheritParentConfig and then
clang-format looks into the parent directories for their
.clang-format and takes that as a basis.

Differential Revision: https://reviews.llvm.org/D93844
2021-02-14 19:56:10 +01:00
Haojian Wu e159a3ced4 [Syntax] Remove a strict valid source location assertion for TypeLoc.
The EndLoc of a type loc can be invalid for broken code.

Also extend the existing test to support error code with `error-ok`
annotation.

Differential Revision: https://reviews.llvm.org/D96261
2021-02-11 09:53:52 +01:00
Haojian Wu 35a5e88390 [Syntax] NFC, Simplify a test with annotations 2021-02-11 09:49:06 +01:00
Jan Svoboda 40c261c41c [clang][cli] Generate and round-trip language options
This patch implements generation of remaining language options and tests it by performing parse-generate-parse round trip (on by default for assert builds, off otherwise).

This patch also correctly reports failures in `parseSanitizerKinds`, which is necessary for emitting diagnostics when an invalid sanitizer is passed to `-fsanitize=` during round-trip.

This patch also removes TableGen marshalling classes from two options:
* `fsanitize_blacklist` When parsing: it's first initialized via the generated code, but then also changed by manually written code, which is confusing.
* `fopenmp` When parsing: it's first initialized via generated code, but then conditionally changed by manually written code. This is also confusing. Moreover, we need to do some extra checks when generating it, which would be really cumbersome in TableGen. (Specifically, not emitting it when `-fopenmp-simd` was present.)

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95793
2021-02-09 10:18:55 +01:00
Kadir Cetinkaya f743184911
[clang][CodeComplete] Fix crash on ParenListExprs
Fixes https://github.com/clangd/clangd/issues/676.

Differential Revision: https://reviews.llvm.org/D95935
2021-02-08 13:16:49 +01:00
Stephen Kelly ddca007a29 Add code complete support for mapAnyOf 2021-02-07 16:03:05 +00:00
Stephen Kelly 04b69d9a60 Add clang-query support for mapAnyOf
Differential Revision: https://reviews.llvm.org/D94880
2021-02-07 15:40:15 +00:00
Stephen Kelly 45e210dbeb [ASTMatchers] Make it possible to build mapAnyOf through the registry 2021-02-07 15:36:15 +00:00
Stephen Kelly d3bccdcd50 [ASTMatchers ]Make MatcherDescriptors indicate the node type they match 2021-02-07 15:13:28 +00:00
Haojian Wu 6c1a23303d [Syntax] Support condition for IfStmt.
Differential Revision: https://reviews.llvm.org/D95782
2021-02-04 09:15:30 +01:00
Stephen Kelly 9e5fc578f9 [ASTMatchers] Ignore parts of BindingDecls which are not spelled in source
Differential Revision: https://reviews.llvm.org/D95740
2021-02-02 14:23:13 +00:00
Kent Sommer a8105b3766 [clang-format] Add case aware include sorting.
Adds an option to [clang-format] which sorts headers in an alphabetical manner using case only for tie-breakers. The options is off by default in favor of the current ASCIIbetical sorting style.

Reviewed By: MyDeveloperDay, curdeius, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D95017
2021-02-02 15:12:27 +01:00
Stephen Kelly 467a045601 [ASTMatchers] Add matchers for decomposition decls
Differential Revision: https://reviews.llvm.org/D95739
2021-02-02 14:11:02 +00:00
Stephen Kelly d6a06365cf [ASTMatchers] Fix matching after generic top-level matcher
With a matcher like

  expr(anyOf(integerLiteral(equals(42)), unless(expr())))

and code such as

  struct B {
    B(int);
  };

  B func1() { return 42; }

the top-level expr() would match each of the nodes which are not spelled
in the source and then ignore-traverse to match the integerLiteral node.
This would result in multiple results reported for the integerLiteral.

Fix that by only running matching logic on nodes which are not skipped
with the top-level matcher.

Differential Revision: https://reviews.llvm.org/D95735
2021-02-02 13:31:05 +00:00
Björn Schäpers 772eb24e00 [clang-format] Add option to control the spaces in a line comment
Differential Revision: https://reviews.llvm.org/D92257
2021-02-01 22:48:50 +01:00
Stephen Kelly bb57a3422a Fix traversal with hasDescendant into lambdas
Differential Revision: https://reviews.llvm.org/D95607
2021-01-30 13:57:41 +00:00
Stephen Kelly 79125085f1 [ASTMatchers] Fix traversal below range-for elements
Differential Revision: https://reviews.llvm.org/D95562
2021-01-30 13:47:14 +00:00
Björn Schäpers 4ad41f1daf Revert "[clang-format] Add option to control the spaces in a line comment"
This reverts commit 078f30e04d.
2021-01-29 09:30:52 +01:00
Björn Schäpers 078f30e04d [clang-format] Add option to control the spaces in a line comment
Differential Revision: https://reviews.llvm.org/D92257
2021-01-29 07:00:08 +01:00
Stephen Kelly 43cc4f1500 Ensure that we traverse non-op() method bodys of lambdas
Differential Revision: https://reviews.llvm.org/D95644
2021-01-29 00:49:28 +00:00
Stephen Kelly 3c79734f29 [ASTMatchers] Add invocation matcher
Differential Revision: https://reviews.llvm.org/D94865
2021-01-28 20:47:09 +00:00
Stephen Kelly 6f0df3cddb [ASTMatchers] Avoid pathological traversal over nested lambdas
Differential Revision: https://reviews.llvm.org/D95573
2021-01-28 20:45:45 +00:00
Marek Kurdej e3713f156b [clang-format] Avoid considering include directive as a template closer.
This fixes a bug [[ http://llvm.org/PR48891 | PR48891 ]] introduced in D93839 where:
```
#include <stdint.h>
namespace rep {}
```
got formatted as
```
#include <stdint.h>
namespace rep {
}
```

Reviewed By: MyDeveloperDay, leonardchan

Differential Revision: https://reviews.llvm.org/D95479
2021-01-27 09:15:30 +01:00
Duncan P. N. Exon Smith 8afabff6b1 Frontend: Fix memory leak in CompilerInstance::setVerboseOutputStream
Found this memory leak in `CompilerInstance::setVerboseOutputStream` by
inspection; it looks like this wasn't previously exercised, since it was
never called twice.

Differential Revision: https://reviews.llvm.org/D93249
2021-01-26 14:57:23 -08:00
Marek Kurdej 6d5c1cd2ab Revert "[clang-format] add case aware include sorting"
This reverts commit 3395a336b0 as there was a post-merge doubt about option naming and type.
2021-01-26 11:58:56 +01:00
Jan Svoboda 2154cffdc2 [clang][cli] Store LangStandard::Kind in LangOptions
The `LangStandard::Kind` parsed from command line arguments is used to set up some `LangOption` defaults, but isn't stored anywhere.

To be able to generate `-std=` (in future patch), we need `CompilerInvocation` to not forget it.

This patch demonstrates another use-case: using `LangStd` to set up defaults of marshalled options.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95342
2021-01-26 09:05:43 +01:00
Albertas Vyšniauskas 60bf5826cf [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier
Add new option called InsertEmptyLineBeforeAccessModifier. Empty line
before access modifier is inerted if this option is set to true (which
is the default value, because clang-format always inserts empty lines
before access modifiers), otherwise empty lines are removed.

Fixes issue #16518.

Differential Revision: https://reviews.llvm.org/D93846
2021-01-25 21:02:41 +01:00
Lukas Barth 3395a336b0 [clang-format] add case aware include sorting
* Adds an option to [clang-format] which sorts
  headers in an alphabetical manner using case
  only for tie-breakers. The options is off by
  default in favor of the current ASCIIbetical
  sorting style.

Reviewed By: curdeius, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D95017
2021-01-25 18:53:22 +01:00
Lukas Barth 256314711f [clang-format] Add the possibility to align assignments spanning empty lines or comments
Currently, empty lines and comments break alignment of assignments on consecutive
lines. This makes the AlignConsecutiveAssignments option an enum that allows controlling
whether empty lines or empty lines and comments should be ignored when aligning
assignments.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, tinloaf

Differential Revision: https://reviews.llvm.org/D93986
2021-01-25 09:41:50 +01:00
Marek Kurdej 7b9d88ab38 Revert "[clang-format] Add the possibility to align assignments spanning empty lines or comments"
This reverts commit f00a20e51c.
2021-01-25 09:40:46 +01:00
Marek Kurdej f00a20e51c [clang-format] Add the possibility to align assignments spanning empty lines or comments
Currently, empty lines and comments break alignment of assignments on consecutive
lines. This makes the AlignConsecutiveAssignments option an enum that allows controlling
whether empty lines or empty lines and comments should be ignored when aligning
assignments.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, tinloaf

Differential Revision: https://reviews.llvm.org/D93986
2021-01-25 09:36:55 +01:00
Balázs Kéri 98a8344895 [clang][ASTImporter] Add support for importing CXXFoldExpr.
Reviewed By: shafik, martong

Differential Revision: https://reviews.llvm.org/D94786
2021-01-22 15:20:55 +01:00
Stephen Kelly 8000c77853 Make it possible to store a ASTNodeKind in VariantValue
Differential Revision: https://reviews.llvm.org/D94878
2021-01-20 15:44:45 +00:00
Stephen Kelly 0cd0eb6e0a Add API to retrieve a clade kind from ASTNodeKind
Differential Revision: https://reviews.llvm.org/D94877
2021-01-19 22:51:30 +00:00
Stephen Kelly ecf696641e [ASTMatchers] Allow use of mapAnyOf in more contexts
Add an operator overload to ArgumentAdaptingMatcherFunc to allow use of
mapAnyOf within hasAncestor, hasParent etc.

Differential Revision: https://reviews.llvm.org/D94864
2021-01-19 22:10:09 +00:00
Björn Schäpers cbdde495ba [clang-format] Apply Allman style to lambdas
Differential Revision: https://reviews.llvm.org/D94906
2021-01-19 18:17:01 +01:00
Björn Schäpers bcc1dee600 [clang-format] Add StatementAttributeLikeMacros option
This allows to ignore for example Qts emit when
AlignConsecutiveDeclarations is set, otherwise it is parsed as a type
and it results in some misformating:

unsigned char MyChar = 'x';
emit          signal(MyChar);

Differential Revision: https://reviews.llvm.org/D93776
2021-01-18 06:54:31 +01:00
mydeveloperday 00dc97f167 [clang-format] PR48594 BraceWrapping: SplitEmptyRecord ignored for templates
https://bugs.llvm.org/show_bug.cgi?id=48594

Empty or small templates were not being treated the same way as small classes especially when SplitEmptyRecord was set to true

This revision aims to help this by identifying a case when we should try not to merge the lines together

Reviewed By: curdeius, JohelEGP

Differential Revision: https://reviews.llvm.org/D93839
2021-01-17 11:14:33 +00:00
mydeveloperday 9af03864df [clang-format] Revert e9e6e3b34a
Reverting {D92753} due to issues with #pragma indentation in #ifdef/endif structure
2021-01-17 11:07:31 +00:00
Stephen Kelly b765eaf9a6 [ASTMatchers] Add support for CXXRewrittenBinaryOperator
Differential Revision: https://reviews.llvm.org/D94130
2021-01-16 13:44:22 +00:00
Stephen Kelly e810e95e4b [ASTMatchers] Add binaryOperation matcher
This is a simple utility which allows matching on binaryOperator and
cxxOperatorCallExpr. It can also be extended to support
cxxRewrittenBinaryOperator.

Add generic support for MapAnyOfMatchers to auto-marshalling functions.

Differential Revision: https://reviews.llvm.org/D94129
2021-01-16 13:44:09 +00:00
Stephen Kelly dbe056c2e3 [ASTMatchers] Make cxxOperatorCallExpr matchers API-compatible with n-ary operators
This makes them composable with mapAnyOf().

Differential Revision: https://reviews.llvm.org/D94128
2021-01-16 12:53:11 +00:00
Stephen Kelly a7101450a4 [ASTMatchers] Add mapAnyOf matcher
Make it possible to compose a matcher for different base nodes.

This accepts one or more node matcher functors and zero or more
matchers, composing the latter into the former.

This allows composing of matchers where the same inner matcher name is
used for the same concept, but with a different node functor. Currently,
there is a limitation that the nodes must be in the same "clade", so
while

  mapAnyOf(ifStmt, forStmt).with(hasBody(stmt()))

can be used, functionDecl can not be added to the tuple.

It is possible to use this in clang-query, but it will require changes
to the QueryParser, so is deferred to a future review.

Differential Revision: https://reviews.llvm.org/D94127
2021-01-16 12:53:11 +00:00
Stephan Bergmann 215ed9b33c Adapt CastExpr::getSubExprAsWritten to ConstantExpr
Differential Revision: https://reviews.llvm.org/D87030
2021-01-12 09:41:03 +01:00
Jan Svoboda 97100646d1 Reapply "[clang][cli] Port DiagnosticOpts to new option parsing system"
This reverts commit 8e3e148c

This commit fixes two issues with the original patch:
* The sanitizer build bot reported an uninitialized value. This was caused by normalizeStringIntegral not returning None on failure.
* Some build bots complained about inaccessible keypaths. To mitigate that, "this->" was added back to the keypath to restore the previous behavior.
2021-01-11 10:05:53 +01:00
Rafał Jelonek 89878e8c96 [clang-format] Find main include after block ended with #pragma hdrstop
Find main include in first include block not ended with #pragma hdrstop

Reviewed By: curdeius

Differential Revision: https://reviews.llvm.org/D94217
2021-01-11 09:49:34 +01:00
Rafał Jelonek 7473940bae [clang-format] turn on formatting after "clang-format on" while sorting includes
Formatting is not active after "clang-format on" due to merging lines while formatting is off. Also, use trimmed line. Behaviour with LF is different than with CRLF.

Reviewed By: curdeius, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D94206
2021-01-11 09:41:15 +01:00
Rafał Jelonek ee27c767bd [clang-format] Skip UTF8 Byte Order Mark while sorting includes
If file contain BOM then first instruction (include or clang-format off) is ignored

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D94201
2021-01-11 09:32:55 +01:00
Jan Svoboda 8e3e148c88 Revert "[clang][cli] Port DiagnosticOpts to new option parsing system"
This reverts commit 8e3230ff
2021-01-08 10:53:12 +01:00
Jan Svoboda 8e3230ffa3 [clang][cli] Port DiagnosticOpts to new option parsing system
This patch introduces additional infrastructure necessary to accommodate DiagnosticOptions.

DiagnosticOptions are unique in that they are parsed by the same function in cc1 AND in the Clang driver. The call to the parsing function from the driver occurs early on in the compilation process, where no proper DiagnosticEngine exists, because the diagnostic options (passed through command line) are not known yet.

To preserve the current behavior, we need to be able to selectively parse:
* all options (for -cc1),
* only diagnostic options (for driver).

This patch achieves that in the following way:
* new MacroPrefix field is added to the Option TableGen class,
* new IsDiag TableGen mixin sets MacroPrefix to "DIAG_",
* TableGen backend serializes option records into a macro with the prefix,
* CompilerInvocation parse/generate methods define the [DIAG_]OPTION_WITH_MARSHALLING macros to handle diagnostic options separately.

Depends on D93700, D93701 & D93702.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D84673
2021-01-08 10:44:22 +01:00