Commit Graph

4350 Commits

Author SHA1 Message Date
Arthur O'Dwyer e181a6aedd s/instantate/instantiate/ throughout. NFCI.
The static_assert in "libcxx/include/memory" was the main offender here,
but then I figured I might as well `git grep -i instantat` and fix all
the instances I found. One was in user-facing HTML documentation;
the rest were in comments or tests.
2020-12-01 22:13:40 -05:00
Mark Nauwelaerts 1e4d6d1c1f [clang-format] Add new option PenaltyIndentedWhitespace
Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D90534
2020-12-01 23:59:44 +01:00
Jan Svoboda 2b84efa000 [clang][cli] Port Frontend option flags to new option parsing system
Depends on D91861.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83697
2020-12-01 10:02:08 +01:00
Jan Svoboda 88ab38449b [clang][cli] Split DefaultAnyOf into a default value and ImpliedByAnyOf
This makes the options API composable, allows boolean flags to imply non-boolean values and makes the code more logical (IMO).

Differential Revision: https://reviews.llvm.org/D91861
2020-12-01 09:50:11 +01:00
Duncan P. N. Exon Smith 94f537c6b2 Remove dead code added in ac49500cd0, NFC
This was a copy/paste bug; `M0` is never referenced later.
2020-11-30 14:50:46 -08:00
Duncan P. N. Exon Smith 1b042de5b2 FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRef
Add `FileEntryRef::getDir`, which returns a `DirectoryEntryRef`. This
includes a few changes:

- Customize `OptionalStorage` so that `Optional<DirectoryEntryRef>` is
  pointer-sized (like the change made to `Optional<FileEntryRef>`).
  Factored out a common class, `FileMgr::MapEntryOptionalStorage`, to
  reduce the code duplication.
- Store an `Optional<DirectoryEntryRef>` in `FileEntryRef::MapValue`.
  This is set if and only if `MapValue` has a real `FileEntry`.
- Change `FileManager::getFileRef` and `getVirtualFileRef` to use
  `getDirectoryRef` and store it in the `StringMap` for `FileEntryRef`.

Differential Revision: https://reviews.llvm.org/D90484
2020-11-30 14:50:46 -08:00
Yitzhak Mandelbaum fdff677a95 [libTooling] Remove deprecated Clang Transformer declarations
A number of declarations were leftover after the move from `clang::tooling` to
`clang::transformer`. This patch removes those declarations and upgrades the
handful of references to the deprecated declarations.

Differential Revision: https://reviews.llvm.org/D92340
2020-11-30 20:15:26 +00:00
Gabor Marton 70eb2ce395 [ASTImporter] Support import of CXXDeductionGuideDecl
CXXDeductionGuideDecl is a FunctionDecl, but its constructor should be called
appropriately, at least to set the kind variable properly.

Differential Revision: https://reviews.llvm.org/D92109
2020-11-30 17:55:25 +01:00
Raphael Isemann 89c1a7a67d [ASTImporter] Import the default argument of NonTypeTemplateParmDecl
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching NonTypeTemplateParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92106
2020-11-27 11:40:07 +01:00
Raphael Isemann 3f6c856bb5 [ASTImporter] Import the default argument of TemplateTypeParmDecl
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching TemplateTypeParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Also updates several LLDB tests that now as intended omit the default template
arguments of several std templates.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92103
2020-11-26 18:01:30 +01:00
Raphael Isemann 39a5dd164c [ASTImporter] Import the default argument of TemplateTemplateParmDecl
Same idea as in D92103 and D92106, but I realised after creating those reviews that there are
also TemplateTemplateParmDecls that can have default arguments, so here's hopefully the
last patch for default template arguments.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92119
2020-11-26 15:12:45 +01:00
Raphael Isemann 0c926e6d24 [ASTImporter] Make the Import() return value consistent with the map of imported decls when merging ClassTemplateSpecializationDecls
When importing a `ClassTemplateSpecializationDecl` definition into a TU with a matching
`ClassTemplateSpecializationDecl` definition and a more recent forward decl, the ASTImporter
currently will call `MapImported()` for the definitions, but will return the forward declaration
from the `ASTImporter::Import()` call.

This is triggering some assertions in LLDB when we try to fully import some DeclContexts
before we delete the 'From' AST. The returned 'To' Decl before this patch is just the most recent
forward decl but that's not the Decl with the definition to which the ASTImporter will import
the child declarations.

This patch just changes that the ASTImporter returns the definition that the imported Decl was
merged with instead of the found forward declaration.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92016
2020-11-24 23:46:18 +01:00
Stephen Kelly f052cf494f Update mode used in traverse() examples
traverse() predates the IgnoreUnlessSpelledInSource mode. Update example
and test code to use the newer mode.

Differential Revision: https://reviews.llvm.org/D91917
2020-11-23 14:27:48 +00:00
Stephen Kelly 72a9f365e9 Remove automatic traversal from forEach matcher
Differential Revision: https://reviews.llvm.org/D91916
2020-11-23 14:27:47 +00:00
Samuel Giddins 244022a3cd Don’t break before nested block param when prior param is not a block
Add ScopedTrace to verify methods in FormatTestObjC
Add tests from D17700

Reviewed By: keith, kastiglione

Differential Revision: https://reviews.llvm.org/D91669
2020-11-20 15:16:04 -08:00
Yitzhak Mandelbaum 88e6208562 [libTooling] Update Transformer's `node` combinator to include the trailing semicolon for decls.
Currently, `node` only includes the semicolon for (some) statements. However,
declarations have the same issue of (potentially) trailing semicolons, so `node`
should behave the same for them.

Differential Revision: https://reviews.llvm.org/D91872
2020-11-20 18:11:50 +00:00
Stephen Kelly bcaa198949 Remove unportable test
The default content of translation unit varies too much between
platforms.
2020-11-18 12:42:07 +00:00
Stephen Kelly ef1a4169e8 [Transformer] Split ForStmt test into two
It is apparently not possible to have two rewrites in one gtest function
because atomic changes in the test harness accumulate.
2020-11-17 18:16:10 +00:00
Stephen Kelly 6ef6beaa57 Comment out new test while I figure out what is wrong with it 2020-11-17 17:48:48 +00:00
Stephen Kelly 4cadb66b49 [AST] Update matchers to be traverse-aware
Don't match Stmt or Decl nodes not spelled in the source when using
TK_IgnoreUnlessSpelledInSource.  This prevents accidental modification
of source code at incorrect locations.

Differential Revision: https://reviews.llvm.org/D90984
2020-11-17 16:31:08 +00:00
Stephen Kelly 246b428fb3 [AST] Ignore implicit nodes in IgnoreUnlessSpelledInSource mode
Update the ASTNodeTraverser to dump only nodes spelled in source.  There
are only a few which need to be handled, but Decl nodes for which
isImplicit() is true are handled together.

Update the RAV instances used in ASTMatchFinder to ignore the nodes too.
As with handling of template instantiations, it is necessary to allow
the RAV to process the implicit nodes because they need to be visitable
before the first traverse() matcher is encountered.  An exception to
this is in the MatchChildASTVisitor, because we sometimes wish to make a
node matchable but make its children not-matchable.  This is the case
for defaulted CXXMethodDecls for example.

Extend TransformerTests to illustrate the kinds of problems that can
arise when performing source code rewriting due to matching implicit
nodes.

This change accounts for handling nodes not spelled in source when using
direct matching of nodes, and when using the has() and hasDescendant()
matchers.  Other matchers such as
cxxRecordDecl(hasMethod(cxxMethodDecl())) still succeed for
compiler-generated methods for example after this change.  Updating the
implementations of hasMethod() and other matchers is for a follow-up
patch.

Differential Revision: https://reviews.llvm.org/D90982
2020-11-17 16:30:07 +00:00
Vassil Vassilev 54e655b3f8 Reland "Move the test compiler setup in a common place. NFCI"
Original commit message: "
Move the test compiler setup in a common place. NFCI

This patch reduces the copy paste in the unittest/CodeGen folder by moving the
common compiler setup phase in a header file.

Differential revision: https://reviews.llvm.org/D91061
"

This patch includes a fix for the memory leaks pointed out by @vitalybuka
2020-11-16 13:22:10 +00:00
Vitaly Buka 6c185acfff Revert "Move the test compiler setup in a common place. NFCI"
There is memory leaks

This reverts commit 23cc838099.
This reverts commit 888d06dfb8.
2020-11-16 04:21:28 -08:00
Vassil Vassilev 23cc838099 Add forgotten in 888d06d file. 2020-11-14 21:32:23 +00:00
Vassil Vassilev 888d06dfb8 Move the test compiler setup in a common place. NFCI
This patch reduces the copy paste in the unittest/CodeGen folder by moving the
common compiler setup phase in a header file.

Differential revision: https://reviews.llvm.org/D91061
2020-11-14 21:30:30 +00:00
Krasimir Georgiev 77b4841169 [clang-format] do not break before @tags in JS comments
In JavaScript breaking before a `@tag` in a comment puts it on a new line, and
machinery that parses these comments will fail to understand such comments.

This adapts clang-format to not break before `@`. Similar functionality exists
for not breaking before `{`.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D91078
2020-11-11 12:27:15 +01:00
Martin Probst 16212b8b3e clang-format: [JS] support new assignment operators.
Before:

    a && = b;

After:

    a &&= b;

These operators are new additions in ES2021.

Differential Revision: https://reviews.llvm.org/D91132
2020-11-10 09:26:46 +01:00
Jan Svoboda dbfa69c502 Port some floating point options to new option marshalling infrastructure
This ports a number of OpenCL and fast-math flags for floating point
over to the new marshalling infrastructure.

As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to
imply them, via `DefaultAnyOf<>`. For example:
```
defm signed_zeros : OptOutFFlag<"signed-zeros", ...,
  "LangOpts->NoSignedZero",
  DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>;
```
defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`)
linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`,
but set to `true` implicitly if one of `-cl-no-signed-zeros` or
`-menable-unsafe-fp-math` is on.

Note that the initial patch was written Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D82756
2020-11-09 18:00:10 -05:00
Kirill Bobyrev 142c6f82fd
[clang] Simplify buildSyntaxTree API
Follow-up on https://reviews.llvm.org/D88553#inline-837013

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90672
2020-11-09 22:49:54 +01:00
Stephen Kelly 23f17ab5ff Fix use of directly-nested traverse() matchers 2020-11-09 19:23:17 +00:00
Stephen Kelly 121d51dc83 Fix trailing whitespace
My editor keeps on changing this and I keep having to revert it.
2020-11-09 19:12:38 +00:00
Krasimir Georgiev 7b7170fa57 [clang-format] avoid introducing multiline comments
In C++ with -Werror=comment, multiline comments are not allowed.
clang-format could accidentally introduce multiline comments when reflowing.
This adapts clang-format to not introduce multiline comments by not allowing a
break after `\`. Note that this does not apply to comment lines that already are
multiline comments, such as comments in macros.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90949
2020-11-09 15:29:09 +01:00
Stephen Kelly 4eb880439a Fix dumping of explicit template specializations
This was missing from commit 7efe07a1 (Traverse-ignore explicit template
instantiations, 2020-11-06).
2020-11-07 22:34:16 +00:00
Stephen Kelly 0d6e1251d7 Add new matchers for dependent names in templates
Differential Revision: https://reviews.llvm.org/D90767
2020-11-06 21:03:20 +00:00
Stephen Kelly 7efe07a12b Traverse-ignore explicit template instantiations
Continue to dump and match on explicit template specializations, but
omit explicit instantiation declarations and definitions.

Differential Revision: https://reviews.llvm.org/D90763
2020-11-06 15:25:59 +00:00
Krasimir Georgiev 2dbcbd357d [clang-format] do not break before { in JS comments
In JavaScript some @tags can be followed by `{`, and machinery that parses
these comments will fail to understand the comment if followed by a line break.

clang-format already handles this case by not breaking before `{` in comments.
However this was not working in cases when the column limit falls within `@tag`
or between `@tag` and `{`. This adapts clang-format for this case.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D90908
2020-11-06 10:34:10 +01:00
Raphael Isemann 659f4bd87e [clang] Add an option for hiding line numbers in diagnostics
Clang offers a `-f[no]-show-column` flag for hiding the column numbers when
printing diagnostics but there is no option for doing the same with line
numbers.

In LLDB having this option would be useful, as LLDB sometimes only knows the
file name for a SourceLocation and just assigns it the dummy line/column `1:1`.
These fake line/column numbers are confusing to the user and LLDB should be able
to tell clang to hide *both* the column and the line number when rendering text
diagnostics.

This patch adds a flag for also hiding the line numbers. It's not exposed via
the command line flags as it's most likely not very useful for any user and can
lead to ambiguous output when the user decides to only hide either the line or
the column number (where `file:1: ...` could now refer to both line 1 or column
1 depending on the compiler flags). LLDB can just access the DiagnosticOptions
directly when constructing its internal Clang instance.

The effect doesn't apply to Vi/MSVC style diagnostics because it's not defined
how these diagnostic styles would show an omitted line number (MSVC doesn't have
such an option and Vi's line mode is theory only supporting line numbers if I
understand it correctly).

Reviewed By: thakis, MaskRay

Differential Revision: https://reviews.llvm.org/D83038
2020-11-05 16:10:18 +01:00
Serge Pavlov 20b4f4f760 [Driver] Add callback to Command execution
Summary:
Object of type `Compilation` now can keep a callback that is called
after each execution of `Command`. This must simplify adaptation of
clang in custom distributions and allow facilities like collection of
execution statistics.

Reviewers: rsmith, rjmccall, Eugene.Zelenko

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78899
2020-11-05 12:21:40 +07:00
Matt Morehouse a6d15d4070 Undo Revert "Ignore template instantiations if not in AsIs mode"
MaskRay already fixed the ASan bug.
2020-11-03 13:59:01 -08:00
Matt Morehouse 72531ae6e6 Revert "Ignore template instantiations if not in AsIs mode"
This reverts commit 53df3beb62 due to
check-asan failure on the buildbot.
2020-11-03 13:57:31 -08:00
Fangrui Song 96ed6793b3 [unittest][TrasnformerTest] Fix asan stack-use-after-return 2020-11-03 12:34:45 -08:00
Nathan James b091af790f
[ASTMatchers] Made isExpandedFromMacro Polymorphic
Made the isExpandedFromMacro matcher work on Stmt's, TypeLocs and Decls in line with the other macro expansion matchers.
Also tweaked it to take a `std::string` instead of a `StringRef`.
This prevents potential use-after-free bugs if the matcher is created with a string thats destroyed before the matcher finishes matching.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90303
2020-11-03 14:36:51 +00:00
Stephen Kelly ff02ae2139 Add test missing from previous commit 2020-11-03 11:06:52 +00:00
Stephen Kelly 53df3beb62 Ignore template instantiations if not in AsIs mode
Summary:
IgnoreUnlessSpelledInSource mode should ignore these because they are
not written in the source.  This matters for example when trying to
replace types or values which are templated.  The new test in
TransformerTest.cpp in this commit demonstrates the problem.

In existing matcher code, users can write
`unless(isInTemplateInstantiation())` or `unless(isInstantiated())` (the
user must know which to use).  The point of the
TK_IgnoreUnlessSpelledInSource mode is to allow the novice to avoid such
details.  This patch changes the IgnoreUnlessSpelledInSource mode to
skip over implicit template instantiations.

This patch does not change the TK_AsIs mode.

Note: An obvious attempt at an alternative implementation would simply
change the shouldVisitTemplateInstantiations() in ASTMatchFinder.cpp to
return something conditional on the operational TraversalKind.  That
does not work because shouldVisitTemplateInstantiations() is called
before a possible top-level traverse() matcher changes the operational
TraversalKind.

Reviewers: sammccall, aaron.ballman, gribozavr2, ymandel, klimek

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80961
2020-11-02 20:21:48 +00:00
Stephen Kelly 537cc6dd2b Rename CXXUnresolvedConstructExpr::arg_size for consistency
Make it possible to use argumentCountIs and hasArgument with
CXXUnresolvedConstructExpr.

Differential Revision: https://reviews.llvm.org/D90553
2020-11-02 20:21:48 +00:00
Alex Richardson 906b9dbc9d [clang-format] Improve BAS_DontAlign+AllowAllArgumentsOnNextLine=false
TokenAnnotator::splitPenalty() was always returning 0 for opening parens if
AlignAfterOpenBracket was set to BAS_DontAlign, so the preferred point for
line breaking was always after the open paren (and was ignoring
PenaltyBreakBeforeFirstCallParameter). This change restricts the zero
penalty to the AllowAllArgumentsOnNextLine case. This results in improved
formatting for FreeBSD where we set AllowAllArgumentsOnNextLine: false
and a high value for PenaltyBreakBeforeFirstCallParameter to avoid breaking
after the open paren.

Before:
```
functionCall(
    paramA, paramB, paramC);
void functionDecl(
    int A, int B, int C)
```
After:
```
functionCall(paramA, paramB,
    paramC);
void functionDecl(int A, int B,
    int C)
```

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D90246
2020-11-02 17:52:37 +00:00
Duncan P. N. Exon Smith ac49500cd0 Reapply "FileManager: Improve the FileEntryRef API and customize its OptionalStorage"
This reverts commit 940d0a310d,
effectively reapplying 84e8257937, after
working around the compile errors on the bots that I wasn't seeing
locally. I removed the `constexpr` from `OptionalStorage<FileEntryRef>`
that I had cargo-culted from the generic version, since `FileEntryRef`
isn't relevant in `constexpr` contexts anyway.

The original commit message follows:

Make a few changes to the `FileEntryRef` API in preparation for
propagating it enough to remove `FileEntry::getName()`.

- Allow `FileEntryRef` to degrade implicitly to `const FileEntry*`. This
  allows functions currently returning `const FileEntry *` to be updated
  to return `FileEntryRef` without requiring all callers to be updated
  in the same patch. This helps avoid both (a) massive patches where
  many fields and locals are updated simultaneously and (b) noisy
  incremental patches where the first patch adds `getFileEntry()` at
  call sites and the second patch removes it. (Once `FileEntryRef` is
  everywhere, we should remove this API.)
- Change `operator==` to compare the underlying `FileEntry*`, ignoring
  any difference in the spelling of the filename. There were 0 users of
  the existing function because it's not useful.  In case comparing the
  exact named reference becomes important, add/test `isSameRef`.
- Add `==` comparisons between `FileEntryRef` and `const FileEntry *`
  (compares the `FileEntry*`).
- Customize `OptionalStorage<FileEntryRef>` to be pointer-sized. Add
  a private constructor that initializes with `nullptr` and specialize
  `OptionalStorage` to use it. This unblocks updating fields in
  size-sensitive data structures that currently use `const FileEntry *`.
- Add `OptionalFileEntryRefDegradesToFileEntryPtr`, a wrapper around
  `Optional<FileEntryRef>` that degrades to `const FileEntry*`. This
  facilitates future incremental patches, like the same operator on
  `FileEntryRef`. (Once `FileEntryRef` is everywhere, we should remove
  this class.)
- Remove the unncessary `const` from the by-value return of
  `FileEntryRef::getName`.
- Delete the unused function `FileEntry::isOpenForTests`.

Note that there are still `FileEntry` APIs that aren't wrapped and I
plan to deal with these separately / incrementally, as they are needed.

Differential Revision: https://reviews.llvm.org/D89834
2020-10-30 15:06:01 -04:00
Duncan P. N. Exon Smith 940d0a310d Revert "FileManager: Improve the FileEntryRef API and customize its OptionalStorage" and follow-ups
This reverts commit 5530fb586f.
This reverts commit 010238a296.
This reverts commit 84e8257937.

Having trouble getting the bots compiling. Will try again later.
2020-10-30 14:06:55 -04:00
Duncan P. N. Exon Smith 84e8257937 FileManager: Improve the FileEntryRef API and customize its OptionalStorage
Make a few changes to the `FileEntryRef` API in preparation for
propagating it enough to remove `FileEntry::getName()`.

- Allow `FileEntryRef` to degrade implicitly to `const FileEntry*`. This
  allows functions currently returning `const FileEntry *` to be updated
  to return `FileEntryRef` without requiring all callers to be updated
  in the same patch. This helps avoid both (a) massive patches where
  many fields and locals are updated simultaneously and (b) noisy
  incremental patches where the first patch adds `getFileEntry()` at
  call sites and the second patch removes it. (Once `FileEntryRef` is
  everywhere, we should remove this API.)
- Change `operator==` to compare the underlying `FileEntry*`, ignoring
  any difference in the spelling of the filename. There were 0 users of
  the existing function because it's not useful.  In case comparing the
  exact named reference becomes important, add/test `isSameRef`.
- Add `==` comparisons between `FileEntryRef` and `const FileEntry *`
  (compares the `FileEntry*`).
- Customize `OptionalStorage<FileEntryRef>` to be pointer-sized. Add
  a private constructor that initializes with `nullptr` and specialize
  `OptionalStorage` to use it. This unblocks updating fields in
  size-sensitive data structures that currently use `const FileEntry *`.
- Add `OptionalFileEntryRefDegradesToFileEntryPtr`, a wrapper around
  `Optional<FileEntryRef>` that degrades to `const FileEntry*`. This
  facilitates future incremental patches, like the same operator on
  `FileEntryRef`. (Once `FileEntryRef` is everywhere, we should remove
  this class.)
- Remove the unncessary `const` from the by-value return of
  `FileEntryRef::getName`.
- Delete the unused function `FileEntry::isOpenForTests`.

Note that there are still `FileEntry` APIs that aren't wrapped and I
plan to deal with these separately / incrementally, as they are needed.

Differential Revision: https://reviews.llvm.org/D89834
2020-10-30 13:25:46 -04:00
Stephen Kelly 52ff86d255 [AST] Fix traversal over CXXConstructExpr in Syntactic mode
Summary:
Skip over elidable nodes, and ensure that intermediate
CXXFunctionalCastExpr nodes are also skipped if they are semantic.

Reviewers: klimek, ymandel

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82278
2020-10-30 12:14:41 +00:00