Commit Graph

8177 Commits

Author SHA1 Message Date
Kadir Cetinkaya 4839929bed
[clangd] Make forwarding parameter detection logic resilient
This could crash when our heuristic picks the wrong function. Make sure
there is enough parameters in the candidate to prevent those crashes.

Also special case copy/move constructors to make the heuristic work in
presence of those.

Fixes https://github.com/llvm/llvm-project/issues/56620

Differential Revision: https://reviews.llvm.org/D130260
2022-07-22 14:37:13 +02:00
Zhouyi Zhou 934d603826
[clang-tidy][NFC] Add preposition "of" to code annotation of ElseAfterReturnCheck
Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D129953
2022-07-22 12:40:08 +01:00
Sam McCall d9d554a3f4 [pseudo] Add ambiguity & unparseability metrics to -print-statistics
These can be used to quantify parsing improvements from a change.

Differential Revision: https://reviews.llvm.org/D130199
2022-07-22 10:35:06 +02:00
Kazu Hirata 70257fab68 Use any_of (NFC) 2022-07-22 01:05:17 -07:00
Haojian Wu 2a88fb2ecb [pseudo] Eliminate the dangling-else syntax ambiguity.
- the grammar ambiguity is eliminated by a guard;
- modify the guard function signatures, now all parameters are folded in
  to a single object, avoid a long parameter list (as we will add more
  parameters in the near future);

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D130160
2022-07-22 09:13:09 +02:00
Haojian Wu 18cee95919 [pseudo] Tweak the cli option messages, NFC. 2022-07-22 08:53:24 +02:00
Sam McCall d26ee284de [pseudo] Fix link error after 3132e9cd7c 2022-07-22 08:43:56 +02:00
Sam McCall 3132e9cd7c [pseudo] Key guards by RuleID, add guards to literals (and 0).
After this, NUMERIC_CONSTANT and strings should parse only one way.

There are 8 types of literals, and 24 valid (literal, TokenKind) pairs.
This means adding 8 new named guards (or 24, if we want to assert the token).

It seems fairly clear to me at this point that the guard names are unneccesary
indirection: the guards are in fact coupled to the rule signature.

(Also add the zero guard I forgot in the previous patch.)

Differential Revision: https://reviews.llvm.org/D130066
2022-07-21 22:42:31 +02:00
Kadir Cetinkaya b5871dfaf3
[clangd] Refactor forwarding call detection logic
Differential Revision: https://reviews.llvm.org/D130261
2022-07-21 17:58:56 +02:00
Kadir Cetinkaya 1515490c80
[clangd] Mention whether compile flags were inferred in check mode
That way when looking at logs it's clear whether diagnostics are a
result of compile flags mismatch.

Differential Revision: https://reviews.llvm.org/D130228
2022-07-21 17:33:44 +02:00
Haojian Wu 65c8e24622 [pseudo] Fix an invalid assertion on recoveryBrackets.
The `Begin` is not the index of the left bracket, `Begin-1` is,
otherwise the assertion will be triggered on case `Foo().call();`.
2022-07-21 14:02:11 +02:00
Haojian Wu 2955192df8 [pseudo] Make sure we rebuild pseudo_gen tool. 2022-07-21 10:09:21 +02:00
Xiang Li a73a84c447 [HLSL] add -I option for dxc mode.
A new option -I is added for dxc mode.
It is just alias of existing cc1 -I option.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D128462
2022-07-20 11:03:22 -07:00
Qwinci 3f73c57935 Argument name support for function pointer signature hints
Fixes https://github.com/clangd/clangd/issues/1068

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D125120
2022-07-19 20:02:26 -04:00
Sam McCall c91ce94144 [pseudo] Add `clang-pseudo -html-forest=<output.html>`, an HTML forest browser
It generates a standalone HTML file with all needed JS/CSS embedded.
This allows navigating the tree both with a tree widget and in the code,
inspecting nodes, and selecting ambiguous alternatives.

Demo: https://htmlpreview.github.io/?https://gist.githubusercontent.com/sam-mccall/03882f7499d293196594e8a50599a503/raw/ASTSignals.cpp.html

Differential Revision: https://reviews.llvm.org/D130004
2022-07-19 22:32:11 +02:00
Haojian Wu d489b3807f [pseudo] Implement a guard to determine function declarator.
This eliminates some simple-declaration/function-definition false
parses.

- implement a function to determine whether a declarator ForestNode is a
  function declarator;
- extend the standard declarator to two guarded function-declarator and
  non-function-declarator nonterminals;

Differential Revision: https://reviews.llvm.org/D129222
2022-07-19 09:44:45 +02:00
Nathan James 6357f1c1aa
[clang-tidy] Remove unnecessary code from ReadabilityModuleTest
D56303 added testing code that was then made redundant by the changes in D125026. However this code wasn't completely removed in the latter patch.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130026
2022-07-19 05:21:19 +01:00
Sam McCall fa0c7639e9 [pseudo] Add guards for module contextual keywords 2022-07-18 22:38:41 +02:00
Martin Storsjö 315072b450 [clang-tidy] Reduce the dependencies for the "make-confusable-table" tool
When cross compiling llvm, a separate recursive native cmake build
is generated, for building the tools that generate code (unless they're
provided externally by the caller).

This reduces the number of build steps for that native build from
1000+ steps to 162.

This matches how the clang-pseudo-gen tool is set up in
clang-tools-extra/pseudo/gen/CMakeLists.txt.

Differential Revision: https://reviews.llvm.org/D129797
2022-07-18 22:50:29 +03:00
Kadir Cetinkaya 0496cf2f6a
[clangd] Use empty string to represent None semantics in FoldingRange::kind
Differential Revision: https://reviews.llvm.org/D130003
2022-07-18 15:01:48 +02:00
Haojian Wu 098488e09a [pseduo] More precise on printing the error message, NFC 2022-07-18 13:23:18 +02:00
Utkarsh Saxena 70914aa631 Use pseudo parser for folding ranges
This first version only uses bracket matching. We plan to extend this to
use DirectiveTree as well.

Also includes changes to Token to allow retrieving corresponding token
in token stream of original source file.

Differential Revision: https://reviews.llvm.org/D129648
2022-07-18 11:35:34 +02:00
Haojian Wu b94ea8b3eb [pseudo] Add bracket recovery for function parameters. 2022-07-18 10:23:15 +02:00
Kazu Hirata 246bf08db3 Use drop_begin (NFC) 2022-07-15 23:24:59 -07:00
Kazu Hirata 5cff5142a8 Use value instead of getValue (NFC) 2022-07-15 20:03:13 -07:00
Haojian Wu 76910d4a56 [pseudo] Share the underly payload when stripping comments for a token stream
`stripComments(cook(...))` is a common pattern being written.
Without this patch, this has a use-after-free issue (cook returns a temporary
TokenStream object which has its own payload, but the payload is not
shared with the one returned by stripComments).

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D125311
2022-07-15 15:20:48 +02:00
Haojian Wu 2315358906 [pseudo] Generate an enum type for identifying grammar rules.
The Rule enum type enables us to identify a grammar rule within C++'s
type system.

Differential Revision: https://reviews.llvm.org/D129359
2022-07-15 15:09:31 +02:00
Haojian Wu 263dcf452f [syntax] Introduce a TokenManager interface.
TokenManager defines Token interfaces for the clang syntax-tree. This is the level
of abstraction that the syntax-tree should use to operate on Tokens.

It decouples the syntax-tree from a particular token implementation (TokenBuffer
previously).  This enables us to use a different underlying token implementation
for the syntax Leaf node -- in clang pseudoparser, we want to produce a
syntax-tree with its own pseudo::Token rather than syntax::Token.

Differential Revision: https://reviews.llvm.org/D128411
2022-07-15 10:30:37 +02:00
Fangrui Song 3c849d0aef Modernize Optional::{getValueOr,hasValue} 2022-07-15 01:20:39 -07:00
Jonas Devlieghere 888673b6e3
Revert "[clang] Implement ElaboratedType sugaring for types written bare"
This reverts commit 7c51f02eff because it
stills breaks the LLDB tests. This was  re-landed without addressing the
issue or even agreement on how to address the issue. More details and
discussion in https://reviews.llvm.org/D112374.
2022-07-14 21:17:48 -07:00
Matheus Izvekov 7c51f02eff
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.

The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.

An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.

---

Troubleshooting list to deal with any breakage seen with this patch:

1) The most likely effect one would see by this patch is a change in how
   a type is printed. The type printer will, by design and default,
   print types as written. There are customization options there, but
   not that many, and they mainly apply to how to print a type that we
   somehow failed to track how it was written. This patch fixes a
   problem where we failed to distinguish between a type
   that was written without any elaborated-type qualifiers,
   such as a 'struct'/'class' tags and name spacifiers such as 'std::',
   and one that has been stripped of any 'metadata' that identifies such,
   the so called canonical types.
   Example:
   ```
   namespace foo {
     struct A {};
     A a;
   };
   ```
   If one were to print the type of `foo::a`, prior to this patch, this
   would result in `foo::A`. This is how the type printer would have,
   by default, printed the canonical type of A as well.
   As soon as you add any name qualifiers to A, the type printer would
   suddenly start accurately printing the type as written. This patch
   will make it print it accurately even when written without
   qualifiers, so we will just print `A` for the initial example, as
   the user did not really write that `foo::` namespace qualifier.

2) This patch could expose a bug in some AST matcher. Matching types
   is harder to get right when there is sugar involved. For example,
   if you want to match a type against being a pointer to some type A,
   then you have to account for getting a type that is sugar for a
   pointer to A, or being a pointer to sugar to A, or both! Usually
   you would get the second part wrong, and this would work for a
   very simple test where you don't use any name qualifiers, but
   you would discover is broken when you do. The usual fix is to
   either use the matcher which strips sugar, which is annoying
   to use as for example if you match an N level pointer, you have
   to put N+1 such matchers in there, beginning to end and between
   all those levels. But in a lot of cases, if the property you want
   to match is present in the canonical type, it's easier and faster
   to just match on that... This goes with what is said in 1), if
   you want to match against the name of a type, and you want
   the name string to be something stable, perhaps matching on
   the name of the canonical type is the better choice.

3) This patch could exposed a bug in how you get the source range of some
   TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
   which only looks at the given TypeLoc node. This patch introduces a new,
   and more common TypeLoc node which contains no source locations on itself.
   This is not an inovation here, and some other, more rare TypeLoc nodes could
   also have this property, but if you use getLocalSourceRange on them, it's not
   going to return any valid locations, because it doesn't have any. The right fix
   here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
   into the inner TypeLoc to get the source range if it doesn't find it on the
   top level one. You can use getLocalSourceRange if you are really into
   micro-optimizations and you have some outside knowledge that the TypeLocs you are
   dealing with will always include some source location.

4) Exposed a bug somewhere in the use of the normal clang type class API, where you
   have some type, you want to see if that type is some particular kind, you try a
   `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
   ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
   Again, like 2), this would usually have been tested poorly with some simple tests with
   no qualifications, and would have been broken had there been any other kind of type sugar,
   be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
   The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
   into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
   For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.

5) It could be a bug in this patch perhaps.

Let me know if you need any help!

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D112374
2022-07-15 04:16:55 +02:00
Fangrui Song 52cb972537 [CommandLine] --help: print "-o <xxx>" instead of "-o=<xxx>"
Accepting -o= is a quirk of CommandLine. For --help, we should print the
conventional "-o <xxx>".
2022-07-14 01:28:28 -07:00
Balázs Kéri 0e95921bc3 [clang-tidy] Improve check cert-dcl58-cpp.
Detect template specializations that should be handled specially.
In some cases it is allowed to extend the `std` namespace with
template specializations.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129353
2022-07-14 09:04:03 +02:00
Fangrui Song e690137dde [Support] Change compression::zlib::{compress,uncompress} to use uint8_t *
It's more natural to use uint8_t * (std::byte needs C++17 and llvm has
too much uint8_t *) and most callers use uint8_t * instead of char *.
The functions are recently moved into `llvm::compression::zlib::`, so
downstream projects need to make adaption anyway.
2022-07-13 16:26:54 -07:00
Jonas Devlieghere 3968936b92
Revert "[clang] Implement ElaboratedType sugaring for types written bare"
This reverts commit bdc6974f92 because it
breaks all the LLDB tests that import the std module.

  import-std-module/array.TestArrayFromStdModule.py
  import-std-module/deque-basic.TestDequeFromStdModule.py
  import-std-module/deque-dbg-info-content.TestDbgInfoContentDequeFromStdModule.py
  import-std-module/forward_list.TestForwardListFromStdModule.py
  import-std-module/forward_list-dbg-info-content.TestDbgInfoContentForwardListFromStdModule.py
  import-std-module/list.TestListFromStdModule.py
  import-std-module/list-dbg-info-content.TestDbgInfoContentListFromStdModule.py
  import-std-module/queue.TestQueueFromStdModule.py
  import-std-module/stack.TestStackFromStdModule.py
  import-std-module/vector.TestVectorFromStdModule.py
  import-std-module/vector-bool.TestVectorBoolFromStdModule.py
  import-std-module/vector-dbg-info-content.TestDbgInfoContentVectorFromStdModule.py
  import-std-module/vector-of-vectors.TestVectorOfVectorsFromStdModule.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45301/
2022-07-13 09:20:30 -07:00
Sam McCall 6b50f2bbdb [clangd] Enable designator inlay hints by default.
Differential Revision: https://reviews.llvm.org/D129595
2022-07-13 16:31:45 +02:00
Kazu Hirata 53daa177f8 [clang, clang-tools-extra] Use has_value instead of hasValue (NFC) 2022-07-12 22:47:41 -07:00
Matheus Izvekov bdc6974f92
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.

The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.

An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D112374
2022-07-13 02:10:09 +02:00
Sam McCall 93cd159ca9 [clangd] Remove `allCommitCharacters`
This was added in 2a095ff6f5, however it never worked with VSCode
due to bugs in vscode-languageclient
(https://github.com/microsoft/vscode-languageserver-node/issues/673).
Now that it does work, we can tell the interactions with text editing, with
snippets, and vscode's select-first-completion behavior are bad.

The spec is vague and clients could do something reasonable with the
current values. However they could clearly do something unreasonable
too, and over time behavior+spec tends to converge on VSCode's behavior.

This addresses https://github.com/clangd/vscode-clangd/pull/358
See also https://github.com/clangd/vscode-clangd/pull/358 which hotfixes
this on the client-side (as we can't apply this change retroactively to
clangd 12-14).

Differential Revision: https://reviews.llvm.org/D129579
2022-07-12 21:42:38 +02:00
Tom Praschan 9f57b65a27 [clangd] Include "final" when printing class declaration
Fixes https://github.com/clangd/clangd/issues/1184

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D128202
2022-07-11 12:20:23 +02:00
Tom Praschan cd85d9aeef Go-to-type on smart_ptr<Foo> now also shows Foo
Fixes clangd/clangd#1026

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D128826
2022-07-11 12:13:47 +02:00
Danny Mösch 963192228b [clang-tidy] Sort release notes entries alphabetically by check name 2022-07-09 15:45:19 +02:00
Danny Mösch 33e2129544 [clang-tidy] Initialize boolean variables with `false` in cppcoreguidelines-init-variables' fix-it
In case of a variable with a built-in boolean type, `false` is a better fit to default-initialize it.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D129420
2022-07-09 14:48:50 +02:00
Christian Kandeler b1fbc0519c [clangd] Support "usedAsMutableReference" in member initializations
That is, mark constructor parameters being used to initialize
non-const reference members.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D128977
2022-07-08 23:16:20 -04:00
Leonard Chan 474c873148 Revert "[llvm] cmake config groundwork to have ZSTD in LLVM"
This reverts commit f07caf20b9 which seems to break upstream https://lab.llvm.org/buildbot/#/builders/109/builds/42253.
2022-07-08 13:48:05 -07:00
Cole Kissane f07caf20b9 [llvm] cmake config groundwork to have ZSTD in LLVM
- added `FindZSTD.cmake`
- added a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- likewise added have_zstd to compiler-rt/test/lit.common.cfg.py, clang-tools-extra/clangd/test/lit.cfg.py, and several lit.site.cfg.py.in files mirroring have_zlib behavior

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-08 11:46:52 -07:00
Cole Kissane ea61750c35 [NFC] Refactor llvm::zlib namespace
* Refactor compression namespaces across the project, making way for a possible
  introduction of alternatives to zlib compression.
  Changes are as follows:
  * Relocate the `llvm::zlib` namespace to `llvm::compression::zlib`.

Reviewed By: MaskRay, leonardchan, phosek

Differential Revision: https://reviews.llvm.org/D128953
2022-07-08 11:19:07 -07:00
Aaron Ballman fee77a2073 Disable clang-format entirely for test directories
See discussion here:

https://github.com/llvm/llvm-project/issues/55982

And the RFC here:
https://discourse.llvm.org/t/rfc-disable-clang-format-in-the-clang-test-tree/63498/2

We don't generally expect test files to be formatted according to the
style guide. Indeed, some tests may require specific formatting for the
purposes of the test.

When tests intentionally do not conform to the "correct" formatting,
this causes errors in the CI, which can drown out real errors and causes
people to stop trusting the CI over time.

From the history of the clang/test/.clang-format file, it looks as if
there have been attempts to make clang-format do a subset of formatting
that would be useful for tests. However, it looks as if it's hard to
make clang-format do exactly the right thing -- see the back-and-forth
between
13316a7
and
7b5bddf.

These changes disable the .clang-format file for clang/test, llvm/test,
and clang-tools-extra/test.

Fixes #55982
Differential Revision: https://reviews.llvm.org/D128706
2022-07-08 07:34:18 -04:00
Sam McCall b15127d056 [clangd] Disable flaky test 2022-07-07 19:17:09 +02:00
Sam McCall eb64dbd6e0 [clangd] Fix flaky throttler test
The production code doesn't depend on the relative destruction order of
the throttle request and the main request, but the test does.
2022-07-07 18:09:54 +02:00