Commit Graph

8264 Commits

Author SHA1 Message Date
Haojian Wu 6a9f79e102 [pseudo] Eliminate the type-name identifier ambiguities in the grammar.
See https://reviews.llvm.org/D130626 for motivation.

Identifier in the grammar has different categories (type-name, template-name,
namespace-name), they requires semantic information to resolve. This patch is
to eliminate the "local" ambiguities in type-name, and namespace-name, which
gives us a performance boost of the parser:

  - eliminate all different type rules (class-name, enum-name, typedef-name), and
    fold them into a unified type-name, this removes the #1 type-name ambiguity, and
    gives us a big performance boost;
  - remove the namespace-alis rules, as they're hard and uninteresting;

Note that we could eliminate more and gain more performance (like fold template-name,
type-name, namespace together), but at current stage, we'd like keep all existing
categories of the identifier (as they might assist in correlated disambiguation &
keep the representation of important concepts uniform).

| file               |ambiguous nodes |  forest size     | glrParse performance |
|SemaCodeComplete.cpp|  11k -> 5.7K   | 10.4MB -> 7.9MB  | 7.1MB/s -> 9.98MB/s  |
|       AST.cpp      |  1.3k -> 0.73K | 0.99MB -> 0.77MB | 6.7MB/s -> 8.4MB/s   |

Differential Revision: https://reviews.llvm.org/D130747
2022-08-17 14:30:53 +02:00
Kadir Cetinkaya 83411bf06f
[clangd] Support for standard type hierarchy
This is mostly a mechanical change to adapt standard type hierarchy
support proposed in LSP 3.17 on top of clangd's existing extension support.

This does mainly two things:
- Incorporate symbolids for all the parents inside resolution parameters, so
  that they can be retrieved from index later on. This is a new code path, as
  extension always resolved them eagerly.
- Propogate parent information when resolving children, so that at least one
  branch of parents is always preserved. This is to address a shortcoming in the
  extension.

This doesn't drop support for the extension, but it's deprecated from now on and
will be deleted in upcoming releases. Currently we use the same struct
internally but don't serialize extra fields.

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

Differential Revision: https://reviews.llvm.org/D131385
2022-08-17 09:29:15 +02:00
Sam McCall 0b90e136ee [pseudo] Style tweaks forgotten in D130337. NFC 2022-08-16 10:26:25 +02:00
Kazu Hirata f5a68feab3 Use llvm::none_of (NFC) 2022-08-14 16:25:39 -07:00
Kazu Hirata 55f0a87ea4 [clangd] Use llvm::any_of (NFC) 2022-08-14 16:25:38 -07:00
Kazu Hirata 6d9cd9199a Use llvm::all_of (NFC) 2022-08-14 16:25:36 -07:00
Kazu Hirata 2febc32c9c Use llvm::erase_if (NFC) 2022-08-13 12:55:48 -07:00
Kazu Hirata 2b43bd0bd9 Remove unused forward declarations (NFC) 2022-08-13 12:55:47 -07:00
Kazu Hirata 7c69476564 [clangd] Drop unnecessary const from return types (NFC)
Identified with readability-const-return-type.
2022-08-13 12:55:44 -07:00
Kazu Hirata 2117fcb1c0 Use Optional::transform instead of Optional::map (NFC)
I'm planning to deprecate map in favor of transform for consistency
with std::optional::transform in C++23.
2022-08-13 11:48:26 -07:00
Brett Wilson 68266828b1 [clang-doc] Always emit the TagType for RecordInfo
Always emit the TagType for RecordInfo in YAML output. Previously this omitted the type for "struct", considering it the default. But records in C++ don't really have a default type so always emitting this is more clear.

Emit IsTypeDef in YAML. Previously this existed only in the Representation but was never written. Additionally, adds IsTypeDef to the record merge operation which was clearing it (all RecordInfo structures are merged with am empty RecordInfo during the reduce phase).

Reviewed By: paulkirth

Differential Revision: https://reviews.llvm.org/D131739
2022-08-12 18:39:20 +00:00
Brett Wilson 75c7e79464 [clang-doc] Fix assert on startup
When using `clang-doc --format=html` it will crash on startup because of an assertion doing a self-assignment of a `SmallString`. This patch removes the self-assignment by creating an intermediate copy.

Reviewed By: paulkirth

Differential Revision: https://reviews.llvm.org/D131793
2022-08-12 18:37:23 +00:00
Aleksandr Platonov 42ee0d8c16 [clangd][unittests][IncludeCleaner] Don't call findReferencedFiles() if the result is not used
IncludeCleaner.RecursiveInclusion and IncludeCleaner.IWYUPragmaExport tests don't check referenced files list, so we don't need to call findReferencedFiles() there.

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D131706
2022-08-12 21:00:11 +03:00
Haojian Wu 06b97b4985 [clangd] Fix an inlay-hint crash on a broken designator.
Differential Revision: https://reviews.llvm.org/D131696
2022-08-12 14:37:46 +02:00
Haojian Wu 1828c75d5f [pseudo] Apply the function-declarator to member functions.
A followup patch of d489b3807f, but for
member functions, this will eliminate a false parse of member
declaration.

Differential Revision: https://reviews.llvm.org/D131720
2022-08-12 13:49:01 +02:00
Haojian Wu a1a1a78ac8 [pseudo] Eliminate an ambiguity for the empty member declaration.
We happened to introduce a `member-declaration := ;` rule
when inlining the `member-declaration := decl-specifier-seq_opt
member-declarator-list_opt ;`.
And with the `member-declaration := empty-declaration` rule, we had two parses of `;`.

This patch is to restrict the grammar to eliminate the
`member-declaration := ;` rule.

Differential Revision: https://reviews.llvm.org/D131724
2022-08-12 13:46:26 +02:00
Balázs Kéri 6e75ec5e38 [clang-tidy] Support C++14 in bugprone-signal-handler.
Check `bugprone-signal-handler` is improved to check for
C++-specific constructs in signal handlers. This check is
valid until C++17.

Reviewed By: whisperity

Differential Revision: https://reviews.llvm.org/D118996
2022-08-12 09:45:53 +02:00
Vladimir Plyashkun 6c7b049f6e
[clang-tidy][docs] Fixed page title for abseil-no-internal-dependencies check documentation
It seems that documentation for abseil-no-internal-dependencies has invalid title.
This can be checked by looking at the actual web-site - https://clang.llvm.org/extra/clang-tidy/checks/abseil/no-internal-dependencies.html
There is redundant "subl.. title:: clang-tidy - abseil-no-internal-dependencies" paragraph in the beginning.

Reviewed By: njames93, sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D131590
2022-08-11 21:09:39 +01:00
Brett Wilson 99baa10f8f [clang-doc] Read docstrings for record members
Struct/class data members did not have the comments associated with
them. This adds that information to the MemberTypeInfo class and emits
it in the YAML. This does not update the frontends yet.

Reviewed By: paulkirth

Differential Revision: https://reviews.llvm.org/D131298
2022-08-11 17:14:15 +00:00
Haojian Wu bf0e219d04 [pseudo] Use C++17 variant to simplify the DirectiveTree::Chunk class, NFC.
Differential Revision: https://reviews.llvm.org/D131396
2022-08-11 14:27:38 +02:00
Haojian Wu e935f7fd0c [pseudo] Fix a bug in checking the duplicated grammar rules. 2022-08-11 13:16:01 +02:00
Carlos Galvez 9ae5896d96 [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check
Flags uses of const-qualified and reference data members in structs.
Implements rule C.12 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D126880
2022-08-11 07:46:04 +00:00
Tom Praschan 15bf2aa44a [clangd][test] Fix error message in SerializationTest.BinaryConversions
I noticed this when adding a new type to the index for
https://github.com/clangd/clangd/issues/529. When the assertion failed,
this actually caused a crash, because llvm::expected would complain that
we did not take the error.
2022-08-11 08:50:23 +02:00
Clement Courbet 156c0754bc [clang][transformer] Finish plumbing `Note` all the way to the output.
Right now we can only add a single warning, notes are not possible.

Apparently some provisions were made to allow notes, but they were never
propagated all the way to the diagnostics.

Differential Revision: https://reviews.llvm.org/D128807
2022-08-11 07:54:44 +02:00
Aaron Ballman af01f717c4 Default implicit function pointer conversions diagnostic to be an error
Implicitly converting between incompatible function pointers in C is
currently a default-on warning (it is an error in C++). However, this
is very poor security posture. A mismatch in parameters or return
types, or a mismatch in calling conventions, etc can lead to
exploitable security vulnerabilities. Rather than allow this unsafe
practice with a warning, this patch strengthens the warning to be an
error (while still allowing users the ability to disable the error or
the warning entirely to ease migration). Users should either ensure the
signatures are correctly compatible or they should use an explicit cast
if they believe that's more reasonable.

Differential Revision: https://reviews.llvm.org/D131351
2022-08-10 13:54:17 -04:00
Simon Pilgrim 25340410c9 Revert rGa772f775a2ba401e95a0bbe73deb6300f1dc12c0 "[clang-tidy] Support C++14 in bugprone-signal-handler."
This was breaking a number of buildbots: https://lab.llvm.org/buildbot/#/builders/139/builds/26335
2022-08-10 15:25:04 +01:00
Balázs Kéri a772f775a2 [clang-tidy] Support C++14 in bugprone-signal-handler.
Check `bugprone-signal-handler` is improved to check for
C++-specific constructs in signal handlers. This check is
valid until C++17.

Reviewed By: whisperity

Differential Revision: https://reviews.llvm.org/D118996
2022-08-10 12:00:16 +02:00
Clement Courbet 5331e1229a [clang][transformer] Fix crash on replacement-less ASTEdit.
Given that we provide an EditGenerator edit(ASTEdit), we can't ever be
sure that the user won't give us an empty replacement.

Differential Revision: https://reviews.llvm.org/D128887
2022-08-10 09:08:05 +02:00
Haojian Wu c2c5c39c40 [pseudo] Fix a suspicious usage of `sizeof(this)`.
It should be `sizeof(*this)`.
2022-08-09 21:46:56 +02:00
Simon Pilgrim d9e5462da6 [clang-pseudo] Forest.h - don't inherit from std::iterator
Now that we've updated to C++17 MSVC gives very verbose warnings about not creating classes that inherit from std::iterator - use llvm::iterator_facade_base instead

Fixes #57005
2022-08-09 10:18:53 +01:00
Fangrui Song 32197830ef [clang][clang-tools-extra] LLVM_NODISCARD => [[nodiscard]]. NFC 2022-08-09 07:11:18 +00:00
Fangrui Song 0972a390b9 LLVM_FALLTHROUGH => [[fallthrough]]. NFC 2022-08-09 04:06:52 +00:00
Haojian Wu 7dc410cbff [clang-tidy] Fix a regression of readability-container-size-empty after the AST ElaboratedType change.
With 15f3cd6bfc, we no longer emit a
diagnostic on a real std::vector case where the size method returns a
sugar `size_type`. This patch fixes it.

```
std::vector<int> v;
if (v.size() == 0) // => no check diagnostics
  ;
```

Differential Revision: https://reviews.llvm.org/D131390
2022-08-08 14:40:36 +02:00
Kazu Hirata 1dd8a31854 [clang-tidy] Use is_contained (NFC) 2022-08-07 23:55:25 -07:00
Haojian Wu 82439b201a [clang-tidy] Fix a forwarding-reference-overload crash after the
ElaboratedType change.

After 15f3cd6bfc, the nss of
ElaboratedType can be null.
2022-08-07 16:53:56 +02:00
Kazu Hirata 7542e72188 Use llvm::is_contained (NFC) 2022-08-07 00:16:17 -07:00
Fangrui Song c7ec86b13c [clang-tidy] Fix g++ -DCMAKE_CXX_STANDARD=17 build
`constexpr std::initializer_list<llvm::StringRef>` leads to
```
error: modification of '<temporary>' is not a constant expression
```
Related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102921
2022-08-06 23:12:18 +00:00
Rashmi Mudduluru 13bc713109 fixes clang-tidy/checks/list.rst: a line was accidentally removed in 95a92995d4 2022-08-05 12:36:03 -07:00
Nathan James 4c106c93eb
[clangd] Change the url for clang-tidy check documentation
In 6e566bc552, The directory structure of the documentation for clang-tidy checks was changed, however clangd wasn't updated.
Now all the links generated will point to old dead pages.
This updated clangd to use the new page structure.

Reviewed By: sammccall, kadircet

Differential Revision: https://reviews.llvm.org/D128379
2022-08-05 08:42:52 +01:00
Petr Hosek ea50901aa9 [clang-doc] Default to Standalone executor and improve documentation
This should provide a more intuitive usage consistent with other tools.

Differential Revision: https://reviews.llvm.org/D130226
2022-08-04 17:43:16 +00:00
Kadir Cetinkaya df48e3fbcc
Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator overloads"
This reverts commit 4e94f66531.
See https://reviews.llvm.org/D129973#3698969 for reasoning.
2022-08-04 12:14:43 +02:00
Corentin Jabot 127bf44385 [Clang][C++20] Support capturing structured bindings in lambdas
This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768
2022-08-04 10:12:53 +02:00
Corentin Jabot a274219600 Revert "[Clang][C++20] Support capturing structured bindings in lambdas"
This reverts commit 44f2baa380.

Breaks self builds and seems to have conformance issues.
2022-08-03 21:00:29 +02:00
Corentin Jabot 44f2baa380 [Clang][C++20] Support capturing structured bindings in lambdas
This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768
2022-08-03 20:00:01 +02:00
Utkarsh Saxena 9ef11616b2 Add foldings for multi-line comment.
Differential Revision: https://reviews.llvm.org/D130081
2022-08-03 08:19:12 +02:00
Stanislav Gatev c44c71843f [clang][dataflow] Make the type of the post visit callback consistent
Make the types of the post visit callbacks in `transferBlock` and
`runTypeErasedDataflowAnalysis` consistent.

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

Reviewed-by: ymandel, xazax.hun, gribozavr2
2022-08-03 05:58:38 +00:00
Rashmi Mudduluru 95a92995d4 Adds the NSDateFormatter checker to clang-tidy
Differential Revision: https://reviews.llvm.org/D126097
2022-08-02 13:57:44 -07:00
Ben Langmuir 54110b8aa0 Fix use-after-free in clang-apply-replacements
Accidentally introduced a dangling StringRef in b4c6dc2e66.

Differential Revision: https://reviews.llvm.org/D131017
2022-08-02 13:34:20 -07:00
Ben Langmuir b4c6dc2e66 [clang] Update code that assumes FileEntry::getName is absolute NFC
It's an accident that we started return asbolute paths from
FileEntry::getName for all relative paths. Prepare for getName to get
(closer to) return the requested path. Note: conceptually it might make
sense for the dependency scanner to allow relative paths and have the
DependencyConsumer decide if it wants to make them absolute, but we
currently document that it's absolute and I didn't want to change
behaviour here.

Differential Revision: https://reviews.llvm.org/D130934
2022-08-01 14:48:37 -07:00
David Goldman 61ef0ab701 [clangd] Add decl/def support to SymbolDetails
Add an optional declarationRange and definitionRange to SymbolDetails.

This will allow SourceKit-LSP to implement toggling between goto
definition/declaration based on whether the symbol at the cursor
is a definition or declaration.

Differential Revision: https://reviews.llvm.org/D130041
2022-08-01 14:42:19 -04:00