Commit Graph

8285 Commits

Author SHA1 Message Date
Haojian Wu f7dc91ad56 [pseudo] Eliminate a false parse of structured binding declaration.
Using the guard to implement part of the rule https://eel.is/c++draft/dcl.pre#6.

```
void foo() {
  // can be parsed as
  //   - structured-binding declaration (a false parse)
  //   - assignment expression
  array[index] = value;
}
```

Differential Revision: https://reviews.llvm.org/D132260
2022-08-23 15:25:52 +02:00
Haojian Wu edb8fb2659 [pseudo] Fix HeadsPartition is not initialized correctly.
The bug was that if we recover from the token 0, we will make the
Heads empty (Line646), which results no recovery being applied.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D132388
2022-08-23 15:08:33 +02:00
Kadir Cetinkaya 3c2cb8e2f0
[clangd] Disable IncludeCleaner for ObjC 2022-08-22 11:28:06 +02:00
Kazu Hirata 8b1b0d1d81 Revert "Use std::is_same_v instead of std::is_same (NFC)"
This reverts commit c5da37e42d.

This patch seems to break builds with some versions of MSVC.
2022-08-20 23:00:39 -07:00
Kazu Hirata c5da37e42d Use std::is_same_v instead of std::is_same (NFC) 2022-08-20 22:36:26 -07:00
Kazu Hirata 8e494b85a5 Use llvm::drop_begin (NFC) 2022-08-20 21:18:30 -07:00
Kazu Hirata 258531b7ac Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
eahcmrh 9e1a4ce0b5 [clang-tidy] Fix for bugprone-sizeof-expression PR57167
This addresses a change in behavior of the bugprone-sizeof-expression
checker after upstream commit 15f3cd6bfc, which cleaned up
ElaboratedType sugaring in the AST.  This restores (mostly) the
beahvior of the checker prior to that commit, which may or may not have
been consistent with the intent of the checker, but at least gave a
tolerable level of what users would consider false positives.

Bug: https://github.com/llvm/llvm-project/issues/57167

Reviewed By: mizvekov, aaron.ballman

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

Change-Id: Ibe5aad77ad00977134aa7fa67efbbd6bd725fd79
2022-08-19 23:29:32 +02:00
Denis Fatkulin ee648c0ce0 [clang][index] Index unresolved member expression as reference
Unresolved member expressions aren't indexed as references.

Example code:

```
struct Foo {
  template <typename T> void bar(T t);
};
template <typename T> void test(Foo F, T t) {
  F.bar(t); // Not indexed
}
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D131091
2022-08-19 19:02:42 +03:00
Sam McCall bd5cc6575b [pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.
Previously we were calling glrRecover() ad-hoc at the end of input.
Two main problems with this:
 - glrRecover() on two separate code paths is inelegant
 - We may have to recover several times in succession (e.g. to exit from
   nested scopes), so we need a loop at end-of-file
Having an actual shift action for an EOF terminal allows us to handle
both concerns in the main shift/recover/reduce loop.

This revealed a recovery design bug where recovery could enter a loop by
repeatedly choosing the same parent to identically recover from.
Addressed this by allowing each node to be used as a recovery base once.

Differential Revision: https://reviews.llvm.org/D130550
2022-08-19 16:49:37 +02:00
Haojian Wu e32799d1d6 [pseudo] NFC, remove redundant ; 2022-08-19 15:55:19 +02:00
Sam McCall ac31781759 [Sema] Tweak diagnostic logic so suppress-in-header logic works in tools too.
Certain idioms are ignored by -Wunused in header files only.
The current "is a header" check assumes that if headers are the main file, we're
building a PCH or a module or something. However in tools we may be parsing the
header in its own right, but still want to treat it as a header.

Fixes https://github.com/clangd/vscode-clangd/issues/360

Differential Revision: https://reviews.llvm.org/D129642
2022-08-19 15:16:10 +02:00
Sam McCall 605035bf45 [pseudo] Changes omitted from previous commit 2022-08-19 15:15:37 +02:00
Sam McCall 2cc7463c85 [pseudo] Perform unconstrained reduction prior to recovery.
Our GLR uses lookahead: only perform reductions that might be consumed by the
shift immediately following. However when shift fails and so reduce is followed
by recovery instead, this restriction is incorrect and leads to missing heads.

In turn this means certain recovery strategies can't be made to work. e.g.
```
ns := NAMESPACE { namespace-body } [recover=Skip]
ns-body := namespace_opt
```
When `namespace { namespace {` is parsed, we can recover the inner `ns` (using
the `Skip` strategy to ignore the missing `}`). However this `namespace` will
not be reduced to a `namespace-body` as EOF is not in the follow-set, and so we
are unable to recover the outer `ns`.

This patch fixes this by tracking which heads were produced by constrained
reduce, and discarding and rebuilding them before performing recovery.

This is a prerequisite for the `Skip` strategy mentioned above, though there are
some other limitations we need to address too.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D130523
2022-08-19 15:07:36 +02:00
Sam McCall 13b2a0c69b [clangd] Support hover on __func__ etc (PredefinedExpr)
Expose these as variables as that's what the standard calls them (and D131175).

To make this work, we also fix a bug in SelectionTree: PredefinedExpr has
an implicit/invisible StringLiteral, and SelectionTree should not traverse
implicit things.

Reviewed By: ckandeler

Differential Revision: https://reviews.llvm.org/D132135
2022-08-19 14:51:46 +02:00
Carlos Galvez 3fd4213059 [clang-tidy] Do not trigger cppcoreguidelines-avoid-const-or-ref-data-members on lambda captures
Lambdas are implemented as regular classes internally,
and the captured variables end up as members there.
Do not diagnose those - the check should cover only
regular classes and structs.

Differential Revision: https://reviews.llvm.org/D131780
2022-08-19 08:26:34 +00:00
Joey Watts b8655f7ff2
[clang-tidy] Improve modernize-use-emplace check
This patch improves the modernize-use-emplace check by adding support for
detecting inefficient invocations of the `push` and `push_front` methods on
STL-style containers and replacing them with their `emplace`-style equivalent.

Fixes #56996.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131623
2022-08-19 07:57:42 +01:00
Kadir Cetinkaya 7f2a079a12
[clangd] Fix a tsan failure in PreambleThrottle tests 2022-08-18 18:36:01 +02:00
Christian Kandeler 1c056f8df2 [clangd] Use the "macro" semantic token for pre-defined identifiers
This matches user expectations.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D131175
2022-08-18 16:12:55 +02:00
Martin Storsjö 9ad0ace2ba [clang-tidy] Rename a local cmake variables to match the new tool name. NFC.
This shouldn't have any externally visible effect.

This matches the new name from 18b4a8bcf3.

Differential Revision: https://reviews.llvm.org/D130701
2022-08-18 14:27:45 +03:00
Vladimir Plyashkun fa8f861602
[clang-tidy] hicpp-signed-bitwise - Return location of the operand (and not of the operator beginning)
Currently, the "hicpp/signed-bitwise" check returns the beginning of the binary/unary operator as location, which sometimes confuses users in the IDE due to incorrect [[ https://youtrack.jetbrains.com/issue/CPP-12445/Clang-Tidy-highlighting-for-binary-operators-applied-to-wrong-operand | highlighting ]].
Yes, the offset from Ranges can be used for this particular check, but i suppose better solution is to return begin location of the problematic operand instead of operator.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131678
2022-08-17 19:25:59 +01:00
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